Ankit KanojiyaBeginner

Evergreen guide by Ankit Kanojiya · Beginner · Frontend

Web Accessibility Fundamentals Every Frontend Developer Should Know

The core accessibility practices that cover most real-world needs: semantic HTML, keyboard support, labels, focus, and contrast. Practical examples with the reasoning behind each rule.

Accessibility means building interfaces that people can use regardless of how they interact with a device, whether through a screen reader, a keyboard alone, voice control, or a magnifier. Most accessibility wins come from a small set of fundamentals rather than exotic techniques. Getting these right benefits everyone, not only users with disabilities.

Start with semantic HTML

The single most effective practice is using the correct element for the job. Native elements carry built-in roles, keyboard behavior, and states that assistive technology understands for free.

  • A button element is focusable, is announced as a button, and responds to Enter and Space automatically.
  • A styled div with a click handler has none of that.
<!-- Accessible and keyboard-operable by default -->
<button type="button">Save</button>

<!-- Not focusable, not announced, no keyboard support -->
<div class="btn" onclick="save()">Save</div>

The same reasoning applies to headings, lists, nav, main, and form controls. Reaching for ARIA to recreate what a native element already provides is almost always the wrong move. The first rule of ARIA is to not use ARIA when a native element will do.

Keyboard access

Many people navigate entirely by keyboard. Every interactive control must be reachable with Tab, operable with Enter or Space, and dismissible with Escape where relevant. Two things to verify:

  • The tab order follows the visual and logical order. This usually happens naturally when the DOM order matches the layout.
  • Focus is never trapped unexpectedly, except intentionally inside a modal dialog, which should return focus to the trigger on close.

Avoid positive tabindex values, which override natural order and cause confusing jumps. Use tabindex="0" only to make a custom interactive element focusable, and tabindex="-1" to move focus programmatically.

Visible focus indicators

Keyboard users need to see where focus currently sits. Removing the focus outline without providing a replacement makes a page unusable for them.

/* Do not do this with no alternative */
:focus { outline: none; }

/* Provide a clear, visible indicator instead */
:focus-visible {
  outline: 3px solid #1a73e8;
  outline-offset: 2px;
}

The :focus-visible selector shows the indicator for keyboard interaction while avoiding an outline on mouse clicks, which addresses the usual reason people remove outlines.

Labels and names

Every form control needs an accessible name so a screen reader can announce its purpose. The most robust way is a real label associated with the control.

<label for="email">Email address</label>
<input id="email" type="email" name="email" />

When a visible label is not possible, provide a name another way, but prefer a visible one. Placeholder text is not a label; it disappears on input and is often too low in contrast. For icon-only buttons, give an explicit name:

<button type="button" aria-label="Close dialog">X</button>

Images and alternative text

Images that convey information need descriptive alternative text. Images that are purely decorative should have an empty alt attribute so screen readers skip them.

  • Informative: describe the content or function, not the file.
  • Decorative: use alt="" so it is ignored rather than read as a filename.
<img src="/chart.png" alt="Sales rose 20 percent from March to April" />
<img src="/divider.png" alt="" />

Color and contrast

Text must have enough contrast against its background to be readable. The common target is a contrast ratio of at least 4.5 to 1 for normal text and 3 to 1 for large text. Also avoid using color as the only way to convey meaning: pair it with text, an icon, or a pattern so that users who cannot distinguish certain colors still get the information.

Respect user preferences

Some users are sensitive to motion. Honor their system setting to reduce animation:

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

Test with real tools

Automated checkers catch only part of the picture, roughly a third of issues, but they are a fast first pass.

  • Run an automated audit such as the accessibility checks in browser dev tools.
  • Navigate the whole page using only the keyboard and confirm every action is possible.
  • Try a screen reader to hear how content and controls are announced.

A starting checklist

  • Use native semantic elements before custom ones.
  • Ensure everything works with the keyboard alone.
  • Keep a visible focus indicator.
  • Give every control and image an accessible name or empty alt.
  • Meet contrast ratios and never rely on color alone.
  • Respect reduced-motion preferences.

Accessibility is not a final polish step. Building on these fundamentals from the start is far cheaper than retrofitting, and it produces a more robust interface for every user.