How to improve Web Accessibility
Developing a website that everyone can use, no matter their abilities or disabilities is important; however, many sites and tools are developed with accessibility barriers that make them difficult or impossible for some people to use. Web accessibility helps screen readers and other tools understand content better.
Semantic HTML
A semantic tag describes its meaning to both the browser and the developer, and also improves SEO, making your site more findable.
Semantic markup has other benefits beyond accessibility: - Easier to develop with; they have built-in keyboard accessibility — users can navigate between buttons using the Tab key and activate their selection using Space, Return or Enter. - Semantic elements like headings and links are favored by search engines for SEO, making your content more discoverable compared to non-semantic elements like <div>
.
ARIA roles
By default, many semantic elements in HTML have a role; for example, <main>
has the "main" role.
ARIA roles can be used to describe elements that don't natively exist in HTML or exist but don't yet have full browser support.
For instance, aria-required="true"
can be used to indicate required fields.
Heading hierarchy
The hierarchical structure shows users how topics fit together, it shows readers where to find information and how important it is
Using clear language
Use meaningful text that provides users with information. Instead of providing generic text write descriptive text
Using tabindex
When users use the tab key to browse a webpage, only interactive elements (like links, buttons, form controls) get focused. With the tabindex
other elements can be made focusable.
When set to 0, the element becomes focusable by keyboard and script. When set to -1, the element becomes focusable by script, but it does not become part of the keyboard focus order.
Use element.focus()
to set focus
Additionally, touch targets must be large enough for the user to interact with, with the recommended size being 48x48 px.
State and Property Attributes
ARIA attributes convey the state and properties of elements. For example, aria-hidden
can be used to indicate whether the element is exposed to an accessibility API.
Accessible Names and Descriptions
ARIA attributes can be used to make widgets more understandable for screen reader users.
The aria-describedby
attribute lists the ids of the elements that describe the object. It is used to establish a relationship between widgets or groups and the text that describes them.
aria-describedby
can be associated with error messages within form fields.
The aria-label
provides the interactive element with its accessible name.
Alternative Text for Images
Alternative text provides descriptive content or purpose to screen reader users and search engines for SEO.
Captions and Transcripts
Captions and transcripts are necessary for web accessibility, especially for people with hearing impairments. They ensure that audio and video content is accessible to a wider audience.
Captions provide a text representation of a video's content.
In this example:
<video>
: Embeds the video element.<source>
: Specifies the video source file.<track>
: Defines a caption track.kind="captions":
Indicates that this track contains captions.label="English"
: Specifies the label for the captions.src="captions-en.vtt"
: Points to the WebVTT (Web Video Text Tracks) file containing captions.srclang="en"
: Specifies the language of the captions.default
: Indicates that these captions should be displayed by default.
Transcripts provide a written version of the audio's content. Here's an example of an audio transcript
Understanding web accessibility is important. As a frontend developer, you help make the internet inclusive for everyone. Use practices like semantic HTML, alt text for images, and keyboard navigation. Every accessible website you create matters. Keep going!
Key Takeaways
-
Semantic HTML Best Practices
- Use appropriate HTML elements for their intended purpose
- Maintain proper heading hierarchy
- Include meaningful alt text for images
- Use semantic elements for better SEO and accessibility
-
ARIA Implementation
- Use ARIA roles and attributes when native HTML isn't sufficient
- Provide clear accessible names and descriptions
- Maintain proper state management
- Don't use ARIA when native HTML elements suffice
-
Content Accessibility
- Write clear, descriptive text
- Provide captions and transcripts for media
- Ensure sufficient color contrast
- Make interactive elements keyboard accessible
References
Let's work together
I build exceptional and accessible digital experiences for the web
WRITE AN EMAILor reach out directly at hello@mohammadshehadeh.com