HTML Link Colors
In this page:
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.
Note: Style :link the same as the plain a selector unless you specifically want unvisited links to look different from visited ones.
Warning: :link only applies to anchors with an href attribute; a plain anchor tag used as a scroll target has no link state to style.
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.
Note: Use a slightly muted color for :visited links so users can tell at a glance which pages they have already explored.
Warning: Browsers deliberately restrict :visited to a small set of safe properties like color, to prevent a page from probing a user's browsing history.
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.
Note: Keep hover transitions short (100-200ms) so the color change feels responsive rather than sluggish.
Warning: :hover has no equivalent effect on touchscreens, since there is no mouse pointer to hover with, so never rely on it alone to convey critical information.
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.
Note: Give :active a noticeably different, punchier color than :hover so users feel a distinct "click confirmed" moment.
Warning: On touchscreens, :active often only flashes very briefly, so avoid making its styling carry information users need time to read.
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.
Note: Even when customizing colors fully, keep some form of visual distinction (like an underline) between links and plain text for accessibility.
Warning: A custom link theme that removes all color and underline differences from surrounding text can make links effectively invisible to users.
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