The anchor element creates hyperlinks to web pages, files, email addresses, locations within the same page, or any other URL.
Progressive Enhancement
The anchor element is the fundamental building block of the web. It works in every browser with zero CSS or JavaScript.
- HTML-first: Links function without any styling — the browser provides default blue/purple colors and underlines
- CSS-enhanced: Vanilla Breeze adds interactive colors, hover effects, auto-detected link-type indicators, and focus rings
- Works without JavaScript: Styling and auto-detection are CSS; the only script is the optional
noopener upgrade for new-tab links
When to Use
- Navigation: Links in site navigation, menus, and breadcrumbs
- In-page links: Table of contents linking to sections
- External resources: Linking to external sites and references
- Downloads: Use with
download attribute for downloadable files
- Contact links: Use
mailto: and tel: protocols
When NOT to Use
- Actions: Use
<button> for toggles, dialogs, form submission, or state changes
- Dialogs: Use
<button commandfor="..." command="show-modal"> via the Invokers API
Auto-Detection
Vanilla Breeze automatically detects and adds visual indicators to special link types using CSS only. The glyphs are decorative: they carry empty alternative text, so screen readers read only the link text.
| Link Type |
Detection |
Indicator |
| External |
href^="http" or href^="//" |
↗ arrow after text |
| Download |
[download] |
↓ arrow after text |
| Email |
href^="mailto" |
✉ envelope before text |
| Phone |
href^="tel" |
☎ phone before text |
| PDF |
href$=".pdf" |
PDF badge after text (a download link to a PDF shows the download arrow instead) |
External detection is a string match on the URL, so an absolute link to your own site (https://your-site.com/…) also gets the arrow. Use root-relative URLs for internal links, or add data-no-icon.
<a href="https://example.com">Example.com</a>
<a href="/files/report.pdf" download>Download the PDF</a>
Custom Link Icons
Use icon-wc inside links for custom icons. A link with an <icon-wc> child drops its auto-detected glyph, so you never get two icons. data-no-icon suppresses the indicator explicitly.
<a href="/files/report.pdf" download data-no-icon> <icon-wc name="file-text" size="xs"></icon-wc> Annual Report (PDF)</a> <a href="https://github.com/example" data-no-icon> <icon-wc name="github" size="xs"></icon-wc> View on GitHub</a>
Suppressing Auto-Icons
Use data-no-icon to suppress automatic icons. Links inside <nav>, <header>, and <footer>, and button-styled links, suppress every auto-icon — no attribute needed.
<a href="https://example.com" data-no-icon>Example.com</a>
Variants
Use data-variant to change link appearance.
<a href="#">default link</a>
<a href="#" data-variant="muted">muted link</a>
<a href="#" data-variant="plain">plain link</a>
Use plain sparingly. Without an underline, a link inside running text is distinguished by colour alone, which fails WCAG 1.4.1. Keep it for places where context already says "this is a link": card titles, lists of links, navigation.
Button-Styled Links
Use class="button" on a link to give it button styling. This is for links that navigate to another page but need the visual weight of a button — hero CTAs, sign-up links, prominent calls to action.
All button variants and sizes work: .secondary, .ghost, .small, .large, and .full-width. Auto-icons are automatically suppressed on button-styled links.
<a href="/get-started/" class="button">Get Started</a><a href="/docs/" class="button secondary">Documentation</a><a href="/learn/" class="button ghost">Learn More</a>
<a href="#" class="button small">Small</a><a href="#" class="button">Default</a><a href="#" class="button large">Large</a>
Note: For actions that don't navigate (toggles, form submission, dialogs), use <button> instead.
Links Wrapping Content
When links wrap images, pictures, figures, or cards, the underline is automatically removed via the CSS :has() selector.
<a href="#"> <img src="image.jpg" alt="..." /></a>
<a href="#"> <layout-card data-padding="m"> <p>Click this entire card</p> </layout-card></a>
Context Overrides
Auto-icons are suppressed in certain contexts to keep UI clean:
1234567891011121314151617
:is(nav, header, footer) a:is([href^="http"], [href^="//"], [download], [href$=".pdf"])::after,:is(nav, header, footer) a:is([href^="mailto"], [href^="tel"])::before { content: none;} a:is([href^="mailto"], [href^="tel"]):has(> icon-wc)::before,a:is([href^="http"], [href^="//"], [download], [href$=".pdf"]):has(> icon-wc)::after { content: none;} a.button:is([href^="http"], [href^="//"], [download], [href$=".pdf"])::after,a.button:is([href^="mailto"], [href^="tel"])::before { content: none;}
Link Relations
The rel attribute is styled too, through src/utils/links.css. See Link relations for the full vocabulary.
rel value |
Presentation |
external | ↗ arrow after text (replaces the href-based detection, so there is only one arrow) |
help | Dotted underline |
tag | Pill chip |
prev / next | ← before / → after the text |
license, privacy-policy, terms-of-service | Muted, slightly smaller |
Safe new-tab links
When a page contains <a target="_blank">, a small enhancement loads and adds rel="noopener" to any such link that doesn't already declare an opener policy. Add data-link-privacy="strict" to <html> to also add noreferrer. It is opt-in because referral analytics depend on the Referer header.
Key Attributes
| Attribute |
Description |
href |
The URL the link points to (required for a functional link) |
target |
Where to open the link (_blank for new tab) |
rel |
Relationship to the linked resource (noopener, external, help…) |
download |
Prompts download instead of navigation (same-origin URLs only) |
hreflang |
Language of the linked document |
ping |
URLs notified with a POST when the link is followed |
referrerpolicy |
How much referrer information to send |
data-variant |
Visual variant: muted | plain |
data-no-icon |
Suppress auto-detected link type icons |
CSS Properties
| Property |
Value |
color |
var(--color-interactive) |
text-decoration |
underline |
text-decoration-thickness |
1px (default), 2px (hover) |
text-underline-offset |
0.15em |
transition |
var(--duration-fast) var(--ease-default) |
Link States
Hover
Underline thickness increases from 1px to 2px on hover.
Focus
A visible focus ring appears when navigating via keyboard (uses :focus-visible with var(--color-interactive) outline).
Visited
Vanilla Breeze deliberately does not style :visited links, so links look the same wherever they appear. This is a design choice: browsers already limit which properties :visited can change, to prevent history sniffing, whether or not a stylesheet uses it.
Accessibility
- Descriptive link text: Avoid "click here" or "read more" — use meaningful text that describes the destination
- Visual distinction: Links have underlines by default — color alone is not sufficient to identify links
- Focus visibility: Links have visible focus rings for keyboard navigation
- New tab warning: When links open in new tabs, inform users
- Skip links: Use anchor links to create "skip to content" navigation
External Link Best Practice
For links that open in a new tab, add a visually hidden notice for screen reader users:
<a href="https://example.com" target="_blank" rel="noopener noreferrer"> Example.com <span class="visually-hidden">(opens in new tab)</span></a>