How to Change Link Color on Click in CSS?

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;
}

Author

  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.

    View all posts