Lesson 04 · Part 1 · Links

Linking content

A link takes you somewhere. A button does something on this page. The element you pick is the role a screen reader announces, and the keyboard behaviour the browser gives you for free. Then the link text has to say where it goes.

In one minute

In plain words

A link is a road sign. "Read more" is a sign that says only "Road". If you drive past forty signs that all say "Road", you learn nothing. Screen reader users often hear all the signs at once as a list, so every sign has to name its destination.

1. Real link or clickable text?

A real <a href> is in the tab order, announced as "link", opens with Enter, can be opened in a new tab by right click, and works before your JavaScript loads. Text with a click handler has none of that. The role is what kind of thing the element is, and assistive technology announces it.

Step 1. Choose the markup, then press Tab to find it and Enter to use it.


          

Clickable text

Bad
Read the notes

Not in the tab order. No role of link.

Real link, real name

Fixed
Read the notes on buttons

Tab to it. The name says where it goes, not "click here".

2. The name says where it goes

The accessible name is the link text. Screen readers can list every link on a page, out of context. "PDF" is a bad name. "Invoice March (PDF)" is a good one. This is WCAG 2.4.4 (Link Purpose in Context) and, stricter, 2.4.9 (Link Purpose, link only).

Step 1. Pick the wording for four links on a news page. Then read the links list.

Links list (what the screen reader offers)

The third option uses visually hidden text inside the link: Read more<span class="sr-only"> about the bus strike</span>. It works, but the visible text must still be part of the name so voice control users can say "click Read more" (WCAG 2.5.3 Label in Name).

3. Warn about changes: new tab, downloads, mail, phone

Opening a new tab, starting a download, or launching the mail app are surprises. Someone using a magnifier may not see the new window appear, and a screen reader user may not know the old page is still open behind it. Say it in the name. Do not rely on an icon alone.

Step 1. Choose the kind of link, then switch the name between bare and informative.


          

4. Image links: alt is the destination

When an image is the only thing in a link, its alt text becomes the link name. It should say where the link goes, not what the picture looks like (WCAG 1.1.1, 2.4.4).

Step 1. Choose the alt text for a logo that links to the home page.


          

5. Apps: the link worked only if the document says so

In a client-rendered app, clicking a link swaps the content without a reload. The browser does not announce a new page, so you must. Update document.title, and move focus to the new page's heading (or announce the change). Otherwise a screen reader user hears nothing, and a keyboard user is left on a link that no longer matters.

Step 1. Choose how the router behaves, then activate a link.

Home · Northwind (simulated browser tab)

Home

Welcome to Northwind.

Common mistakes

You seeWhy it is a problemFix
<span onclick> as a linkNo focus, no role, no Enter.<a href>
"Click here", "Read more"Meaningless in a links list.Name the destination.
<a href="#"> that runs scriptAnnounced as a link but goes nowhere.Use a button.
New tab with no warningUsers lose their place."(opens in a new tab)" in the name.
Image link with alt="image"Name is "image, link".Alt = destination.
Route change without a title updateScreen reader says nothing happened.Set document.title and move focus.
Try it yourself
  1. Find a "Learn more" link in a product you use. Rewrite the name so it still makes sense when all links are read as a list.
  2. Press Tab through lab 1 with the real link selected. Where does the focus ring appear?
  3. Open a link with Ctrl/Cmd + click. Does it work? (It only does if it is a real <a href>.)

Remember

Edit this example in the playground