How to Add different colors to visited/unvisited links in CSS

As a web developer, one of the most important aspects of creating a website is ensuring that it is visually appealing and easy to navigate.

One way to accomplish this is by styling the links on your website to indicate whether they have been visited or not.

In this CSS tutorial, we will take a look at how to add different colors to visited and unvisited links in CSS.

First, let’s start by understanding the difference between visited and unvisited links.

When a user clicks on a link, the link is considered “visited.”

Once a link has been visited, it will display a different color than unvisited links.

This is a useful feature because it allows users to quickly see which links they have already clicked on.

Now that we understand the difference between visited and unvisited links, let’s take a look at how to style them in CSS.


The first step in styling visited and unvisited links is to identify the links on your website.

You can do this by using the “a” tag in CSS.

The “a” tag is used to define a hyperlink, which is the HTML element used for links.

Once you have identified the links on your website, the next step is to style the unvisited links.

To do this, you can use the “a” tag in CSS and add a color property.

For example:

a {
    color: blue;
}

This will set the color of all unvisited links to blue.

After styling the unvisited links, the next step is to style the visited links.

To do this, you can use the “a:visited” tag in CSS and add a color property.

For example:

a:visited {
    color: purple;
}

This will set the color of all visited links to purple.

Test Your Code

After you have added your CSS code, it’s important to test it to make sure that it’s working correctly.

You can do this by visiting your website and clicking on a few links.

If everything is working correctly, the unvisited links should be blue and the visited links should be purple.


In conclusion, styling visited and unvisited links in CSS is a simple and effective way to make your website more visually appealing and easy to navigate.

By using the “a” and “a:visited” tags in CSS and adding color properties, you can quickly and easily change the color of your links.

Also Read:

How Do I Vertically Center Text With CSS
How to Add a Blur Effect to the Shadow in CSS
How to Add a Button to an Image With CSS
How to Add a Color to the Shadow in CSS
How to Add a Form to a Full-width Image With CSS
How to Add Rounded Corners to Elements in CSS
How to Add space between an outline and the border of an element in CSS
How to Add White Text With Black Shadow in CSS
How to Align Images Side by Side With CSS
How to Align the text in CSS



Resources and References:

  1. CSS Resources – CSS Portal
  2. CSS: Cascading Style Sheets – MDN Web Docs
  3. CSS Tutorial – W3Schools
  4. CSS – Useful Resources – Tutorialspoint