Skip to main content
almarefa.net

Back to all posts

How to Style Links In CSS?

Published on
3 min read
How to Style Links In CSS? image

Best CSS Styling Tools to Buy in October 2025

1 CSS Mastery: Advanced Web Standards Solutions

CSS Mastery: Advanced Web Standards Solutions

BUY & SAVE
$13.40 $34.99
Save 62%
CSS Mastery: Advanced Web Standards Solutions
2 CSS PocketGuide Reference: A Handy Guide for Quick Styling Solutions

CSS PocketGuide Reference: A Handy Guide for Quick Styling Solutions

BUY & SAVE
$3.00
CSS PocketGuide Reference: A Handy Guide for Quick Styling Solutions
+
ONE MORE?

To style links in CSS, you can use the following properties:

  1. color: Determines the color of the link text. Example:

a { color: blue; }

  1. text-decoration: Controls the decoration of the link, such as underlining. Example:

a { text-decoration: none; }

  1. font-weight: Sets the weight, or thickness, of the link text. Example:

a { font-weight: bold; }

4.:hover: This pseudo-class applies styles when the link is being hovered over by the user. Example:

a:hover { color: red; text-decoration: underline; }

  1. :visited: This pseudo-class applies styles to links that have been visited. Example:

a:visited { color: purple; }

You can combine these properties and use additional CSS properties to further customize the styling of links according to your specific needs.

The default color of links in CSS is typically blue. After a link has been visited, the default color changes to purple by default, and when a user hovers over a link, the default color changes to red by default. However, these default colors can be modified in CSS using the appropriate properties.

To change the link color on hover in CSS, you can use the :hover pseudo-class selector. Here is an example:

a:hover { color: red; }

In the code above, a is the selector for all the anchor <a> tags. The :hover selector specifies the style for the link when it is being hovered over. In this case, the color property is set to red, but you can replace it with any valid CSS color value.

You can apply this CSS code to your HTML by either:

  1. Adding it within a block inside the section of your HTML document.
  2. Linking an external CSS file using the tag and placing the CSS code within that file.

Note: If there are other CSS rules affecting the link color, make sure the above code comes after those rules to override them.

The pseudo-element for link underlines in CSS is ::after.

The default cursor for links in CSS is usually the "pointer" cursor.

To add padding around links in CSS, you can use the padding property. Here's an example:

a { padding: 10px; /* adds 10 pixels of padding on all sides */ }

You can also specify different values for each side using the shorthand notation:

a { padding: 10px 20px; /* adds 10 pixels of padding vertically and 20 pixels horizontally */ }

Alternatively, you can use individual padding properties for each side:

a { padding-top: 10px; padding-right: 20px; padding-bottom: 10px; padding-left: 20px; }

Feel free to adjust the pixel values according to your desired amount of padding.