Disable color change of anchor tag when visited
Stop visited links from changing color by applying the same styles to the :link
and :visited
pseudo-classes:
This rule ensures that the link always stays blue no matter its visit status.
Role of pseudo-classes sequence
Anchor pseudo-classes sequence plays a key role in CSS styling. Remember the acronym—LoVe/HAte (link, visited, hover, active). The correct sequence is:
To completely remove the visited color, you can simply skip defining a color for the :visited
pseudo-class:
Keeping it consistent
A consistent user experience can be achieved by using the inherit value. This ensures the anchor retains the color of its parent element:
The browser-default approach
A universal method without defining a manual color for visited links involves employing system color values:
Note: System color values like LinkText
might not be supported across all browsers. They should be used wisely, keeping in mind the potential compatibility issues.
Sass and @extend
While using Sass, @extend
can avoid repetitions. However, be cautious as it might inflate the CSS file size.
Use @extend
sparingly to retain the balance between maintainability and performance.
Was this article helpful?