---
title: "Accessibility"
description: "Accessibility patterns in defuss-shadcn: ARIA roles, keyboard navigation, focus management, and screen reader support."
slug: "accessibility"
---

import { DocPage, PageHeader, SkillPanel, Example, ExampleLabel, ExampleHint, ExampleCode, SourceFiles, SourceNote, StatesSection, CodeBlock, Demo, DemoCode, ChangelogEntries, ArchBody, StatsClaim, StatsCards, PageOverlay, DocText, DocLink, H2, SkillField, SkillText, SkillRow, SkillGrid, Variant, ApiPill, Dim, CodeWindow, CodeCard, TableCard } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="accessibility" title="Accessibility" introStyle="max-width:38rem;">
  Every component follows WAI-ARIA Authoring Practices. Semantic HTML first, ARIA attributes where native semantics don't exist, full keyboard support throughout.
</PageHeader>

<H2>Semantic HTML first</H2>

<p class="text-sm text-muted-foreground mb-5">Components start from the most semantic native element available. A <code>&lt;button&gt;</code> is already a button - no <code>role="button"</code> needed. A <code>&lt;dialog&gt;</code> already traps focus and handles Escape. ARIA is only added when the native element doesn't express the full semantics of the widget.</p>

<div class="grid grid-cols-auto gap-4 mb-10">
  <CodeWindow lang="markup" title="Avoid: unnecessary ARIA" column code={"<!-- Don't add ARIA roles to native elements -->\n<div role=\"button\" tabindex=\"0\"\n  onclick=\"...\">\n  Click me\n</div>"} />
  <CodeWindow lang="markup" title="Prefer: native elements" column code={"<!-- Native button: focusable, keyboard\n     activatable, announced correctly -->\n<button class=\"btn\">\n  Click me\n</button>"} />
</div>

<div class="sep" />

<H2>ARIA roles</H2>

<p class="text-sm text-muted-foreground mb-5">When no native element expresses the widget semantics, ARIA roles tell assistive technology what the element represents. These follow the <a href="https://www.w3.org/WAI/ARIA/apg/" target="_blank" rel="noopener" class="btn" data-variant="link">WAI-ARIA Authoring Practices Guide (APG)</a>.</p>

<TableCard title="ARIA roles by component" mb="2.5rem"><table class="table" data-variant="simple">
      <thead>
        <tr>
          <th class="whitespace-nowrap">Role</th>
          <th>Component</th>
          <th>Purpose</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>
            <code>menu</code>
          </td>
          <td>Dropdown, Context Menu</td>
          <td>A list of actions or options</td>
        </tr>
        <tr>
          <td>
            <code>menuitem</code>
          </td>
          <td>Dropdown, Context Menu</td>
          <td>A single action in a menu</td>
        </tr>
        <tr>
          <td>
            <code>menuitemcheckbox</code>
          </td>
          <td>Dropdown</td>
          <td>A togglable menu item</td>
        </tr>
        <tr>
          <td>
            <code>menuitemradio</code>
          </td>
          <td>Dropdown</td>
          <td>A mutually exclusive menu option</td>
        </tr>
        <tr>
          <td>
            <code>tablist</code>
          </td>
          <td>Tabs</td>
          <td>Container for tab triggers</td>
        </tr>
        <tr>
          <td>
            <code>tab</code>
          </td>
          <td>Tabs</td>
          <td>A single tab trigger</td>
        </tr>
        <tr>
          <td>
            <code>tabpanel</code>
          </td>
          <td>Tabs</td>
          <td>Content area associated with a tab</td>
        </tr>
        <tr>
          <td>
            <code>listbox</code>
          </td>
          <td>Combobox</td>
          <td>A list of selectable options</td>
        </tr>
        <tr>
          <td>
            <code>option</code>
          </td>
          <td>Combobox</td>
          <td>A single option in a listbox</td>
        </tr>
        <tr>
          <td>
            <code>toolbar</code>
          </td>
          <td>Toolbar</td>
          <td>A container for grouped actions</td>
        </tr>
        <tr>
          <td>
            <code>treeitem</code>
          </td>
          <td>Tree View</td>
          <td>A node in a hierarchical tree</td>
        </tr>
        <tr>
          <td>
            <code>dialog</code>
          </td>
          <td>Dialog, Sheet</td>
          <td>A modal or non-modal overlay (native via <code>&lt;dialog&gt;</code>)</td>
        </tr>
        <tr>
          <td>
            <code>alertdialog</code>
          </td>
          <td>Alert Dialog</td>
          <td>A dialog requiring acknowledgment</td>
        </tr>
        <tr>
          <td>
            <code>alert</code>
          </td>
          <td>Alert</td>
          <td>An important, time-sensitive message</td>
        </tr>
        <tr>
          <td>
            <code>status</code>
          </td>
          <td>Toast</td>
          <td>A polite status notification</td>
        </tr>
      </tbody>
    </table></TableCard>

