Estimate project
← All posts

Web Accessibility Part 2: Hands-On Basics Every Frontend Developer Should Know

A guide full of practical advice for building interfaces that are inclusive, meet the requirements, and just work better for all users.

15 min read
AccessibilityWeb AccessibilityDigital AccessibilityFrontend

The first part of this series explained why accessibility is important and how the European Accessibility Act is changing digital standards throughout the EU. This time, we move on to practice.

Part two focuses on concrete accessibility best practices for front-end developers. It’s a guide full of practical advice for building interfaces that are inclusive, meet the requirements, and just work better for all users.

Introduction

Making a website or web application EAA-ready isn’t only a matter of audits and paperwork – above all, it comes down to the everyday choices of those who write the code. Below you’ll find practical advice that every frontend developer should be familiar with and use when working on accessibility.

1. Semantic HTML

An accessible front-end starts with choosing the right HTML tags. Elements like <header>, <nav>, <main>, <section>, <aside>, <button>, or <label> don’t just keep the code organized – they also let assistive technologies (e.g., screen readers) correctly understand how the page is structured and what each part does.

<!-- ❌ Incorrect -->
<div onclick="submitForm()">Save</div>

<!-- ✅ Correct -->
<button type="submit">Save</button>

Site navigation is another good example:

<!-- ❌ Difficult to scan an HTML document, poor accessibility-->
<div class="nav">
  <div class="nav-links">
    <p><a href="#">Home Page</a></p>
    <p><a href="#">Articles</a></p>
    <p><a href="#">About</a></p>
  </div>
</div>

<!-- ✅ With semantic HTML elements -->
<nav>
  <ul>
    <li><a href="#">Home Page</a></li>
    <li><a href="#">Articles</a></li>
    <li><a href="#">About</a></li>
  </ul>
</nav>

2. Headings

Headings (<h1> to <h6>) are central to an HTML document’s structure – not only for SEO, but first and foremost for accessibility. They let screen reader users get their bearings in the page layout quickly and move around its content. Using headings incorrectly breaks the document’s semantics and hampers navigation.

Think of a book with no table of contents – hard to search, messy, and impossible to read. Websites work the same way: assistive technologies rely on headings to build an outline of the page, so users can “scan” the content quickly.

Core rules:

  • Every page should have just one h1 heading, standing for the main subject or title of the subpage,
  • Headings should follow a logical, hierarchical order, e.g., h1 → h2 → h3, with no unjustified skipping of levels. This makes the content structure easier to understand,
  • Don’t pick a lower-level heading (h3, h4, etc.) simply because it looks nicer. If it is semantically the main title, use h1 and adjust its look with CSS,
  • Don’t use non-semantic elements (e.g., p, span) in place of headings – even when they look alike. Assistive technologies don’t treat them as structural landmarks.
<!--  ❌ Incorrect structure – hierarchy omitted -->
<h1>Company blog</h1>
  <h3>Product news</h3>
  <h4>Version 2.0 – what's new?</h4>
  <h2>Guides</h2>

<!-- ✅ Correct structure -->
<h1>Company blog</h1>
  <h2>Product news</h2>
    <h3>ersion 2.0 – what's new?</h3>
  <h2>Guides</h2>
    <h3>How to implement accessibility step by step?</h3>

A proper heading structure isn’t merely about looks and tidiness – it makes a genuine difference for thousands of people who browse the Internet in a different way than most. It’s also one of the cornerstones of meeting WCAG standards and the European Accessibility Act.

3. Forms

Every form should have clearly described fields. A <label> has to be tied to its form field through for/id. Extra messages (e.g., error messages) should be connected to the field with aria-describedby (which lets screen readers recognize the message as belonging to that field) and placed inside a container with aria-live (which tells assistive technologies that the page content has changed in a meaningful way).

A) Connecting form fields with labels

Tying a label properly to an input field makes forms easier to use – both for people with limited mobility (they get a bigger click target) and for screen reader users (the label is announced automatically when the field receives focus).

You can link them in two main ways:

<!-- ✅ Implicit association – the form field is located as a child of the label -->
<label>
  Name:
  <input type="text" name="name" />
</label>

<!-- ✅ Explicit association – the label and input are associated via for and id -->
<label for="user-name">Name:</label>
<input type="text" id="user-name" name="name" />

