HTML Link Colors
In this page:
<style>
a:link { color: colorvalue; }
a:visited { color: colorvalue; }
a:hover { color: colorvalue; }
a:active { color: colorvalue; }
</style>
The Default Unvisited Link
The :link pseudo-class targets an anchor element that has not yet been visited by the user, and is the state most links are in by default.
Using :link instead of styling the anchor tag directly lets you target only unvisited links specifically, separate from visited ones.
Example: The Default Unvisited Link
In this preview, the link hasn't been visited, so it renders in the color set by a:link (blue by default) until it's clicked.
<style>
a:link {
color: blue;
}
</style>
<a href="page.html">Unvisited link</a>
Marking Visited Links
:visited targets links the browser recognizes the user has already clicked before, letting you distinguish "read" links from "unread" ones, commonly used to gray out visited search results or wiki links.
Example: Marking Visited Links
This purple color only appears after a link has actually been clicked and visited — in a fresh preview like this one, the link still shows its unvisited (:link) color until you click it.
<style>
a:visited {
color: purple;
}
</style>
<a href="page.html">Visited link</a>
Highlighting on Hover
:hover applies styles the moment a mouse pointer moves over a link, and disappears the instant the pointer moves away, giving users immediate visual feedback that an element is interactive before they even click it.
Example: Highlighting on Hover
<style>
a:hover {
color: red;
}
</style>
<a href="page.html">Hover over me</a>
Styling the Active Click Moment
:active applies only during the brief moment a link is actively being pressed down, between mouse-down and mouse-up, giving tactile visual feedback that a click registered, similar to how a physical button visibly depresses when pushed.
Example: Styling the Active Click Moment
<style>
a:active {
color: orange;
}
</style>
<a href="page.html">Click and hold me</a>
Custom Link Themes
Combining all four pseudo-classes lets you build a fully custom link theme that matches your site's design instead of relying on the browser's default blue-purple scheme, while still preserving the underlying behavioral feedback users expect from links.
Example: Custom Link Themes
<style>
a:link { color: teal; }
a:visited { color: gray; }
a:hover { color: coral; }
a:active { color: darkred; }
</style>
<a href="page.html">Themed link</a>
- Declaring the four link pseudo-classes out of order, which can cause later rules to silently override earlier ones due to normal CSS specificity and source order rules.
- Forgetting that :visited can only style a very limited set of properties (mainly color) for privacy reasons, unlike the other link states.
- Removing text-decoration: underline from links without adding any other visual signal, making links hard to distinguish from plain text.
- The classic link order is Link, Visited, Hover, Active -- often remembered with the mnemonic "LoVe HAte".
- :hover styles apply while the mouse is over the link, and :active applies only during the actual click.
- :visited is restricted by browsers to a small set of stylable properties to prevent websites from detecting a user's browsing history.
All four link pseudo-classes (:link, :visited, :hover, :active) are supported in every browser and have been part of CSS since CSS1.
Chapter Quiz — Complete all 26 topics to unlock
0/26 topics done
Complete these topics first:
- HTML Favicon
- HTML Page Title
- HTML Tables
- HTML Lists
- HTML Block & Inline
- HTML Comments
- HTML Colors
- HTML CSS
- HTML Links
- HTML Images
- HTML RGB Colors
- HTML HEX Colors
- HTML HSL Colors
- HTML Link Colors
- HTML Link Bookmarks
- HTML Background Images
- HTML Table Borders
- HTML Table Sizes
- HTML Table Headers
- HTML Table Padding & Spacing
- HTML Colspan & Rowspan
- HTML Table Styling
- HTML Table Colgroup
- HTML Unordered Lists
- HTML Ordered Lists
- HTML Other Lists / Description Lists