<div class="sep" />

<H2>State attributes</H2>

<p class="text-sm text-muted-foreground mb-5">ARIA state attributes communicate dynamic state changes to assistive technology. These are managed by JavaScript at runtime.</p>

<TableCard title="ARIA state attributes" mb="2.5rem"><table class="table" data-variant="simple">
      <thead>
        <tr>
          <th class="whitespace-nowrap">Attribute</th>
          <th>Values</th>
          <th>Usage</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>
            <code>aria-expanded</code>
          </td>
          <td><code>true</code> / <code>false</code></td>
          <td>Dropdown triggers, popover triggers, accordion headers - indicates whether the controlled content is visible</td>
        </tr>
        <tr>
          <td>
            <code>aria-selected</code>
          </td>
          <td><code>true</code> / <code>false</code></td>
          <td>Tab triggers, combobox options - indicates the active selection</td>
        </tr>
        <tr>
          <td>
            <code>aria-checked</code>
          </td>
          <td><code>true</code> / <code>false</code> / <code>mixed</code></td>
          <td>Menu item checkboxes, menu item radios, toggle buttons</td>
        </tr>
        <tr>
          <td>
            <code>aria-pressed</code>
          </td>
          <td><code>true</code> / <code>false</code></td>
          <td>Toggle buttons - indicates pressed/active state</td>
        </tr>
        <tr>
          <td>
            <code>aria-disabled</code>
          </td>
          <td>
            <code>true</code>
          </td>
          <td>Non-native disabled elements (menu items, links) where the HTML <code>disabled</code> attribute isn't available</td>
        </tr>
        <tr>
          <td>
            <code>aria-invalid</code>
          </td>
          <td>
            <code>true</code>
          </td>
          <td>Form inputs with validation errors</td>
        </tr>
        <tr>
          <td>
            <code>aria-busy</code>
          </td>
          <td>
            <code>true</code>
          </td>
          <td>Loading states - tells screen readers content is still loading</td>
        </tr>
      </tbody>
    </table></TableCard>

<div class="sep" />

<H2>Relationship attributes</H2>

<p class="text-sm text-muted-foreground mb-5">These attributes create semantic connections between elements, allowing assistive technology to navigate related content.</p>

<TableCard title="relationship attributes" mb="1.5rem"><table class="table" data-variant="simple">
      <thead>
        <tr>
          <th class="whitespace-nowrap">Attribute</th>
          <th>Purpose</th>
          <th>Example</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>
            <code>aria-controls</code>
          </td>
          <td>Links a trigger to the element it controls</td>
          <td>Tab trigger → tab panel</td>
        </tr>
        <tr>
          <td>
            <code>aria-labelledby</code>
          </td>
          <td>Labels an element using another element's text</td>
          <td>Tab panel labeled by its tab trigger</td>
        </tr>
        <tr>
          <td>
            <code>aria-describedby</code>
          </td>
          <td>Provides additional descriptive text</td>
          <td>Input described by its help text</td>
        </tr>
        <tr>
          <td>
            <code>aria-activedescendant</code>
          </td>
          <td>Points to the visually focused item in a composite widget</td>
          <td>Combobox input → highlighted option</td>
        </tr>
        <tr>
          <td>
            <code>aria-haspopup</code>
          </td>
          <td>Indicates a trigger will open a popup</td>
          <td><code>menu</code>, <code>dialog</code>, or <code>listbox</code></td>
        </tr>
        <tr>
          <td>
            <code>aria-owns</code>
          </td>
          <td>Creates parent-child relationship in the accessibility tree</td>
          <td>Combobox input owns the listbox</td>
        </tr>
      </tbody>
    </table></TableCard>