Either approach is fine. What matters most is that the relationship is unambiguous and assistive technologies can interpret it.

B) Field-specific error messages

When a form has errors, each one must be tied directly to the field it concerns – otherwise people with disabilities may not grasp what went wrong.

A frequent mistake is showing an error message beside a field with no logical link between them. Then the screen reader passes nothing on to the user.

<!-- ✅ Properly linked form label and error message using aria-describedby -->
<label for="username">Username:</label>
<input
  type="text"
  id="username"
  name="username"
  aria-describedby="username-error"
/>
<p id="username-error" aria-live="polite">
  Username is required.
</p>

In a real implementation, the message element (<p> or <div>) should be present in the DOM tree from the start but stay empty at first, so that once content appears, the message is treated as an update and announced automatically.

C) Autocomplete support

Turning autocomplete off can be annoying, particularly for people with motor impairments who have to type the same information over and over. Even though the autocomplete attribute is on by default, it’s worth stating it explicitly where needed so the browser knows which kind of data the field expects.

<!-- ✅ Proper use of autocomplete attribute for improved form usability -->
<label for="first-name">First Name:</label>
<input
  type="text"
  id="first-name"
  name="first-name"
  autocomplete="given-name"
/>

D) Choosing the right field types

HTML provides more than 20 types of form fields (type=“…”), and it pays to choose them deliberately. This gives users – mobile users in particular – tailored keyboards and suggestions.

Examples:

  • type=“email” – turns on validation and a mobile keyboard that includes @,
  • type=“number” – brings up a numeric keyboard,
  • type=“tel” – makes typing phone numbers easier.

E) A clear focus indicator

Every active form field should show a visible focus indicator (:focus). It tells users which field they are in, which makes navigating and filling in data easier. Don’t strip out the default outline unless you supply a clear replacement.

4. Modals

Modals (dialogs) are widespread in complex web applications, yet getting them right in terms of accessibility is tricky. The main concerns are managing focus, keyboard navigation, and preventing access to the content underneath the modal.

A) The built-in <dialog>

The simplest and most recommended way to build an accessible modal is the semantic <dialog> element, which is now supported by browsers. It handles many accessibility mechanisms out of the box, such as keyboard navigation and closing the window with the Esc key.

B) A custom modal

If you build your own modal component (e.g., in React, without <dialog>), accessibility is your responsibility. The most important points:

Managing focus

When a modal window opens, keyboard and screen reader users may stay, without realizing it, on the button that opened the modal, which makes navigating awkward. It can also cause the same window to be opened several times. To avoid that, you should:

  • Move focus to the first interactive element inside the modal window as soon as it opens.
  • Apply a “focus trap” – a mechanism that keeps focus within the modal and stops users from reaching elements on the page behind it.
  • Once the modal closes, return focus to the element that opened it.

Hiding inactive content

Even though the modal visually covers the rest of the page, screen reader users can still “browse” what’s underneath. To stop this, apply the inert attribute to the page’s main container (e.g., <main>), which makes the background content unreachable and non-interactive.

Closing a modal with the Escape key

Letting users close a modal with the Esc key is good UX practice and a real help for people with motor impairments. Users expect it as the default way to leave a dialog box.

5. Making sure text contrast is sufficient

WCAG 2.1 and level AA call for a minimum contrast ratio of 4.5:1 for regular text and 3:1 for large text. Insufficient contrast is one of the most frequent obstacles for people with poor vision or color blindness. Contrast analysis tools are worth using (e.g., WebAIM Contrast Checker, Coolors Contrast Checker).

In the image above, the left side shows the form as a user with typical vision sees it. On the right is the same form as perceived by people with impaired color perception (e.g., color blindness). Without clear contrast, the elements become hard or even impossible to read.

Color should never be the sole carrier of meaning (e.g., a red border or text colored to signal an error). Back it up with extra cues: an icon, a text label, bold type, a symbol, or an asterisk. Below is an improved form design with an added icon and a bigger font size.

6. Keyboard operation

A well-built website should be usable by people who navigate with the keyboard alone (e.g., Tab, Enter, Esc). Test regularly how it works without a mouse and make sure the focus order is logical. A sound HTML structure and careful use of the tabindex attribute are essential here.

Usually, there’s no need to define the tab order between elements by hand. Native, semantic tags (<button>, <a href=“”>, <input>) are enough, as they support Tab navigation automatically. Overriding the tab order manually (e.g., tabindex=“1”, tabindex=“2”) is hard to maintain, frequently out of sync with the DOM, and regarded as an antipattern.

