CSS :link Selector

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 4 Examples
Link States

What You’ll Learn

The :link pseudo-class targets unvisited anchor links. It is the foundation of hyperlink styling alongside :visited, :hover, and :active.

01

Unvisited

Not clicked yet.

02

a:link

Anchor only.

03

Needs href

Real links.

04

LVHA

Correct order.

05

:visited

Pair together.

06

Navigation

Menu styling.

Introduction

The CSS :link selector is used to target unvisited links on a webpage. It allows you to style hyperlinks that have not been clicked yet, helping differentiate between visited and unvisited links.

This is useful for enhancing user experience by visually guiding users through available links on your site.

Definition and Usage

Write a:link to style anchor elements with an href attribute in their default, unvisited state. Once a user visits the URL, the link moves to the :visited state instead.

💡
Beginner Tip

Always declare link pseudo-classes in LVHA order: :link, :visited, :hover, :active. Wrong order can cause hover styles to be overridden by visited styles.

📝 Syntax

The syntax for the :link pseudo-class is:

syntax.css
a:link {
  /* CSS properties */
}

The :link pseudo-class only applies to <a> elements that have an href attribute and are in their unvisited state.

Basic Example

link-basic.css
a:link {
  color: #2563eb;
  text-decoration: none;
  font-weight: 700;
}

a:visited {
  color: #7c3aed;
  text-decoration: underline;
}
a:link nav a:link .menu a:link

LVHA Declaration Order

1. :link 2. :visited 3. :hover 4. :active

Syntax Rules

  • Only matches <a> elements with an href attribute.
  • Applies to links the browser has not yet visited in this session/history.
  • Declare before :visited, :hover, and :active (LVHA).
  • Does not match <a> without href (placeholder anchors).
  • Pair with :visited so users can distinguish clicked links.

Related Selectors

  • :visited — styles links the user has already visited
  • :hover — styles links while the pointer rests over them
  • :active — styles links while being clicked
  • :focus — styles links when focused via keyboard
  • :any-link — matches both unvisited and visited links

⚡ Quick Reference

QuestionAnswer
Selector typeLink pseudo-class
Syntaxa:link
MatchesUnvisited <a href> elements
Requireshref attribute on anchor
Declare orderLVHA — :link, :visited, :hover, :active
Browser supportAll browsers

When to Use :link

:link is essential for hyperlink presentation:

  • Default link color — Set the base appearance for all unclicked links.
  • Navigation menus — Style menu items before users explore the site.
  • Content links — Distinguish inline links in articles from body text.
  • Branded design — Remove default blue underline for a custom look.
  • Visited vs unvisited — Help users see which pages they have not opened yet.

👀 Live Preview

Unvisited links match a:link (blue, bold, no underline). Visited links use a:visited (purple, underlined):

Visit the following links:

Example Another Example

Examples Gallery

Practice :link with basic styling, navigation menus, the full LVHA stack, and focus states.

📜 Core Patterns

Style unvisited links and pair with :visited.

Example 1 — Style unvisited and visited links

Set blue bold text for unvisited links and purple underlined text for visited ones.

link-basic.html
<style>
  a:link {
    color: #2563eb;
    text-decoration: none;
    font-weight: 700;
  }
  a:visited {
    color: #7c3aed;
    text-decoration: underline;
  }
</style>

<p>
  Visit:
  <a href="https://www.example.com">Example</a>
  <a href="https://www.anotherexample.com">Another Example</a>
</p>
Try It Yourself

How It Works

Before a link is clicked, a:link applies. After visiting, the browser switches to a:visited so users can tell which links they have already opened.

Example 2 — Navigation menu links

Style unvisited nav links with a clean, underline-free look.

link-nav.css
nav a:link {
  color: #1e293b;
  text-decoration: none;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
}

nav a:visited {
  color: #64748b;
}
Try It Yourself

How It Works

Scoping to nav a:link limits styles to navigation links only, leaving inline content links unaffected.

📄 LVHA & Accessibility

Full link state stack and keyboard-friendly focus.

Example 3 — Complete LVHA link styles

Declare all four link states in the correct order for consistent behavior.

link-lvha.css
a:link {
  color: #2563eb;
  text-decoration: none;
}

a:visited {
  color: #7c3aed;
}

a:hover {
  text-decoration: underline;
}

a:active {
  color: #b91c1c;
}
Try It Yourself

How It Works

