Tailwind Accessibility

Accessibility means building pages that everyone can use, including people who navigate with a keyboard, use a screen reader, see low contrast poorly, or prefer less motion. Tailwind does not make a page accessible on its own, though its variants and helpers make good habits quick to apply.

Start With Semantic HTML

Correct tags carry meaning that assistive tools understand. Use button for actions, a for links, nav for menus, and real headings in order. A div styled to look like a button lacks keyboard support and a role. Tailwind classes control only the appearance, so choose the tag first and style it second.

Good                              Weak
<button class="rounded bg-sky-600 px-4 py-2">   <div class="rounded bg-sky-600 px-4 py-2">
 reachable by Tab, works with Enter   unreachable by keyboard

Visible Focus

Keyboard users move through the page with the Tab key. A visible outline shows where they are. Removing the outline without a replacement leaves them lost. Use focus-visible: to show a ring only for keyboard focus, which keeps mouse clicks clean.

<a href="#" class="rounded focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-600">
  Read more
</a>

<button class="focus:outline-hidden focus-visible:ring-2 focus-visible:ring-sky-500">Save</button>

Version 4 renamed outline-none to outline-hidden. The hidden version keeps a transparent outline that remains visible in high contrast modes.

Color Contrast

Text needs enough contrast against its background. The WCAG guidelines ask for a ratio of at least 4.5 to 1 for normal text and 3 to 1 for large text. Light gray on white fails the test for many readers.

Combination                     Result
─────────────────────────────────────────
text-gray-900 on bg-white       strong contrast
text-gray-600 on bg-white       passes for body text
text-gray-400 on bg-white       too light for body text
text-white on bg-sky-300        too light
text-white on bg-sky-700        passes

Check real pairs with a contrast checker or the color picker in browser developer tools. Do not use color as the only signal. An error needs an icon or a message besides a red border.

Screen Reader Helpers

The sr-only class hides text from the screen while keeping it in the reading order. Icon buttons need such text, because an icon alone says nothing aloud.

<button>
  <svg aria-hidden="true" class="h-5 w-5">...</svg>
  <span class="sr-only">Close dialog</span>
</button>

Skip Link

A skip link lets keyboard users jump past a long menu. It hides until it receives focus.

<a href="#main" class="sr-only focus:not-sr-only focus:absolute focus:left-2 focus:top-2 focus:rounded focus:bg-white focus:p-2">
  Skip to main content
</a>

Respecting Motion Preferences

Some visitors feel dizzy from moving elements, and their device tells the browser to reduce motion. Two variants respond to that setting.

motion-safe:animate-bounce      plays only if motion is welcome
motion-reduce:transition-none   stops transitions when reduced

State Variants for ARIA Attributes

ARIA attributes describe the state of custom controls. Tailwind variants style those states directly, so appearance and meaning stay in sync.

aria-expanded:rotate-180      arrow turns when a menu is open
aria-checked:bg-sky-600       switch color follows its state
aria-disabled:opacity-50      dims a disabled control
data-[state=open]:block       reads a data attribute

Touch Targets and Spacing

Fingers are bigger than mouse pointers. Give buttons and links enough area to tap. A height of about 44 pixels, equal to h-11, works well on phones. Spacing between targets prevents accidental taps.

Forms

Every input needs a visible label linked with for and id. Placeholder text disappears while typing, so it cannot replace a label. Show error messages as text beside the field and connect them with aria-describedby.

Testing Checklist

  • Press Tab through the whole page and confirm a clear focus mark on every control.
  • Zoom the browser to 200 percent and check that nothing breaks.
  • Turn on a screen reader briefly and listen to a form and a menu.
  • Run an automated checker such as the accessibility audit in browser developer tools.

Automated tools catch only part of the problems, so combine them with hands-on testing. Small habits add up to pages that welcome every visitor.