When a custom component (e.g., a drop-down menu) needs keyboard support, use:

  • tabindex=“0” – puts the element into the natural focus order (e.g., a custom button),
  • tabindex=“-1” – lets you move focus to it programmatically, keeping the element out of sequential keyboard navigation (e.g., once a modal is opened),
  • Never use tabindex > 1 – it can break the intuitive navigation order.

Use the tabindex attribute on interactive elements only. Putting it on static content (e.g., div, p) creates needless confusion and can make the page harder to use for people with motor or visual impairments.

<!-- ✅ Properly operable custom button -->

<div
  role="button"
  tabindex="0"
  aria-pressed="false"
  onclick="toggleState()"
  onkeydown="
    if(event.key==='Enter'||event.key===' ') {
      toggleState();
    }"
>
  More...
</div>
<!-- ✅ Element with tabindex="-1" for temporary focus -->

<div id="modal" tabindex="-1" role="dialog" aria-modal="true">
  <h2>Modal Title</h2>
  <p>Description...</p>
</div>

<script>
  document.getElementById('modal').focus();
</script>

A well-planned focus order makes the interface more predictable and easier to use, both for those who prefer the keyboard and for those who have no alternative.

7. Visible focus

Being able to see the outline of the active element (:focus) is essential for people who move around the site without a mouse. Don’t remove it (outline: none) unless you offer a visual replacement. Many CSS frameworks hide it by default – keep this under deliberate control.

/*✅ Visible and accessible focus indicator for keyboard navigation*/
button:focus {
  outline: 2px solid #005fcc;
  outline-offset: 2px;
}

8. Sensible sizes for interactive elements

Buttons, links, and other interactive components need to be large enough. The recommended minimum is 44 × 44 px, particularly for people with motor difficulties and for mobile users.

9. Alternative text for images

Every image should have an alt attribute describing what it is for. Assistive technologies such as screen readers use it to help visually impaired users understand the image. For a purely decorative image, you can set alt=“” so the screen reader skips it. On top of that, the alt attribute helps SEO by making it easier for search engines to understand the content of the page’s content.

<!-- ✅ Descriptive and meaningful alt text for screen reader users -->
<img src="avatar.jpg" alt="Profile picture of user John Doe" />

10. Accessible SVG icons

SVG icons are one of the most neglected parts of website accessibility. The way an icon is implemented matters a lot to screen reader users. The crucial thing is telling decorative icons apart from semantic ones.

A) Decorative icons

When an icon adds no extra meaning (e.g., an arrow beside the “Submit” button), a screen reader shouldn’t announce it. In that case, hide it with the aria-hidden=“true” attribute.

Also, for compatibility with older browsers (e.g., Internet Explorer), it’s a good idea to add focusable=“false” so the icon can’t receive focus by accident.

<!-- ✅ Decorative SVG icons hidden from screen readers using aria-hidden and focusable -->
<button>
  <svg
    class="paper-airplane"
    aria-hidden="true"
    focusable="false"
  >
     ...
  </svg>
  Submit
</button>

<a href="#">
  <svg
    class="home"
    aria-hidden="true"
    focusable="false"
  >
     ...
  </svg>
  Home Page
</a>

B) Semantic icons

Icons that stand in for text or carry a particular functional meaning (e.g., an arrow in pagination navigation), have to be identifiable and understandable for a screen reader. Here, it’s worth using the <title> and <desc> elements, which give a brief description and wider context of what the icon does.

  • title – a short alternative text acting as a label,
  • desc – an extended description that gives the user additional information.

The aria-labelledby and aria-describedby attributes connect these descriptions with the icon.

<!-- ✅ Fully accessible SVG icon with title and description -->
<svg 
  class="right-arrow"
  role="img"
  aria-labelledby="arrow-title"
>
  <title id="arrow-title">Pagination arrow</title>
  <!-- SVG content -->
</svg>

<svg
  class="right-arrow"
  role="img"
  aria-labelledby="arrow-title"
  aria-describedby="arrow-desc"
>
  <title id="arrow-title">Pagination arrow</title>
  <desc id="arrow-desc">
    Arrow to go to the next page
  </desc>
  <!-- SVG content -->
</svg>

