Link
Links in running text are ember and underlined. Navigation links are quieter because their position already says they're links.
Read the case study on Spotlight.me's discovery work to see the process.
Read the case study on Spotlight.me's discovery work to see the process.
Show code
<p>Read <a href="/insights/">our Insights</a> on prototyping.</p> When to use it
- To go to another page, or another part of this one, from a sentence.
- For an email address, a phone number or a file to download.
Use something else when:
- It is the main thing to do on the page: a button (which may still be a link underneath).
- It does something here and goes nowhere, such as opening a dialog: a real
<button>. - It is one of a set of topics on a card or an article: a tag.
States
- Rest: ember (
color.action.primary), underlined, offset 2 px from the text. - Hover: the underline thickens to 2 px. The colour doesn't change, so the link never looks disabled.
- Focus: the 2 px ember focus ring.
- Print: external links print their address after the text.
Section links on headings
Every content heading with an anchor (the same anchors search results jump to) has a link to its section (components/HeadingLinks.astro).
- Where: a link icon just after the end of the heading's text, on its last line. With a mouse it shows when you hover over the heading; on touch screens, where there's no hover, it is always shown, faintly. It also shows whenever it has keyboard focus. Headings keep a little room at the end of each line so the icon always fits inside the column.
- What it does: a click copies the section's address, puts it in the address bar and shows Link copied (also announced to screen readers). Right-click "Copy link", Cmd- or Ctrl-click, and visitors without JavaScript get an ordinary link to the section.
- Accessibility: the link sits next to the heading, not inside it, so headings keep just their own text in a screen reader's list of headings. Its name says which section it copies: "Copy link to 'Versioning'".
- Leaving it out: headings in dialogs, cards and examples are skipped; add
data-no-heading-linkto skip any other part of a page. Section links don't print.
Do and don't
Do
- Name the destination: "Read the Spotlight.me case study"
- Say when a link leaves the site or opens a file: "Download the checklist (PDF, 220 KB)"
Don't
- "Click here", "this page", "more"
- Open links in a new tab without saying so
- Underline text that isn't a link
Accessibility
What it does for you
- Links in running text are underlined as well as coloured, so they are never told by colour alone.
- Pointing at one thickens the underline; the colour doesn’t change.
- The usual 2px focus ring on keyboard focus.
- On paper, a link to another site prints its address after its words.
- Every heading with an address gets a link beside it, not inside it, named for its section: "Copy link to “States”". It shows on hover and whenever it has keyboard focus, and says "Link copied" out loud and in words.
What you need to do
- Words that name where the link goes, and make sense out of their sentence.
- Say so when a link opens a new tab or a file, in its words.
- A link that sits alone on a line, or in a list of short links, needs room to be tapped.
Keyboard
| Key | What it does |
|---|---|
| Tab | Moves to the link. |
| Enter | Follows it. On a heading’s link: copies the section’s address and puts it in the address bar. |
What a screen reader is told
- A link, named by its words.
- A heading’s link: "Copy link to" and the heading; then "Link copied".
This is what the browser reports to assistive technology. What each screen reader then says varies, and has not been listened to yet.
WCAG 2.2
| Criterion | Level | How this meets it |
|---|---|---|
| 1.4.1 Use of Color | A | Underlined, not only coloured. |
| 1.4.3 Contrast (Minimum) | AA | The link colour against the page, in light and dark. |
| 2.4.4 Link Purpose (In Context) | A | What a link says is the page’s to get right; a heading’s link names its section. |
| 2.4.7 Focus Visible | AA | A 2px ring on keyboard focus; a heading’s link appears when it has focus. |
| 2.5.8 Target Size (Minimum) | AA | A link inside a sentence is exempt; a heading’s link is 28px square. |
| 4.1.3 Status Messages | AA | "Link copied" is announced without moving focus. |
The criteria this component has a part in. A page that uses it still has to meet the rest.
Checked
| Check | How | Result |
|---|---|---|
| Automated (axe-core) | WCAG 2.0, 2.1 and 2.2 rules at A and AA, the page in light and in dark | Passed Nothing found, light or dark |
| Narrow screen | No sideways scrolling at 320px wide (WCAG 1.4.10) | Passed No sideways scrolling |
| Keyboard and what the browser reports | Real key presses on the live example, and the role, name and state given to assistive technology | Passed 8 of 8 checks pass |
| On paper | Somnia’s print check: no overlaps, stranded headings or controls on the page | Passed No faults on 5 sheets |
| Screen reader | Listened to by a person, in VoiceOver and NVDA | Not yet Not yet checked by a person |
The 8 checks made with the keyboard, on the example at the top of this page:
- Passed A link in running text is underlined as well as coloured
- Passed Its colour has at least 4.5:1 against the page, in light and dark
- Passed Pointing at it thickens the underline, and the colour stays
- Passed Tab reaches a link and shows the focus ring
- Passed Each heading has a link beside it, not inside it, named for its section
- Passed A heading’s link appears when it has keyboard focus
- Passed Enter on it copies the section’s address, puts it in the address bar and announces "Link copied"
- Passed A heading’s link is at least 24px square
Run by script on against Somnia DS 1.89.0, in Chromium with axe-core 4.14.0. How these checks work, and every component's results.
Not yet checked
- How it sounds in a screen reader (VoiceOver, NVDA, TalkBack) has not been checked by a person. The roles, names and states the browser reports are checked by script; what is actually spoken is not.
- Windows high contrast (forced colours) has not been looked at by a person.
- Link text across the sites has not been read through for "click here" and links that make no sense alone.
Evidence
Where it's used
| Where | For |
|---|---|
| Every Somnia site | Running text in articles, case studies, legal pages and these docs. |
| Heading links | Every content heading with an address on every site: the same addresses search results jump to. |
What we saw, and what changed
| When | What we saw | What changed |
|---|---|---|
| The link style reached buttons and components inside articles, and hid a button’s words on dark Insight pages. | It applies to running text only; anything marked not-prose keeps its own links (1.3.2). | |
| Headings had addresses but nothing on the page to copy one from. | A link beside each heading that copies its address (1.11.0). | |
| The heading link sat in the left margin, on wide screens only. | It sits just after the heading’s words, shown on hover, and always, faintly, on touch screens (1.14.0). | |
| A link to a section that was folded shut landed on a closed heading. | A link to a folded section, or to anything inside one, opens it first (1.38.0). |
From building and using it on real sites, each entry taken from the changelog or the build's own notes. This is observation by the studio and its clients, not research sessions with users.
What it rests on
- WCAG technique G201: Giving users advanced warning when opening a new window: Say in the link that it opens a new window or tab, so nobody is taken by surprise. Advisory, not required.
What we don't know yet
- Which links in an article are followed is not counted.