Drop In
Accessibility 10 min read

Building Accessible Web Components

A practical guide to creating inclusive components with semantic HTML, ARIA, keyboard navigation, and automated testing.

Maya Rodriguez Feb 18, 2026

Accessibility is not an afterthought. It is a fundamental aspect of building for the web. When we create components that work for everyone, we build a better internet. Yet many developers still treat accessibility as a checkbox to tick before launch rather than a core design principle.

In this guide, we will walk through the process of building web components that are accessible by default. We will cover semantic HTML, ARIA attributes, keyboard navigation, and testing strategies that ensure your components work for all users, regardless of how they interact with the web.

Why Accessibility Matters

Over one billion people worldwide live with some form of disability. That includes visual, auditory, motor, and cognitive impairments that affect how people use the web. When we build inaccessible components, we are not just failing a compliance checklist. We are actively excluding real people from using our products.

Accessibility is not a feature. It is a social responsibility. And it is also the law in many jurisdictions.

Beyond the ethical imperative, accessible components tend to be better components. They have cleaner markup, more predictable behavior, and work across a wider range of devices and input methods. Building with accessibility in mind often reveals design flaws that would otherwise go unnoticed.

Core Principles

Before diving into code, it helps to understand the four principles of web accessibility, often abbreviated as POUR:

  1. Perceivable — Information must be presentable in ways all users can perceive. This means providing text alternatives for images, captions for video, and sufficient color contrast.
  2. Operable — Interface components must be operable by all users. Every interactive element should be reachable and usable via keyboard, and users should have enough time to read and interact with content.
  3. Understandable — Information and operation of the interface must be understandable. Use clear language, predictable navigation, and helpful error messages.
  4. Robust — Content must be robust enough to be interpreted by a wide variety of user agents, including assistive technologies. Use semantic HTML and valid markup.

Building Your First Accessible Component

Let us build a disclosure widget, a common pattern where clicking a trigger reveals or hides content. Many developers reach for a div with a click handler, but the correct approach starts with semantic HTML.

Start with Semantic HTML

The <details> and <summary> elements give us disclosure behavior for free. No JavaScript required. The browser handles the toggle state, keyboard interaction, and communicates the expanded or collapsed state to assistive technologies automatically.

<details>
  <summary>What is web accessibility?</summary>
  <p>
    Web accessibility means that websites, tools,
    and technologies are designed and developed so
    that people with disabilities can use them.
  </p>
</details>

This simple pattern gives you a fully accessible disclosure widget with zero JavaScript. The browser provides keyboard support, screen reader announcements, and proper focus management out of the box.

Tip: Always start with native HTML elements before reaching for ARIA. The first rule of ARIA is "do not use ARIA if you can use a native HTML element." Native elements come with built-in accessibility that is difficult to replicate manually.

When You Need ARIA

Sometimes native HTML does not provide the exact pattern you need. In those cases, ARIA attributes bridge the gap. For example, if you are building a custom tab interface, you would use role="tablist", role="tab", and role="tabpanel" to communicate the structure to assistive technologies.

The key ARIA attributes you will use most often are aria-label for providing accessible names, aria-expanded for toggle states, aria-hidden for decorative elements, and aria-live for dynamic content updates.

Keyboard Navigation

Every interactive element in your component must be reachable and operable via keyboard. This is non-negotiable. Many users rely on keyboards, switch devices, or other alternative input methods to navigate the web.

If you can not use it with a keyboard, it is not accessible. Full stop. Keyboard accessibility is the foundation upon which all other accessibility features are built.

The essential keyboard interactions to support are Tab and Shift+Tab for moving between interactive elements, Enter and Space for activating buttons and links, Escape for closing modals and popups, and Arrow keys for navigating within composite widgets like menus and tab lists.

Focus Management

Focus management is critical for components that change the DOM. When a modal opens, focus should move into it. When it closes, focus should return to the trigger element. When content is dynamically added or removed, the focus position should remain logical and predictable.

// Move focus into a modal when it opens
function openModal(dialog) {
  dialog.showModal();
  const firstFocusable = dialog.querySelector(
    'button, [href], input, select, textarea'
  );
  firstFocusable?.focus();
}

Testing for Accessibility

Automated testing catches roughly 30 to 50 percent of accessibility issues. The rest require manual testing. A solid testing strategy combines both approaches.

Automated Testing

Tools like axe-core and Lighthouse can catch common issues such as missing alt text, low contrast ratios, and missing form labels. Integrate these into your CI pipeline so regressions are caught early.

Manual Testing Checklist

For every component you build, verify the following:

  • Navigate the entire component using only the keyboard
  • Test with a screen reader (VoiceOver on macOS, NVDA on Windows)
  • Verify the component works at 200% browser zoom
  • Check that focus indicators are visible and logical
  • Ensure color is not the only means of conveying information
  • Test with reduced motion preferences enabled

Warning: Do not rely solely on automated tools. They cannot detect issues like illogical tab order, missing context for screen readers, or confusing interaction patterns. Manual testing with real assistive technologies is essential.

Conclusion

Building accessible web components is not about adding complexity. It is about starting with the right foundation. Use semantic HTML first, layer on ARIA only when needed, ensure keyboard operability, and test with real assistive technologies.

The web was designed to be universal. Every component we build should honor that principle. When we prioritize accessibility, we create experiences that work for everyone, and that is always worth the effort.


Maya Rodriguez

Maya is a front-end engineer and accessibility advocate with over a decade of experience building inclusive web applications. She writes about HTML, CSS, and the intersection of design and accessibility.

Related Articles