Join free

Tech and Coding Club

How to build web applications that work for everyone

Practical techniques for implementing accessibility standards ensure your code is usable by people with different physical and cognitive needs.

, 4 min read

Developers writing code at their monitors
Photo: Compagnons

A website that looks perfect on a high-resolution monitor can be completely unusable for someone relying on a screen reader or a keyboard to navigate. When developers treat accessibility as a final checklist or a separate layer of design, they often miss the fundamental ways that assistive technology interacts with the Document Object Model. Building for accessibility is not about adding special features for a small group of users, but about writing clean, semantic HTML that provides a predictable structure for every device.

Semantic HTML provides the foundation

The most effective way to improve accessibility is to use the correct HTML elements for their intended purpose. Browsers and assistive technologies rely on the underlying structure of a page to communicate what is happening to the user. If a button is built using a <div> tag with a click listener, a screen reader will not announce it as an interactive element. A user navigating via keyboard will not be able to focus on it, and a person using a screen reader might not even know it is clickable.

Using a <button> element automatically provides keyboard support and the correct role. Similarly, using <nav>, <main>, <header>, and <footer> helps assistive technology users jump between different sections of a page without having to listen to every single line of content. When the structure is semantic, much of the work of accessibility is done by default.

Managing focus and keyboard navigation

Many users navigate the web without a mouse, relying instead on the Tab key to move through links, buttons, and form fields. A common mistake is to remove the visual focus indicator, often by setting outline: none in CSS, because it interferes with a specific design aesthetic. This makes it impossible for keyboard users to know which element they are currently interacting with.

Focus management becomes more complex when building single-page applications or using modal windows. When a user opens a modal, the keyboard focus should move inside that modal immediately. If the focus remains on the button that opened the modal, the user might continue interacting with the background content while the modal is visible. When the modal is closed, the focus must return to the original element that triggered it. Without this logic, the user can become lost in the page structure.

Using ARIA when HTML is not enough

The Accessible Rich Internet Applications (ARIA) suite provides attributes that can add extra meaning to elements when standard HTML falls short. For example, if a menu expands and collapses, the aria-expanded attribute can inform a screen reader user whether the content is currently visible.

However, the first rule of ARIA is to avoid using it if a native HTML element can do the job. Overusing ARIA can create a confusing experience because it can override the natural behaviour of the browser. Only use ARIA when you are building complex, custom components that do not have a built-in semantic equivalent. For instance, if you are building a custom slider, you might use role="slider" and aria-valuemin or aria-valuemax to describe its function, but you should always prefer a standard <input type="range"> if possible.

Testing with more than just automated tools

Automated testing tools are excellent for catching low-hanging fruit, such as missing alt text on images or insufficient colour contrast. These tools can quickly scan a codebase and flag errors that are easy to fix. However, they cannot tell you if the experience is actually logical or easy to follow. An automated tool might confirm that an image has an alt attribute, but it cannot tell if the description is helpful or if it is just "image123.jpg".

To truly understand the accessibility of a project, you must test it manually. This involves navigating your own application using only the Tab and Enter keys. It also involves turning on a screen reader to hear how the content is announced. If you find that you are getting stuck in a loop or that the reading order feels disjointed, your users will face the same problems. Testing on different devices and with different zoom levels is also essential, as many users increase their text size to make content more readable.

Things to try this week

  • Audit one of your existing projects using a browser extension to find missing labels or poor colour contrast.
  • Unplug your mouse and try to complete a common task on your favourite website using only the keyboard.
  • Replace a non-semantic element, such as a <div> used as a button, with a proper <button> tag and observe the difference in behaviour.
  • Check your CSS to ensure you have not accidentally disabled the focus outline for keyboard users.