Compliance
Screen Reader Only Code versus ARIA Labels
In an era where the internet is an integral part of daily life, it is essential to recognise that it should be inclusive for everyone, regardless of ability.
Web accessibility is the principle that guides the design and development of websites and applications to ensure they can be used effectively by people with disabilities. Two techniques contribute significantly: screen reader only code, and ARIA labels.
sr-only code: hiding content for screen readers
Screen readers are one of the most widely used technologies among people with disabilities. They convert the information and content within digital environments to audio, and rely heavily on the source code of a website to function correctly.
When the reading order of a website follows a logical flow, similar to how the eye would read it, using that website becomes an equitable experience. However, there are times when a developer or designer wants to make certain information available only to screen reader users. This is where sr-only code comes in.
sr-only code is a technique that uses CSS to visually hide content while ensuring it remains accessible to screen readers. It is commonly used to provide additional context that may be redundant for sighted users, such as instructions on how to navigate a carousel, or extra information about an infographic or data table.
One important caveat: websites should be designed for the benefit of all users. Information that developers believe is useful only to screen reader users may in fact be needed by everyone.
ARIA labels: adding roles and properties
The Accessible Rich Internet Applications (ARIA) specification provides roles, properties and states that can be added to HTML elements to improve accessibility. Like sr-only code, ARIA can convey additional information to assistive technology without changing the visual appearance of a page.
ARIA attributes such as label and role can add meaning to div elements and make them interactive. ARIA live can notify users about changes in a live region of a page, or enable form hints and error messages. Attributes like aria-hidden can completely hide purely decorative content from screen readers.
But ARIA must supplement HTML, not replace it. Developers should avoid using ARIA when it is unnecessary and, wherever possible, stick with native HTML elements that already have built-in accessibility. Used incorrectly, ARIA labels override existing content and result in a poor user experience.
When to use each
The two can be used in similar ways. Take a link labelled “learn more”:
- With sr-only code, a developer may add more information so screen reader users hear the link as “learn more about us”.
- With an ARIA label, the visible text is overridden completely, so screen reader users hear “about us”.
Choose based on the accessibility requirement. Completely changing a link label with ARIA can cause problems for voice control users, so sr-only code is preferable there. Skip to main content links, which appear to sighted users on keyboard focus, are usually implemented with sr-only code rather than ARIA.
Elements implemented with icons or graphics, such as an X button to close a pop-up or a plus button to open a submenu, are better served by ARIA labels.
Best practice
sr-only code and ARIA labels help improve accessibility, but they will not get you the whole way. Relying too heavily on either can distract from the importance of universal design.
Semantic HTML is preferred above all. Proper heading structure, readable content, keyboard accessibility, descriptive labels and meaningful text alternatives will keep you ahead of the curve. sr-only code and ARIA should be used alongside these practices, not instead of them.
Vially can help
If you are ready to make your organisation more accessible, are unsure whether you comply with the laws that apply to you, or simply have questions you would like answered, we are here to help.