OneBite.Dev - Coding blog in a bite size

change link color in css

Code snippet for how to change link color in css with sample and detail explanation

If you’ve been exploring the world of web design and have a desire to modify the look of your website, changing the link color with CSS is a great place to start. In this article, we’ll walk you through the basics of changing hyperlink colors using CSS, which will allow you to better match the overall style of your site.

Code Snippet

Before we dive into the process, let’s first look at the CSS code snippet you’d use to change your link’s color:

a:link {
  color: red;
}

a:visited {
  color: green;
}

a:hover {
  color: orange;
}

a:active {
  color: blue;
}

Code Explanation

In this section, we’ll run through what each part of the aforementioned code does, breaking it down line by line.

  1. The first line a:link { this is the CSS selector for the link. The color property is then used to define the color you’d like your links to be. In this case, we’ve chosen ‘red’, but you can replace this with whichever color you prefer.

  2. The third line a:visited { this is the CSS selector for a link that has already been clicked, therefore ‘visited’. Again, the ‘color’ property is used to specify the desired color. You may want to choose a shade that subtly lets users know they’ve already visited this particular link; in our example, we’ve gone for ‘green’.

  3. In the middle, a:hover { this selector denotes the link state when the mouse is hovering over it. You could consider a contrasting color here, as we’ve done with ‘orange’, to highlight when a user is about to click on a link.

  4. Lastly, the a:active { selector refers to when a link is actively being clicked on. This can provide instant feedback to the user that they have indeed clicked the link. We’ve chosen ‘blue’ as our active link color.

By personalizing your code based on this model, you’ll be taking a step towards having a truly unique website, which offers a personalized experience for its visitors. The link color is just one of the many aspects you can alter with CSS, but it’s a simple and effective place to start your customization journey.

css