To change the link color on click in CSS you can use the :active
pseudo-class selector. The :active
selector allows you to add styles to the links only for that moment when the link is being clicked i.e. the user is still holding down the mouse.
As soon as the user finishes clicking the link these styles are completely removed from it.
The following example changes the link color to red as soon as you click the link:
Example:
a:active{ color: red; }
You can also add other styles such as background-color, font-size, text-decoration, etc while the link is being clicked.
The following example changes the background color of the link to Yellow as soon as you click on it:
Example:
a:active{ color: red; background-color: yellow; }