With this labeling, the screen reader tells the user not only that an icon is there but also what it does – which is vital for understanding the interface when it comes to icon buttons.

11. Motion and animations

Animations can make a website more usable by guiding users around it, e.g., during transitions between states. For some users, however (e.g., people sensitive to light and motion), dynamic elements like flashing graphics, auto-rotating carousels, or scroll-triggered animations can be irritating or even harmful. The prefers-reduced-motion media query detects whether the user has turned animations off on their device and lets you apply CSS styles that respect that preference:

.wobble-animation {
  animation: wobble 0.2s ease-in 3 alternate;
  background-color: purple;
}

/* ✅ if the user prefers reduced motion apply these styles */
@media (prefers-reduced-motion: reduce) {
  .wobble-animation {
    animation: none;
  }
}

/* ✅ or in a slightly leaner way - define the animations only when the user has no motion preferences */
@media (prefers-reduced-motion: no-preference) {
  .wobble-animation {
    animation: wobble 0.2s ease-in 3 alternate;
  }
}

12. Accessible video and audio content

Videos, podcasts, and audio recordings should also be accessible to people who are deaf, hard of hearing, blind, or living with other disabilities. This isn’t just a gesture of empathy – it helps SEO too: search engines can’t “read” videos, but they do index subtitles and transcripts.

A) Subtitles and transcripts

Captions and transcripts are a must. Ideally, professionals should prepare them, but you can also make them on your own. Captions come in two kinds:

  • Closed captions – can be switched on and off, translated, and edited,
  • Open captions – burned into the image, always shown, and not editable.

Auto-generated subtitles (e.g., on YouTube) may be inaccurate and frequently leave out background sounds (“murmurs,” “laughter,” “screams”). Transcripts should include all spoken words and describe important visual information, ideally in several languages if the website comes in multiple language versions.

B) Audio description

For blind users, consider adding audio description – a spoken account of what is shown in the recording. Another option is so-called “built-in audio description,” meaning a deliberately chosen way of speaking: for instance, rather than “as you can see in the chart,” say “revenues increased by 59% compared to 43% last year.”

C) Player

The media player has to support:

  • Showing subtitles,
  • Keyboard operation,
  • Full-screen mode,
  • Alternative audio tracks and transcripts.

D) Safety

Don’t autoplay flashing animations or videos. Content like this can harm people with photosensitive epilepsy or migraines. If you have to publish such material, include a warning and disable autoplay.

13. ARIA attributes

Keep in mind that semantic HTML comes before ARIA attributes. aria-* attributes are useful in complex components (e.g., custom modals, dropdowns), but they shouldn’t be overused as a substitute for proper markup.

Two ARIA attributes deserve particular attention, as they are key in day-to-day component coding, especially for elements that have no visible text or are purely decorative:

A) aria-label – a text description for an element that has no visible label

This attribute lets you give an interactive element a description that a screen reader will announce – even when the button or link contains no text, just an icon. For instance, a button showing a magnifying glass icon can be labelled “Search”:

<!-- ✅ Accessible icon-only button with clear aria-label -->
<button aria-label="Search">
  <SearchIcon />
</button>

Bear in mind, though, that aria-label belongs on interactive elements only (e.g., button, a, input). On static elements (e.g., div, span), screen readers may ignore it, or it may produce unclear and conflicting announcements.

B) aria-hidden – hiding an element from screen readers

This attribute tells assistive technology to skip a given element when reading, even though it stays visible on screen. It’s ideal for decorative elements, icons, or content that carries no semantic value.

<!-- ✅ Decorative logo hidden from assistive technologies using aria-hidden -->
<div>
  Company <CompanyLogo aria-hidden="true" />
</div>

With aria-hidden, the screen reader won’t announce the icon, which cuts down semantic noise and gives visually impaired users a better experience.

An Accessible To-Do List

Lastly, take a look at a simple to-do list app I built as an example of how a few of the accessibility techniques covered above can be put into practice.

Conclusion

Building accessible interfaces isn’t about checking boxes; it’s about empathy, clarity, and good craftsmanship.

Each aria-label, each well-structured heading, and each readable contrast level adds up to a better experience – not just for users with disabilities, but for all of us.

Accessibility isn’t a feature; it’s the hallmark of a well-made product.

Keep iterating, testing, and learning. The more inclusive the web gets, the better it serves everyone.