CSS Links

Links are an essential part of any web page. They allow users to navigate between different pages, as well as to access external resources. CSS can be used to style links in a variety of ways, making them more visually appealing and easier to use.

Basic styling

The most basic way to style a link in CSS is to use the color property. This property can be used to change the color of the text of the link. For example, the following CSS will change the color of all links to blue:

Try yourself
        
            a {
  color: blue;
}
        
    

The text-decoration property can be used to add an underline, overline, strikethrough, or none to the text of the link. For example, the following CSS will add an underline to all links:

Try yourself
        
            a {
  text-decoration: underline;
}
        
    

The background-color property can be used to change the background color of the link. For example, the following CSS will change the background color of all links to yellow:

Try yourself
        
            a {
  background-color: yellow;
}
        
    

Link states

The appearance of a link can be changed depending on its state, such as when the user hovers over it or clicks on it. The following are the four link states in CSS:

Styling Visited Links:

CSS Pseudo-class: To style visited links differently from unvisited links, you can use the :visited pseudo-class.

Try yourself
        
            a:visited {
   color: #800080;
}
        
    
Hover Effects:

CSS Pseudo-class: The :hover pseudo-class allows you to apply styles when the user hovers over a link.

Try yourself
        
            a:hover {
   text-decoration: underline;
}
        
    
Active Links:

CSS Pseudo-class: The :active pseudo-class targets links when they are being clicked.

Try yourself
        
            a:active {
   color: #ff0000;
}
        
    
Conclusion

CSS can be used to style links in a variety of ways, making them more visually appealing and easier to use. By following the best practices outlined above, you can create links that are both stylish and functional.