<CodeWindow lang="markup" title="tabs - relationship attributes in action" mb="2.5rem" code={"<div role=\"tablist\" aria-label=\"Settings\">\n  <button role=\"tab\"\n    id=\"tab-1\"\n    aria-selected=\"true\"\n    aria-controls=\"panel-1\"\n    tabindex=\"0\">\n    General\n  </button>\n  <button role=\"tab\"\n    id=\"tab-2\"\n    aria-selected=\"false\"\n    aria-controls=\"panel-2\"\n    tabindex=\"-1\">\n    Advanced\n  </button>\n</div>\n\n<div role=\"tabpanel\"\n  id=\"panel-1\"\n  aria-labelledby=\"tab-1\">\n  General settings content\n</div>\n\n<div role=\"tabpanel\"\n  id=\"panel-2\"\n  aria-labelledby=\"tab-2\"\n  hidden>\n  Advanced settings content\n</div>"} />

<div class="sep" />

<H2>Keyboard navigation</H2>

<p class="text-sm text-muted-foreground mb-5">Every interactive component is fully keyboard accessible. The keyboard patterns follow WAI-ARIA APG conventions so users get consistent behavior across the web.</p>

<TableCard title="keyboard patterns by component type" mb="2.5rem"><table class="table" data-variant="simple">
      <thead>
        <tr>
          <th class="whitespace-nowrap">Key</th>
          <th>Menus &amp; Dropdowns</th>
          <th>Tabs</th>
          <th>Dialogs</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>
            <kbd>↑</kbd>
            <kbd>↓</kbd>
          </td>
          <td>Navigate between menu items</td>
          <td>Navigate tabs (vertical)</td>
          <td>Not used</td>
        </tr>
        <tr>
          <td>
            <kbd>←</kbd>
            <kbd>→</kbd>
          </td>
          <td>Not used</td>
          <td>Navigate tabs (horizontal)</td>
          <td>Not used</td>
        </tr>
        <tr>
          <td>
            <kbd>Home</kbd>
          </td>
          <td>Jump to first item</td>
          <td>Jump to first tab</td>
          <td>Not used</td>
        </tr>
        <tr>
          <td>
            <kbd>End</kbd>
          </td>
          <td>Jump to last item</td>
          <td>Jump to last tab</td>
          <td>Not used</td>
        </tr>
        <tr>
          <td><kbd>Enter</kbd> / <kbd>Space</kbd></td>
          <td>Activate item</td>
          <td>Activate tab</td>
          <td>Activate focused button</td>
        </tr>
        <tr>
          <td>
            <kbd>Escape</kbd>
          </td>
          <td>Close menu, return focus to trigger</td>
          <td>Not used</td>
          <td>Close dialog, return focus to trigger</td>
        </tr>
        <tr>
          <td>
            <kbd>Tab</kbd>
          </td>
          <td>Close menu and move to next focusable</td>
          <td>Move into tab panel</td>
          <td>Trapped within dialog</td>
        </tr>
        <tr>
          <td>Type-ahead</td>
          <td>Jump to item starting with typed character</td>
          <td>Not used</td>
          <td>Not used</td>
        </tr>
      </tbody>
    </table></TableCard>

<div class="sep" />

