Links serve as the primary navigation pathways of the web, making clear destinations essential for people using screen readers, keyboards or screen magnifiers.
Ambiguous link text, low contrast or lack of visual focus indicators, create barriers for users with visual, motor or cognitive disabilities.
Clearly designed links with correct programmatic markup ensures that everyone can navigate the site smoothly and intuitively.
How to code links
Links should be coded using the <a> element with a valid href attribute.
Avoid using non-interactive elements like <div> or <span> with click handlers.
Use link semantics to point to a new page, section within the same page or a file.
Here is the recommended native HTML pattern to code links:
<a href=/schedule>View event schedule</a>
Here is the not recommended HTML pattern, with non-semantic <div> element which makes the link unusable for keyboard and screen reader users:
Not keyboard focusable - it uses the generic <div> element which can not receive the keyboard focus via the Tab key, therefore keyboard only users will not be able to navigate with this element.
Role missing – <div> element is announced by screen readers as static text, failing to convey to screen reader users that it acts as a link.
No keyboard activation – the inline ‘onclick’ event handler is triggered only when the mouse is clicked (or when Enter key is pressed, if it has focus), which means there are no standard handlers for key press (Enter/spacebar) that are expected from custom interactive controls.
Disrupts native browser behaviour – using JavaScript code for navigation instead of proper links interferes with standard browser functions, such as copying the link address, opening in a new tab or previewing the destination URL in the browser status bar.
Icon-only and image-only links
Links that include only an icon like social media logotypes, “Back to top of page” icon or image like brand logotype navigating to the website homepage, must also provide an accessible text, so screen reader users and speech recognition software can understand their purpose.
You may use the following techniques to ensure the programmatic accessible name for non-text links:
Aria-label technique (icon-only elements)
Apply aria-label attribute directly to the <a> tag for inline SVG elements or icon fonts.
The aria-label attribute will replace the text content inside <a> tag for screen readers.
Note: Add aria-hidden=”true” and focusable=”false” to nested child SVG element to hide it from assistive technologies and prevent redundant or confusing announcements.
Note: Be aware that if you additionally add aria-label attribute to <a> tag that contains <img> element with alternative text already set, that alternative text will not be presented by screen readers because it will be overridden by the aria-label.
Visually hidden text technique
Add CSS utility class .visually-hidden to website stylesheet.
This class will shrink the text down to invisible 1-pixel wide box, remove margins and borders and exclude it from the visual layout of the page. At the same time it will remain accessible to assistive technologies.
Place a <span> tag containing the links functional destination inside the anchor tag <a>, positioned alongside the icon element, and add the class=”visually-hidden” inside the opening <span> tag.
To prevent screen reader from announcing the icon path details (as the icon has decorative function), add aria-hidden=”true” and focusable=”false” to nested child SVG element.
Note: Do not use display: none or visibility: hidden property as it will hide the text from the screen readers.