CSS :link Pseudo-class

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The :link pseudo-class matches a hyperlink that has not been visited yet.

In practice that means an <a> (or <area>) with an href that is not in the browser’s history. It is mutually exclusive with :visited. For all links regardless of history, use :any-link.

Baseline · Widely available.

Not deprecated. A long-standing link pseudo-class from Selectors / HTML.

Order matters LVHA

Put :link before :visited, :hover, and :active so hover/active can override it (LVHA order).

CSS Syntax

syntax.css
:link { /* or */ a:link { … }

Example: a:link { color: forestgreen; }

Selector Forms

FormDescriptionTry it
a:linkStyle unvisited anchorsTry it
Needs hrefPlaceholder <a> without href does not matchTry it
LVHA stack:link then visited, hover, activeTry it
DecorationColor + underline on unvisited linksTry it
BackgroundHighlight unvisited links with a backgroundTry it
List of linksStyle several unvisited list linksTry it

How to Use :link

Target unvisited links first, then layer visited and interaction states.

  1. Ensure the element is a real hyperlink (href present).
  2. Write a:link { … } for the unvisited look.
  3. Add :visited, :hover, and :active after it (LVHA).
  4. Prefer properties browsers still allow on visited links (for privacy) when styling both states.

Live Preview

Fresh URLs usually match a:link. The placeholder without href never matches. Toggle the style on/off.

Link sample

Uses unlikely URLs so they stay unvisited in most histories.

Interactive

CSS Examples

Each snippet focuses on :link. Extra styles stay minimal for study. Use Try It Yourself for a live editor.

Example 1 — Style Unvisited Links

Give unvisited anchors a green color.

CSS
<style>
  a:link {
    color: forestgreen;
    text-decoration-color: hotpink;
  }
</style>

<p><a href="https://example.com/a">Demo link A</a></p>
<p><a href="https://example.com/b">Demo link B</a></p>
Try It Yourself

How It Works

  1. Pick anchors. a:link only considers link elements.
  2. Require unvisited. The URL must not be in history for :link to apply.
  3. Set color. Forest green text with a hotpink underline color.
  4. After a visit. The same URL then matches :visited instead.

Example 2 — href Is Required

An <a> without href is not styled by :link.

CSS
<style>
  a:link {
    background-color: gold;
    color: green;
  }
</style>

<a href="#ordinary-target">Ordinary link</a><br>
<a>Placeholder link (won't get styled)</a>
Try It Yourself

How It Works

  1. Hyperlink check. :link needs an href.
  2. First anchor. It has href, so unvisited styling applies.
  3. Second anchor. No href, so it is not a matching link.
  4. Takeaway. Placeholders stay unstyled by a:link.

Example 3 — LVHA Order

Write :link first so hover and active can override it.

CSS
<style>
  a:link { color: #1d4ed8; }
  a:visited { color: #7c3aed; }
  a:hover { color: #dc2626; }
  a:active { color: #ea580c; }
</style>

<a href="https://example.com/lvha-demo">Hover and click me</a>
Try It Yourself

How It Works

  1. Link first. Unvisited default is blue via :link.
  2. Visited next. After a visit, purple can apply.
  3. Hover / active last. Interaction states win while you hover or press.
  4. Wrong order. Putting :link after :hover can block hover styles.

Edge Cases & Pitfalls

Most surprises come from history, missing href, or cascade order.

href

No href = no match

An <a> used only as a button-like wrapper without href will not match :link.

history

Visited URLs leave :link

Once a URL is in history, it matches :visited instead. Clear history or use a fresh demo URL to retest.

order

Remember LVHA

Write :link → :visited → :hover → :active so interaction styles can override.

both

Need every link?

Use :any-link (or a[href]) when visited state should not matter.

privacy

Visited styles are limited

Browsers restrict which properties :visited can change. Prefer shared base styles, then small differences for unvisited/visited.

Browser Support

:link is a browser CSS pseudo-class. Node.js, Deno, and Bun do not evaluate it.

✓ Baseline · Widely available

:link

Supported in all major browsers for many years (Chrome 1+, Firefox 1+, Safari 1+, Edge 12+, Opera 7+, IE 3+/6+ depending on engine era).

98% Global support
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 7+
Full support
Samsung Internet 1+
Full support
Internet Explorer 3+
Full support
:link Widely supported

Bottom line: Safe everywhere for modern sites. It is not a JavaScript runtime API.

Key Takeaways

  • Role: style unvisited hyperlinks with href.
  • Pair: mutually exclusive with :visited.
  • Order: LVHA — link, visited, hover, active.
  • All links: use :any-link when history should not matter.

One line: :link styles unvisited href links—write it before visited/hover/active.

Frequently Asked Questions

It matches hyperlinks that have not been visited yet—typically an <a> or <area> element with an href attribute that is not in the browser’s visited history.
No. An <a> without href is not a hyperlink for :link. Only elements with href that are still unvisited match.
Write link styles in this order for predictable results: :link, then :visited, then :hover, then :active. Later rules with equal specificity override earlier ones.
They are mutually exclusive. :link matches unvisited links; :visited matches visited ones. A single link never matches both at once.
Use :any-link (matches :link or :visited), or style a[href] if you only need attribute matching.
No. It is a CSS pseudo-class evaluated by the browser layout engine, not a Node.js or server runtime feature.

Next: :not() Pseudo-Class

Continue through the CSS tutorial reference.

:not() Pseudo-Class tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful