Links
Link purpose
Screen readers enable users to skim links on a page, moving from one to the next without declaring the neighboring text. Whenever possible, provide link text that identifies the purpose of the link without needing additional context. According to the Canada.ca Content Style Guide, “Your links should be descriptive and able to stand alone so that it's clear what people can expect if they click on them.
”
People with visual disabilities can also determine the purpose of a link by exploring the link's context. If writing stand-alone link text is impossible, ensure the link text identifies its purpose in combination with one of the following:
- The enclosing sentence
- The enclosing list item
- The enclosing paragraph
- The enclosing table cell and table header cell
- The parent list item of a nested list (example follows)
Do not use information-empty link text such as “click here
” or “Read More
” etc.
If two or more links on the same page have identical link text but different destinations, you can distinguish the links from one another in one of three ways:
- Rephrase the link text.
- Use an ARIA label (either the
aria-label
oraria-labelledby
attribute). The ARIA label supercedes the native link text in assistive technology. Be sure to include the visible link text in the ARIA label, so voice input users can target the link (see Link Activation, below). - Add visually-hidden text to the link text (example follows).
Link vs button
Developers frequently confuse the link and button roles, passing the confusion on to screen reader users. Users expect links to navigate (across pages or within a page), and buttons to trigger a local effect (or submit a form). A screen reader user can be disorientated when activating a button and instead navigating to a new page, or when activating a link and instead interpreting a local button effect.
Bad example: Vague link text
In this example, the link text “how much
” communicates nothing useful:
Example begins
A Food Guide Serving is simply a reference amount. It helps you understand how much food is recommended every day from each of the four food groups. In some cases, a Food Guide Serving may be close to what you eat, such as an apple. In other cases, such as rice or pasta, you may serve yourself more than one Food Guide Serving.
Example ends
Good example: Descriptive link text
In this example, the purpose of the link is perfectly clear.
Example begins
A Food Guide serving is how much food you should eat from each of the 4 food groups every day. In some cases, a serving is the amount of a given food group that you normally eat in one sitting, like an apple. In other cases, the daily amount is more than one serving, such as for rice or pasta.
Number of daily food servings for children, teens and adults
Example ends
Good example: Using aria-label for link purpose
In this example, the visible link text “Access
” is repeated for each resource. When there's no avoiding duplicated, visible link text, you can distinguish each instance with the aria-label
attribute.
HTML
Code begins
<h1>Tools and resources</h1>
<h2>Planning Accessible Virtual Events – Job Aid</h2>
<p>[Description of the resource]</p>
<p>
<a href="[...]" aria-label="Access Planning Accessible Virtual Events – Job Aid">Access</a>
</p>
<h2>Employees with Disabilities Network (EwDN)</h2>
<p>[Description of the resource]</p>
<p>
<a href="[...]" aria-label="Access Employees with Disabilities Network">Access</a>
</p>
Code ends
Good example: Using aria-labelledby for link purpose
Again, the visible link text “Access
” is repeated for each resource. You can distinguish each instance with the aria-labelledby
attribute, pointing to one or more id
attribute values of elements containing the desired label. In this example, the label concatenates the link text + the preceding heading.
Note that one instance of the link text “Access
” with an id
attribute can be referenced by multiple ARIA labels, which may be more convenient than creating an id
attribute for each instance of the link “Access”.
HTML
Code begins
<h1>Tools and resources</h1>
<h2 id="planning-virtual">Planning Accessible Virtual Events – Job Aid</h2>
<p>[Description of the resource]</p>
<p>
<a id="linktext" href="[...]" aria-labelledby="linktext planning-virtual">Access</a>
</p>
<h2 id="ewdn">Employees with Disabilities Network (EwDN)</h2>
<p>[Description of the resource]</p>
<p>
<a href="[...]" aria-labelledby="linktext ewdn">Access</a>
</p>
Code ends
Good example: Using visually-hidden text for link purpose
In this example, the duplicated link text “Access
” is extended with text that’s been visually-hidden using the CSS "clip" method. The text is invisible, but it’s still in the HTML and so is encountered by assistive technology.
HTML
Code begins
<h1>Tools and resources</h1>
<h2>Planning Accessible Virtual Events – Job Aid</h2>
<p>[Description of the resource]</p>
<p>
<a href="[...]">
Access
<span class="wb-inv">Planning Accessible Virtual Events – Job Aid</span>
</a>
</p>
<h2>Employees with Disabilities Network (EwDN)</h2>
<p>[Description of the resource]</p>
<p>
<a href="[...]">
Access
<span class="wb-inv">Employees with Disabilities Network</span>
</a>
</p>
Code ends
CSS
Code begins
.wb-inv {
clip: rect(1px,1px,1px,1px);
height: 1px;
margin: 0;
overflow: hidden;
position: absolute;
width: 1px;
}
Code ends
Related WCAG resources
Related WCAG resources
Success criteria
Techniques
- G91: Providing link text that describes the purpose of a link
- G53: Identifying the purpose of a link using link text combined with the text of the enclosing sentence
- H30: Providing link text that describes the purpose of a link for anchor elements
- H77: Identifying the purpose of a link using link text combined with its enclosing list item
- H78: Identifying the purpose of a link using link text combined with its enclosing paragraph
- H79: Identifying the purpose of a link in a data table using the link text combined with its enclosing table cell and associated table header cells
- H81: Identifying the purpose of a link in a nested list using link text combined with the parent list item under which the list is nested
- ARIA7: Using aria-labelledby for link purpose
- ARIA8: Using aria-label for link purpose
- C7: Using CSS to hide a portion of the link text
Failures
- F84: Failure of Success Criterion 2.4.9 due to using a non-specific link such as "click here" or "more" without a mechanism to change the link text to specific text.
- F89: Failure of Success Criteria 2.4.4, 2.4.9 and 4.1.2 due to not providing an accessible name for an image which is the only content in a link
Link activation
Some people with disabilities are not able to use a mouse and instead leverage mechanisms such as keyboard, voice control and alternative pointing devices to navigate and interact with web. Ensure that links (and buttons and other controls) are focusable and actionable by keyboard and voice input and not just via a mouse.
Native links are keyboard-activated by pressing the Enter key. If you design a custom link using the ARIA role="link"
attribute and a div
or span
element, include:
- A
tabindex="0"
attribute, so that the custom link receives keyboard focus via the Tab key. - A JavaScript event listener for the Enter key for activation, in addition to mouse click.
To activate a link using voice input, the user declares the name of the link as visible. When using aria-label
or aria-labelledby
to name a link, ensure the link's visible text matches or is included in the ARIA label. Otherwise, voice input users won't be able to target the link by name, forcing them to switch to less efficient techniques to activate the link.
Related WCAG resources
Related WCAG resources
Success criteria
Techniques
- G202: Ensuring keyboard control for all functionality
- G90: Providing keyboard-triggered event handlers
- SCR20: Using both keyboard and other device-specific functions
- SCR35: Making actions keyboard accessible by using the onclick event of anchors and buttons
- SCR2: Using redundant keyboard and mouse event handlers
- G208: Including the text of the visible label as part of the accessible name
- G211: Matching the accessible name to the visible label
Failures
Visual focus indicator
For keyboard only users, visually tracking where they are in a page can be challenging. Mouse users can roam the page and receive two clues about actionable items: the mouse arrow turns into a hand when hovering over an actionable item, and the element displays its "hover" state to indicate it’s actionable (e.g., an underline appears under a link).
Typically, keyboard users press the Tab key to navigate the interactive elements on a web page (links, buttons, form fields, custom controls).
- Tabbing to an item gives it keyboard "focus", at which point it can be activated with the keyboard. See the section Focus and focus order later in this module.
- Sighted keyboard users need visible feedback of a control's focus state.
Web browsers provide a default visual focus indicator that varies in appearance by browser but usually consists of a border or outline around the focused element.
- Always avoid styles that remove or limit the visibility of keyboard focus indicators. The browser default visual focus indicator can be removed with CSS
outline:0
oroutline: none
, which is a common barrier and anti-pattern. - It's best practice to use CSS to design a highly-visible focus indicator with strong contrast.
Bad example: Visual focus indicator is removed
All browsers display a visible outline around the element that currently has keyboard focus, which can be disabled using the outline: 0
or outline: none
CSS property. If the visual focus indicator is removed, sighted keyboard users will have no idea which link has the focus, making it difficult or impossible to navigate the web page.
CSS
Code begins
a:focus {
outline: none;
}
Code ends
Good example: Canada.ca visual focus indicator
In this example, the first link in a menu of three has a visual focus indicator consisting of a thick black outline, set closely to the text.
CSS
Code begins
a:focus {
outline: 2px auto -webkit-focus-ring-color;
outline-offset: -2px;
}
Code ends
Related WCAG resources
Related WCAG resources
Success criteria
Techniques
- G149: Using user interface components that are highlighted by the user agent when they receive focus
- G165: Using the default focus indicator for the platform so that high visibility default focus indicators will carry over
- G195: Using an author-supplied, highly visible focus indicator
- C15: Using CSS to change the presentation of a user interface component when it receives focus
- C40: Creating a two-color focus indicator to ensure sufficient contrast with all components
- SCR31: Using script to change the background color or border of the element with focus
Failures
Distinguishing links from text
Users with low vision and colour blindness need to distinguish links from neighboring text. The easiest way to do this is with an underline on the link.
When colour is used as the only way to identify a link (meaning the underline has been removed), two conditions must be met:
- 3:1 contrast between the body text and the link text.
- A "visual cue" (not just a color change) that appears on mouse hover and keyboard focus. The most common way to meet this is to underline the link on hover and focus, but you could also provide a background colour or border or outline.
Note that this is only an issue when the link and the body text appear together. It doesn’t apply to links in the header or stacked in a menu, where they’re understood to be links by their position on the page.
These requirements are in addition to the minimum text contrast requirement of 4.5:1 (see tutorial module 7 Visual design and colours > Contrast). It can be difficult to find a link colour that has both a 3:1 contrast with black body text and a 4.5:1 contrast with a white background. WCAG Technique G183 lists colour values that do, in Example 1 (see Related WCAG resources, below).
Related WCAG resources
Related WCAG resources
Success criteria
Techniques
Links that open in a new window
Links open in a new window via the target="_blank"
attribute.
In general, avoid opening links in a new window. When links do open in a new window, warn users. Either:
- Add the visible link text “
(Opens in new window)
”. - Reveal a visually-hidden warning on focus and hover (see example).
Good example: Warn users link opens in a new window by revealing a visually-hidden message on focus and hover
HTML
Code begins
<p>
This is an example of an
<a class="info" href="[...]" target="_blank">
<strong>External link</strong>
<span>Opens a new window</span>
</a>
</p>
Code begins
Until the link receives focus, the inner span is visually hidden using the CSS "clip" method. On hover or focus, the warning “Opens in new window
” (or “Opens in new tab
”) is made visible. See WCAG Technique G201 for the complete HTML and CSS.
Consider styling the warning to appear like the title
attribute tooltip.