LVHA order ensures each state can override the previous one correctly. Putting :visited after :link prevents hover styles from being blocked.

Example 4 — :link with :focus for accessibility

Add a visible focus ring for keyboard users alongside default link styling.

link-focus.css
a:link {
  color: #2563eb;
  text-decoration: underline;
}

a:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
  border-radius: 2px;
}
Try It Yourself

How It Works

:focus-visible shows a focus indicator only for keyboard navigation, keeping mouse clicks clean while meeting accessibility requirements.

💬 Usage Tips

  • Pair with :visited — Always style both so users can distinguish clicked and unclicked links.
  • LVHA order — Declare :link, :visited, :hover, :active in that sequence.
  • Include :focus — Add :focus-visible for keyboard accessibility.
  • Scope selectors — Use nav a:link or .content a:link for targeted styling.
  • Contrast matters — Ensure link colors stand out from body text and meet WCAG contrast ratios.

⚠️ Common Pitfalls

  • Missing href:link does not apply to <a> without an href attribute.
  • Same styles for :link and :visited — Users cannot tell which links they have already opened.
  • Wrong LVHA order — Hover or active styles may not appear if declared before :visited.
  • Removing all underlines — Without another visual cue, links can be hard to spot in paragraphs.
  • Styling buttons as links — Use <button> for actions; reserve <a> for navigation.

♿ Accessibility

  • Visible links — Do not rely on color alone; use underline, icons, or bold weight where needed.
  • Focus indicators — Never remove focus outlines without providing an alternative (:focus-visible).
  • Contrast ratios — Link text must meet WCAG AA contrast against its background (4.5:1 for normal text).
  • Meaningful link text — Avoid “click here”; describe the destination in the anchor text.
  • Visited state — Helps users with cognitive disabilities track where they have been.

🧠 How :link Works

1

Anchor has href

The browser identifies <a href="..."> as a hyperlink.

HTML
2

Check visit history

If the URL is not in browser history, the link is in the unvisited state.

State
3

:link styles apply

CSS rules for a:link set the default unvisited appearance.

Style
=

Clear navigation

Users see which links are fresh and which they have already explored.

🖥 Browser Compatibility

The :link pseudo-class is supported in all modern browsers and has been available since CSS1.

Baseline · Universal support

Link styling everywhere

:link works reliably in Chrome, Firefox, Safari, Edge, and Opera.

99% Universal support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
:link pseudo-class 99% supported

Bottom line: :link is safe for all hyperlink styling in modern projects.

🎉 Conclusion

The CSS :link selector is a handy tool for styling hyperlinks that have not been clicked. It allows customization of unvisited links, enhancing visual clarity and navigation.

Pair it with :visited, :hover, and :active in LVHA order to create a consistent and engaging design for your website’s links.

💡 Best Practices

✅ Do

  • Declare LVHA order: :link, :visited, :hover, :active
  • Style :link and :visited differently
  • Add :focus-visible for keyboard users
  • Ensure sufficient color contrast
  • Use meaningful anchor text

❌ Don’t

  • Omit href and expect :link to work
  • Remove all visual link cues from paragraphs
  • Put :hover before :visited in CSS
  • Remove focus outlines without replacement
  • Use identical colors for :link and :visited

Key Takeaways

Knowledge Unlocked

Five things to remember about :link

Use these points when styling hyperlinks.

5
Core concepts
a 02

a:link

Needs href.

Syntax
LVHA 03

Order

Link first.

Rule
👁 04

:visited

Pair it.

Pair
🌐 05

99% support

All browsers.

Compat

❓ Frequently Asked Questions

The :link pseudo-class matches anchor elements with an href attribute that the user has not yet visited. It lets you style unvisited hyperlinks differently from visited ones.
Yes. The :link pseudo-class only applies to a elements that have an href attribute and are in the unvisited state. Anchors without href are not links.
Declare link pseudo-classes in this order to avoid cascade conflicts: :link, :visited, :hover, :active. This mnemonic is often called LVHA or LoVe HAte.
:link styles hyperlinks the user has not clicked yet. :visited styles links the browser has already visited. Always style both so users can tell them apart.
Yes. All modern browsers support :link. It has been a core CSS feature since CSS1 and works reliably for navigation and inline hyperlinks.

Practice in the Live Editor

Open the HTML editor and experiment with :link, LVHA order, and navigation styling.

HTML Editor →

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.

5 people found this page helpful