<H2>Roving tabindex</H2>

<p class="text-sm text-muted-foreground mb-5">Composite widgets (tabs, toolbars, menus) use roving tabindex so the entire widget acts as a single tab stop. Only one item has <code>tabindex="0"</code> at a time - all others have <code>tabindex="-1"</code>. Arrow keys move focus between items.</p>

<CodeWindow lang="html" title="roving tabindex pattern" mb="1.5rem" code={"<!-- Only the active tab is in the tab order -->\n<div role=\"tablist\">\n  <button role=\"tab\" tabindex=\"0\" aria-selected=\"true\">Tab 1</button>\n  <button role=\"tab\" tabindex=\"-1\" aria-selected=\"false\">Tab 2</button>\n  <button role=\"tab\" tabindex=\"-1\" aria-selected=\"false\">Tab 3</button>\n</div>\n\n<!-- User presses → - focus moves to Tab 2:\n     Tab 1: tabindex=\"-1\", Tab 2: tabindex=\"0\" -->"} />

<CodeWindow lang="javascript" title="roving tabindex - JavaScript pattern" mb="1.5rem" code={"// Move focus to the item at `index` - df$ writes the attributes\nfunction focusItem(items, index) {\n  df$(items).attr('tabindex', '-1');\n  df$(items[index]).attr('tabindex', '0');\n  items[index].focus(); // focus stays a native call\n}"} />

<p class="text-sm text-muted-foreground mb-5"><strong>Used by:</strong> Tabs, Toolbar, Toggle Group, Dropdown Menu, Tree View</p>

<div class="sep" />

<H2>Focus management</H2>

<p class="text-sm text-muted-foreground mb-5">When overlays open and close, focus must move predictably. Dialogs trap focus. When a modal closes, focus returns to the trigger that opened it.</p>

<div class="def-grid">
  <span class="def-term">Focus trapping</span>
  <span class="text-sm text-muted-foreground"><code>&lt;dialog&gt;</code> with <code>.showModal()</code> traps focus natively - Tab cycles within the dialog only. No JS focus-trap library needed.</span>
  <span class="def-term">Focus restoration</span>
  <span class="text-sm text-muted-foreground">When a dialog or menu closes, focus returns to the trigger element that opened it. JS stores a reference to the trigger before opening.</span>
  <span class="def-term">Focus-visible</span>
  <span class="text-sm text-muted-foreground"><code>:focus-visible</code> shows focus rings only on keyboard navigation, not mouse clicks. Applied to every interactive component.</span>
</div>

<CodeWindow lang="javascript" title="focus restoration pattern" mb="2.5rem" code={"// Store the trigger before opening\ndialog._trigger = triggerButton;\ndialog.showModal();\n\n// Restore focus when the dialog closes\ndf$(dialog).on('close', () => dialog._trigger?.focus());"} />

<div class="sep" />

<H2>Live regions</H2>

<p class="text-sm text-muted-foreground mb-5">Live regions announce dynamic content changes to screen readers without moving focus. Toast notifications and alerts use these to ensure users are informed of updates.</p>

<div class="def-grid">
  <code style="font-size:0.8125rem;font-weight:600;">aria-live="polite"</code>
  <span class="text-sm text-muted-foreground">Announced after the screen reader finishes its current output. Used for info and success toasts.</span>
  <code style="font-size:0.8125rem;font-weight:600;">aria-live="assertive"</code>
  <span class="text-sm text-muted-foreground">Interrupts the screen reader immediately. Used for error/destructive toasts and alerts.</span>
  <code style="font-size:0.8125rem;font-weight:600;">aria-atomic="true"</code>
  <span class="text-sm text-muted-foreground">The entire region is announced as a whole, not just the changed parts.</span>
</div>

