In this tutorial, we will learn how to change color of link after clicking on it in HTML and CSS. When you are styling the link on a webpage, you want to change the default color of a link after clicking on it to make it easier for the users to navigate.
By default the visited link color is purple and underlined, but it’s very easy to change the visited link color by using CSS
:visited pseudo-class selector and color property.
In the following example, we have a link and upon clicking, we will change its color. Please have a look over the code example and the steps given below.
- In the HTML file, we have one anchor element with a
- In the head element, we have added a stylesheet (
style.css) using the link element.
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color change of link after clicking on it</title>
<link rel="stylesheet" href="./style.css">
We are selecting the anchor element with CSS
:visited pseudo-class selector and setting the CSS color property value to green. As a result, it will change the default visited link color to green after clicking on it.