<CodeWindow lang="markup" title="live region - toast notification" mb="2.5rem" code={"<!-- Success toast: polite announcement -->\n<div class=\"toast\" role=\"status\"\n  aria-live=\"polite\" aria-atomic=\"true\">\n  Settings saved successfully.\n</div>\n<!-- Error toast: assertive (immediate) announcement -->\n<div class=\"toast\" data-variant=\"destructive\"\n  role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\">\n  Failed to save. Please try again.\n</div>"} />

<div class="sep" />

<H2>Screen reader considerations</H2>

<p class="text-sm text-muted-foreground mb-5">A few patterns help screen readers present clean, meaningful content.</p>

<div class="def-grid">
  <span class="def-term">Decorative icons</span>
  <span class="text-sm text-muted-foreground">Icons next to text labels get <code>aria-hidden="true"</code> so they're not announced redundantly.</span>
  <span class="def-term">Icon-only buttons</span>
  <span class="text-sm text-muted-foreground">Buttons with no visible text need <code>aria-label</code> to provide an accessible name: <code>&lt;button aria-label="Close"&gt;</code>.</span>
  <span class="def-term">Visually hidden text</span>
  <span class="text-sm text-muted-foreground">Text that should be announced but not visible uses the shipped <code>.sr-only</code> utility (see below).</span>
  <span class="def-term">Form labels</span>
  <span class="text-sm text-muted-foreground">Every form input has a visible <code>&lt;label&gt;</code> element with a matching <code>for</code>/<code>id</code> pair, or <code>aria-label</code> for unlabeled inputs.</span>
</div>

<CodeWindow lang="html" title="icon button accessibility" mb="2.5rem" code={"<!-- Icon-only button: needs aria-label -->\n<button class=\"btn\" data-size=\"icon\" aria-label=\"Close\">\n  <svg aria-hidden=\"true\">...</svg>\n</button>\n\n<!-- Button with text: the icon is decorative -->\n<button class=\"btn\">\n  <svg aria-hidden=\"true\">...</svg>\n  Save Changes\n</button>"} />

<div class="sep" />

<H2>Screen-reader-only content</H2>

<p class="text-sm text-muted-foreground mb-5">
  Some text belongs to the accessibility tree but not to the visual design: an extra word of context on a link, the unit a <code>{"<meter>"}</code> omits, the label an icon-only control needs. <code>.sr-only</code> ships in the optional <a class="link" href="#install"><code>theme/utils/accessibility.css</code></a> module and clips content to a 1px box - CSS the browser still hands to assistive technology (unlike <code>display:none</code> or <code>visibility:hidden</code>, which hide it from screen readers too). <code>.not-sr-only</code> reverses it - the classic skip-link pattern. This very page links the module, so the demo below is the real utility, not a replica.
</p>

```html example schema="none" label="Extra context for a screen reader" hint="The link reads 'Read the changelog' on screen; a screen reader announces 'Read the changelog (opens the release history)'. The preview loads the real module - the phrase is in the accessibility tree, clipped to a 1px box."
<a class="btn" data-variant="link" href="#"
  >Read the changelog<span class="sr-only"> (opens the release history)</span></a
>
```

<p class="text-xs text-muted-foreground mt-3 mb-8">
  The link reads identically on screen - a screen reader announces the extra phrase. Never put the <em>only</em> accessible name of a focusable control inside <code>.sr-only</code>; use <code>aria-label</code> for that.
</p>

<h2 id="install" class="h2-display">Load the accessibility module</h2>

```html title="index.html · head"
<link rel="stylesheet" href="../theme/utils/default-semantic-tokens.css" />
<!-- optional module: .sr-only / .not-sr-only -->
<link rel="stylesheet" href="../theme/utils/accessibility.css" />
```

<p class="text-sm text-muted-foreground mt-8 mb-8"> Each component's <code>component-skill.md</code> includes a dedicated ARIA section listing the exact attributes required for that component. See the <a href="https://www.w3.org/WAI/ARIA/apg/" target="_blank" rel="noopener" class="btn" data-variant="link">WAI-ARIA APG</a> for the full specifications these patterns implement. </p>

</DocPage>
