# Accessibility

Contrast, focus, keyboard, target size and names: what every screen has to meet, with the WCAG 2.2 criterion behind each number.

API [Button](/ui/storybook/?path=/docs/ui-primitives-button--docs) [Tooltip](/ui/storybook/?path=/docs/ui-primitives-tooltip--docs) [Label](/ui/storybook/?path=/docs/ui-primitives-label--docs) [Dialog](/ui/storybook/?path=/docs/ui-primitives-dialog--docs) [DropdownMenu](/ui/storybook/?path=/docs/ui-primitives-dropdownmenu--docs) [Input](/ui/storybook/?path=/docs/ui-primitives-input--docs) [Badge](/ui/storybook/?path=/docs/ui-primitives-badge--docs) [Toaster](/ui/storybook/?path=/docs/ui-primitives-toaster--docs) [FilterMenu](/ui/storybook/?path=/docs/ui-filtermenu--docs) [ThemeEditor](/ui/storybook/?path=/docs/ui-themeeditor--docs) [Toolbar](/ui/storybook/?path=/docs/ui-toolbar--docs) [useScrollInsets](/ui/storybook/?path=/docs/ui-hooks-usescrollinsets--docs) [useSlashShortcut](/ui/storybook/?path=/docs/ui-hooks-useslashshortcut--docs) [Markdown](/ui/storybook/?path=/docs/ui-markdown-markdown--docs)

> **Every action works by keyboard, by touch and through a screen reader, and every word and edge is readable in every theme held to the numbers below.**

The bar is [WCAG 2.2](https://www.w3.org/TR/WCAG22/) level AA. Each number below links the success criterion (SC) it comes from; where a page asks for more than AA, it says so and names the source. @orz/ui's components are built on Radix, which brings roles, keyboard handling and focus management with it. What they cannot do for an app is choose its words, its colours and what it puts on a screen, and most of this page is about that.

## Contrast

```tsx
import { resolvePalette, type TokenName } from "@orz/themes";
import { InlineCode } from "@orz/ui/components/inline-code";
import {
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableHeader,
  TableRow,
} from "@orz/ui/components/table";
import { contrastRatio, parseColor } from "@orz/ui/lib/color";
import { useTheme } from "@orz/ui/theme";
import { useEffect, useState } from "react";

// Text needs 4.5:1 (WCAG 2.2 SC 1.4.3); a control's edge or state 3:1 (SC 1.4.11).
const PAIRS: { fg: TokenName; bg: TokenName; min: number; use: string }[] = [
  { fg: "foreground", bg: "background", min: 4.5, use: "Body text" },
  { fg: "muted-foreground", bg: "background", min: 4.5, use: "Secondary text" },
  { fg: "muted-foreground", bg: "muted", min: 4.5, use: "Inactive tab" },
  { fg: "primary-foreground", bg: "primary", min: 4.5, use: "Primary button" },
  { fg: "destructive", bg: "background", min: 4.5, use: "Error message" },
  { fg: "ring", bg: "background", min: 3, use: "Focus ring" },
  { fg: "input", bg: "background", min: 3, use: "Field border" },
];

export function ContrastPairs() {
  const { theme, colorScheme, variant, amoled } = useTheme();
  const tokens = resolvePalette(theme, colorScheme, variant, {
    amoled,
  })?.tokens;
  // The pick lives in the browser, so the server-rendered page cannot show it.
  const [mounted, setMounted] = useState(false);
  useEffect(() => setMounted(true), []);

  return (
    <Table>
      <TableHeader>
        <TableRow>
          <TableHead>Use</TableHead>
          <TableHead>Tokens</TableHead>
          <TableHead className="text-right">Ratio</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        {PAIRS.map(({ fg, bg, min, use }) => {
          const f = tokens && parseColor(tokens[fg]);
          const b = tokens && parseColor(tokens[bg]);
          const ratio =
            mounted && f && b ? contrastRatio(f.color, b.color) : null;
          return (
            <TableRow key={`${fg} ${bg}`}>
              <TableCell>{use}</TableCell>
              <TableCell>
                <InlineCode>{fg}</InlineCode> on <InlineCode>{bg}</InlineCode>
              </TableCell>
              <TableCell className="text-right tabular-nums">
                {ratio === null
                  ? "–"
                  : // Rounded down, so 4.497 never reads as a passing 4.50.
                    `${(Math.floor(ratio * 100) / 100).toFixed(2)}:1 ${ratio >= min ? "passes" : `fails ${min}:1`}`}
              </TableCell>
            </TableRow>
          );
        })}
      </TableBody>
    </Table>
  );
}
```

The table measures the theme you are reading this in; pick another from the theme menu and it follows.

- **Text: 4.5:1** against what it sits on ([SC 1.4.3](https://www.w3.org/TR/WCAG22/#contrast-minimum)). Large text, 24px or 18.66px bold and up, needs 3:1. A tag's name is held to 4.5:1 on its own fill, in each of its colours.
- **Edges and states: 3:1** — the edge that shows where a field is, the focus ring, the tick that marks a highlighted or open row and the bar that marks a picked one in a list box or a table, the edge across the current tab and the edge of a toggle held down while it is on, a chart's series, the thumb of a switch, an icon that carries meaning on its own ([SC 1.4.11](https://www.w3.org/TR/WCAG22/#non-text-contrast)). A fill alone is never the state: a row's highlight measures barely over 1:1 against the list around it. A marker badge's count is held to 4.5:1 on its fill, as text is.
- **Disabled controls are exempt.** They are drawn at half opacity on purpose; do not use the same look for anything a reader is meant to read.
- **Colour reads from the tokens, never a hard-coded value.** A token is held to these numbers in every built-in theme but the ones used as published; a hex code is held to them in the one theme it was picked in.
- **Never colour alone** ([SC 1.4.1](https://www.w3.org/TR/WCAG22/#use-of-color)). An invalid field is red *and* says what is wrong; a diff line is green *and* starts with `+`; a failed run is red *and* has a failed icon.

Catppuccin and Prohibitorum keep their published values, so a few of their pairs fall below these numbers. A few other themes keep a file tree's status colours on a hovered row's accent or in a sidebar, where the letter beside each says the status too. These are all of them, measured from the palettes:

| Theme                                                            | Token              | On                                                             | Lowest              |
| ---------------------------------------------------------------- | ------------------ | -------------------------------------------------------------- | ------------------- |
| Picotera Pico                                                    | `destructive`      | `accent`, `sidebar-accent`                                     | 3.75:1, under 4.5:1 |
| Picotera Pico                                                    | `success`          | `accent`, `sidebar-accent`                                     | 3.79:1, under 4.5:1 |
| Picotera Pico                                                    | `warning`          | `accent`, `sidebar-accent`                                     | 3.88:1, under 4.5:1 |
| Picotera Tera                                                    | `destructive`      | `accent`, `sidebar-accent`                                     | 4.32:1, under 4.5:1 |
| Visual Studio light                                              | `destructive`      | `sidebar-accent`                                               | 4.02:1, under 4.5:1 |
| Visual Studio light                                              | `success`          | `sidebar-accent`                                               | 4.00:1, under 4.5:1 |
| Visual Studio light                                              | `warning`          | `accent`, `sidebar`, `sidebar-accent`                          | 3.63:1, under 4.5:1 |
| Visual Studio light                                              | `muted-foreground` | `sidebar-accent`                                               | 4.49:1, under 4.5:1 |
| Visual Studio dark                                               | `destructive`      | `accent`, `sidebar-accent`                                     | 3.46:1, under 4.5:1 |
| Visual Studio dark · AMOLED                                      | `destructive`      | `accent`, `sidebar-accent`                                     | 4.28:1, under 4.5:1 |
| GitHub light                                                     | `destructive`      | `sidebar-accent`                                               | 4.27:1, under 4.5:1 |
| GitHub light                                                     | `success`          | `accent`, `sidebar-accent`                                     | 4.02:1, under 4.5:1 |
| GitHub light                                                     | `warning`          | `accent`, `sidebar-accent`                                     | 3.85:1, under 4.5:1 |
| GitHub dark                                                      | `destructive`      | `accent`, `sidebar-accent`                                     | 3.74:1, under 4.5:1 |
| GitHub dark · AMOLED                                             | `destructive`      | `accent`, `sidebar-accent`                                     | 4.10:1, under 4.5:1 |
| Catppuccin Latte                                                 | `muted-foreground` | `background`, `muted`, `accent`, `sidebar`, `sidebar-accent`   | 3.20:1, under 4.5:1 |
| Catppuccin Latte                                                 | `success`          | `background`, `popover`, `accent`, `sidebar`, `sidebar-accent` | 2.17:1, under 4.5:1 |
| Catppuccin Latte                                                 | `warning`          | `background`, `popover`, `accent`, `sidebar`, `sidebar-accent` | 1.70:1, under 4.5:1 |
| Catppuccin Latte                                                 | `destructive`      | `accent`, `sidebar`, `sidebar-accent`                          | 3.52:1, under 4.5:1 |
| Catppuccin Latte                                                 | `input`            | `background`, `card`, `popover`                                | 2.30:1, under 3:1   |
| Catppuccin Latte                                                 | `ring`             | `background`, `card`, `popover`, `muted`                       | 2.06:1, under 3:1   |
| Catppuccin Latte                                                 | `sidebar-ring`     | `sidebar`                                                      | 2.62:1, under 3:1   |
| Catppuccin Latte                                                 | `chart-2`          | `background`                                                   | 2.96:1, under 3:1   |
| Catppuccin Latte                                                 | `chart-3`          | `background`                                                   | 2.31:1, under 3:1   |
| Catppuccin Latte · Mocha (Gray), Frappé (Gray), Macchiato (Gray) | `muted-foreground` | `background`, `muted`, `accent`, `sidebar`, `sidebar-accent`   | 3.16:1, under 4.5:1 |
| Catppuccin Latte · Mocha (Gray), Frappé (Gray), Macchiato (Gray) | `success`          | `background`, `popover`, `accent`, `sidebar`, `sidebar-accent` | 2.17:1, under 4.5:1 |
| Catppuccin Latte · Mocha (Gray), Frappé (Gray), Macchiato (Gray) | `warning`          | `background`, `popover`, `accent`, `sidebar`, `sidebar-accent` | 1.70:1, under 4.5:1 |
| Catppuccin Latte · Mocha (Gray), Frappé (Gray), Macchiato (Gray) | `destructive`      | `accent`, `sidebar`, `sidebar-accent`                          | 3.52:1, under 4.5:1 |
| Catppuccin Latte · Mocha (Gray), Frappé (Gray), Macchiato (Gray) | `input`            | `background`, `card`, `popover`                                | 2.29:1, under 3:1   |
| Catppuccin Latte · Mocha (Gray), Frappé (Gray), Macchiato (Gray) | `ring`             | `background`, `card`, `popover`, `muted`                       | 2.06:1, under 3:1   |
| Catppuccin Latte · Mocha (Gray), Frappé (Gray), Macchiato (Gray) | `sidebar-ring`     | `sidebar`                                                      | 2.62:1, under 3:1   |
| Catppuccin Latte · Mocha (Gray), Frappé (Gray), Macchiato (Gray) | `chart-2`          | `background`                                                   | 2.96:1, under 3:1   |
| Catppuccin Latte · Mocha (Gray), Frappé (Gray), Macchiato (Gray) | `chart-3`          | `background`                                                   | 2.32:1, under 3:1   |
| Catppuccin Mocha · Frappé                                        | `muted-foreground` | `muted`, `accent`, `sidebar-accent`                            | 4.26:1, under 4.5:1 |
| Catppuccin Mocha · Frappé                                        | `destructive`      | `accent`, `sidebar-accent`                                     | 3.57:1, under 4.5:1 |
| Catppuccin Mocha · Frappé                                        | `input`            | `background`, `card`, `popover`                                | 2.87:1, under 3:1   |
| Catppuccin Mocha · Frappé (Gray)                                 | `muted-foreground` | `muted`, `accent`, `sidebar-accent`                            | 4.25:1, under 4.5:1 |
| Catppuccin Mocha · Frappé (Gray)                                 | `destructive`      | `accent`, `sidebar-accent`                                     | 3.56:1, under 4.5:1 |
| Catppuccin Mocha · Frappé (Gray)                                 | `input`            | `background`, `card`, `popover`                                | 2.86:1, under 3:1   |
| Catppuccin Mocha · Frappé · AMOLED                               | `input`            | `background`, `card`, `popover`                                | 2.87:1, under 3:1   |
| Catppuccin Mocha · Frappé (Gray) · AMOLED                        | `input`            | `background`, `card`, `popover`                                | 2.86:1, under 3:1   |
| Gruvbox light                                                    | `destructive`      | `sidebar-accent`                                               | 4.10:1, under 4.5:1 |
| Gruvbox light                                                    | `success`          | `accent`, `sidebar-accent`                                     | 3.82:1, under 4.5:1 |
| Gruvbox light                                                    | `warning`          | `accent`, `sidebar-accent`                                     | 3.85:1, under 4.5:1 |
| Gruvbox light                                                    | `muted-foreground` | `sidebar-accent`                                               | 4.44:1, under 4.5:1 |
| Gruvbox dark                                                     | `destructive`      | `accent`, `sidebar-accent`                                     | 3.24:1, under 4.5:1 |
| Gruvbox dark                                                     | `success`          | `accent`, `sidebar-accent`                                     | 3.31:1, under 4.5:1 |
| Gruvbox dark                                                     | `warning`          | `accent`, `sidebar-accent`                                     | 4.13:1, under 4.5:1 |
| Gruvbox dark                                                     | `muted-foreground` | `accent`, `sidebar-accent`                                     | 4.15:1, under 4.5:1 |
| Gruvbox dark · AMOLED                                            | `destructive`      | `accent`, `sidebar-accent`                                     | 4.24:1, under 4.5:1 |
| Gruvbox dark · AMOLED                                            | `success`          | `accent`, `sidebar-accent`                                     | 4.33:1, under 4.5:1 |
| Prohibitorum light                                               | `success`          | `sidebar-accent`                                               | 4.22:1, under 4.5:1 |
| Prohibitorum light                                               | `warning`          | `sidebar-accent`                                               | 3.96:1, under 4.5:1 |
| Prohibitorum light                                               | `muted-foreground` | `sidebar-accent`                                               | 4.38:1, under 4.5:1 |
| Prohibitorum light                                               | `sidebar-ring`     | `sidebar`                                                      | 2.48:1, under 3:1   |
| Prohibitorum light · Nord                                        | `destructive`      | `sidebar-accent`                                               | 4.33:1, under 4.5:1 |
| Prohibitorum light · Nord                                        | `success`          | `accent`, `sidebar`, `sidebar-accent`                          | 3.62:1, under 4.5:1 |
| Prohibitorum light · Sand                                        | `success`          | `accent`, `sidebar-accent`                                     | 3.99:1, under 4.5:1 |
| Prohibitorum light · Sand                                        | `warning`          | `accent`, `sidebar-accent`                                     | 3.74:1, under 4.5:1 |
| Prohibitorum light · Sand                                        | `muted-foreground` | `sidebar-accent`                                               | 4.49:1, under 4.5:1 |
| Prohibitorum light · Matcha                                      | `success`          | `accent`, `sidebar-accent`                                     | 3.89:1, under 4.5:1 |
| Prohibitorum light · Matcha                                      | `warning`          | `accent`, `sidebar`, `sidebar-accent`                          | 3.64:1, under 4.5:1 |
| Prohibitorum light · Matcha                                      | `muted-foreground` | `sidebar-accent`                                               | 4.29:1, under 4.5:1 |
| Prohibitorum light · Sakura                                      | `success`          | `accent`, `sidebar-accent`                                     | 3.99:1, under 4.5:1 |
| Prohibitorum light · Sakura                                      | `warning`          | `accent`, `sidebar-accent`                                     | 3.74:1, under 4.5:1 |
| Prohibitorum light · Lavender                                    | `destructive`      | `sidebar-accent`                                               | 4.34:1, under 4.5:1 |
| Prohibitorum light · Lavender                                    | `success`          | `accent`, `sidebar`, `sidebar-accent`                          | 3.63:1, under 4.5:1 |
| Prohibitorum light · Lavender                                    | `muted-foreground` | `sidebar-accent`                                               | 4.23:1, under 4.5:1 |
| Prohibitorum light · Lagoon                                      | `success`          | `accent`, `sidebar-accent`                                     | 3.98:1, under 4.5:1 |
| Prohibitorum light · Lagoon                                      | `warning`          | `accent`, `sidebar-accent`                                     | 3.73:1, under 4.5:1 |
| Prohibitorum light · Lagoon                                      | `muted-foreground` | `sidebar-accent`                                               | 4.39:1, under 4.5:1 |
| Prohibitorum light · Citrus                                      | `primary`          | `background`, `card`, `accent`                                 | 1.19:1, under 3:1   |
| Prohibitorum light · Citrus                                      | `success`          | `sidebar-accent`                                               | 4.06:1, under 4.5:1 |
| Prohibitorum light · Citrus                                      | `warning`          | `accent`, `sidebar-accent`                                     | 3.81:1, under 4.5:1 |
| Prohibitorum light · Citrus                                      | `chart-1`          | `background`                                                   | 1.33:1, under 3:1   |
| Prohibitorum dark · Nord                                         | `destructive`      | `accent`, `sidebar-accent`                                     | 4.50:1, under 4.5:1 |
| Prohibitorum dark · Nord                                         | `success`          | `accent`, `sidebar-accent`                                     | 4.45:1, under 4.5:1 |
| Prohibitorum dark · Nord                                         | `muted-foreground` | `accent`, `sidebar-accent`                                     | 4.33:1, under 4.5:1 |
| Prohibitorum dark · Matcha                                       | `muted-foreground` | `accent`, `sidebar-accent`                                     | 4.00:1, under 4.5:1 |
| Prohibitorum dark · Lavender                                     | `destructive`      | `accent`, `sidebar-accent`                                     | 4.35:1, under 4.5:1 |
| Dracula dark                                                     | `destructive`      | `accent`, `sidebar-accent`                                     | 3.77:1, under 4.5:1 |
| Nord dark                                                        | `destructive`      | `accent`, `sidebar-accent`                                     | 3.47:1, under 4.5:1 |
| Nord dark                                                        | `success`          | `accent`, `sidebar-accent`                                     | 4.47:1, under 4.5:1 |
| Tokyo Night dark                                                 | `destructive`      | `accent`, `sidebar-accent`                                     | 4.12:1, under 4.5:1 |
| Tokyo Night dark                                                 | `muted-foreground` | `accent`, `sidebar-accent`                                     | 4.44:1, under 4.5:1 |
| One Dark dark                                                    | `destructive`      | `accent`, `sidebar-accent`                                     | 3.65:1, under 4.5:1 |
| One Dark dark                                                    | `warning`          | `accent`, `sidebar-accent`                                     | 3.85:1, under 4.5:1 |
| One Dark dark                                                    | `muted-foreground` | `accent`, `sidebar-accent`                                     | 4.36:1, under 4.5:1 |
| Monokai dark                                                     | `destructive`      | `accent`, `sidebar-accent`                                     | 3.15:1, under 4.5:1 |
| Monokai dark                                                     | `success`          | `accent`, `sidebar-accent`                                     | 4.22:1, under 4.5:1 |
| Monokai dark                                                     | `muted-foreground` | `accent`, `sidebar-accent`                                     | 4.47:1, under 4.5:1 |
| Monokai dark · AMOLED                                            | `destructive`      | `accent`, `sidebar-accent`                                     | 4.03:1, under 4.5:1 |
| Afterglow dark                                                   | `destructive`      | `accent`, `sidebar-accent`                                     | 3.85:1, under 4.5:1 |
| Afterglow dark                                                   | `muted-foreground` | `accent`, `sidebar-accent`                                     | 4.43:1, under 4.5:1 |

A row here is a gap in that palette, not a licence to copy it. A custom theme is held to the same numbers, and the theme editor shows each token's ratio against the surface it is drawn on.

## Focus

**Do**

Keep the focus ring every @orz/ui control draws on `:focus-visible`, and give anything else that takes focus the same one.

**Don't**

Remove the ring because it looks heavy after a click. `:focus-visible` already leaves it off for a mouse click and shows it for the keyboard.

- **Visible** ([SC 2.4.7](https://www.w3.org/TR/WCAG22/#focus-visible)): whatever has keyboard focus shows it. A clickable surface that is not an @orz/ui control is a `<button>` or `<a>`, so it takes focus at all, and borrows the `focus-visible:` classes from `Button`.
- **Drawn apart from the control** ([SC 2.4.13](https://www.w3.org/TR/WCAG22/#focus-appearance)): the ring is a 2px `ring` outline 2px off the control's edge, so the page shows between the two and the ring is measured against the page, never against a filled button that may share its colour. A destructive `Button` draws it in `destructive`. Being an `outline`, not a shadow, it still shows in Windows' contrast themes, which drop shadows.
- **Not hidden** ([SC 2.4.11](https://www.w3.org/TR/WCAG22/#focus-not-obscured-minimum), new in 2.2): a sticky header, a toolbar or the on-screen keyboard never covers the focused element entirely. Give a scroller with a sticky header `scroll-padding-top` of the header's height, so Tab lands clear of it; `useScrollInsets` does the same for the page's own `scrollIntoView` calls, and counts the on-screen keyboard.
- **In reading order** ([SC 2.4.3](https://www.w3.org/TR/WCAG22/#focus-order)): Tab follows the DOM, so the DOM follows the layout. No positive `tabIndex`.
- **Returned.** A `Dialog`, `Sheet` or menu holds focus while open and gives it back to what opened it on close. When that opener is gone — a menu item that removed its own row, a confirmed delete that took it — send focus to the next meaningful control yourself, as `LoadFailure`'s `retryRef` exists to; `ConfirmDialog`'s `onCloseAutoFocus` is the moment for it. A key or a row's own button that removes the row it was on drops the focus the same way. In a list the next meaningful control is the row now in its place, else the one before it, else the empty state that stands in for the emptied list, which takes the focus with `tabIndex={-1}`. What opened it is the control the reader pressed, focused or not (Safari focuses no button or link it presses), so open one from a control that can take the focus back, a button or a link, never a bare image or `div` with a click handler.

## Keyboard

Everything a pointer can do, the keyboard can do ([SC 2.1.1](https://www.w3.org/TR/WCAG22/#keyboard)), and nothing the keyboard enters it cannot leave ([SC 2.1.2](https://www.w3.org/TR/WCAG22/#no-keyboard-trap)). The components follow the WAI-ARIA patterns, so an app keeps to these keys and adds no competing ones:

| Key            | Does                                                                                                             |
| -------------- | ---------------------------------------------------------------------------------------------------------------- |
| Tab, Shift+Tab | Moves between controls, and into and out of a group as one stop                                                  |
| Arrow keys     | Move within a group: `RadioGroup`, `Tabs`, a `Toolbar`, a menu, `Select`'s list, a `Slider`                      |
| Enter          | Activates a button or link, submits a form, picks a menu item                                                    |
| Space          | Activates a button, toggles a `Checkbox` or `Switch`                                                             |
| Escape         | Closes the innermost open overlay, and nothing else; among the toasts, takes the focus back where it was instead |
| Alt+T          | Moves the focus to the toasts, over an open overlay too; Tab past them takes it back                             |
| `/`            | Focuses the page's search (`useSlashShortcut`) unless shortcuts are turned off; typed as itself inside a field   |

```tsx
import {
  INBOX_LABEL_COLORS,
  INBOX_LABELS,
  INBOX_THREADS,
  type InboxThread,
} from "@orz/fixtures/inbox.ts";
import { Badge } from "@orz/ui/components/badge";
import {
  DropdownMenuCheckboxItem,
  DropdownMenuLabel,
} from "@orz/ui/components/dropdown-menu";
import {
  Toolbar,
  ToolbarButton,
  ToolbarMenu,
  ToolbarSpacer,
} from "@orz/ui/components/toolbar";
import {
  ArchiveIcon,
  InboxIcon,
  MailIcon,
  StarIcon,
  TagIcon,
} from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";

const thread = INBOX_THREADS.find(
  ({ id }) => id === "touch-sizes",
) as InboxThread;

export function ThreadToolbar() {
  const [archived, setArchived] = useState(false);
  const [labels, setLabels] = useState(thread.labels);
  const [starred, setStarred] = useState(thread.starred);
  const move = (archive: boolean) => {
    setArchived(archive);
    toast(archive ? "Conversation archived" : "Conversation moved to Inbox", {
      action: { label: "Undo", onClick: () => setArchived(!archive) },
    });
  };
  return (
    <div className="grid gap-3">
      <Toolbar aria-label="Thread actions">
        <ToolbarButton
          aria-label={archived ? "Move to Inbox" : "Archive"}
          onClick={() => move(!archived)}
        >
          {archived ? <InboxIcon /> : <ArchiveIcon />}
        </ToolbarButton>
        <ToolbarButton
          aria-label="Mark as unread"
          onClick={() => toast("Conversation marked as unread")}
        >
          <MailIcon />
        </ToolbarButton>
        <ToolbarMenu
          icon={<TagIcon />}
          label="Labels"
          iconOnly
          contentClassName="w-44"
        >
          <DropdownMenuLabel>Labels</DropdownMenuLabel>
          {INBOX_LABELS.map((label) => (
            <DropdownMenuCheckboxItem
              key={label}
              checked={labels.includes(label)}
              onCheckedChange={(on) =>
                setLabels((now) =>
                  on ? [...now, label] : now.filter((x) => x !== label),
                )
              }
              onSelect={(event) => event.preventDefault()}
            >
              <Badge variant="marker" color={INBOX_LABEL_COLORS[label]}>
                {label}
              </Badge>
            </DropdownMenuCheckboxItem>
          ))}
        </ToolbarMenu>
        <ToolbarSpacer />
        <ToolbarButton
          aria-label="Star"
          aria-pressed={starred}
          onClick={() => setStarred(!starred)}
        >
          <StarIcon className={starred ? "fill-current" : undefined} />
        </ToolbarButton>
      </Toolbar>
      <h3 className="font-semibold">{thread.subject}</h3>
      <p className="flex flex-wrap gap-1">
        {archived && <Badge>Archive</Badge>}
        {labels.map((label) => (
          <Badge key={label} variant="marker" color={INBOX_LABEL_COLORS[label]}>
            {label}
          </Badge>
        ))}
      </p>
    </div>
  );
}
```

Do it without the mouse. Tab reaches the bar once and the arrow keys walk it, and each button's tooltip says what it is. Enter or Space archives, and the button becomes **Move to Inbox** with the focus still on it. In **Labels** the arrow keys move, Space ticks a label and leaves the menu open, and Escape closes the menu and nothing else, with the focus back on its button. `/` here reaches this site's search.

**A single-key shortcut that acts can be turned off** ([SC 2.1.4](https://www.w3.org/TR/WCAG22/#character-key-shortcuts)): speech input types stray single keys, and a stray key that archives, sends or deletes costs the user work. An app with shortcuts like that offers a setting for keyboard shortcuts, and does not mount those bindings while it is off. `/` alone is the mild case: it only moves focus to the search, so a stray one costs an Escape. WCAG still counts it, and once an app has the setting, `useSlashShortcut(onSlash, { enabled })` takes it and binds nothing while it is `false`. This site's [Settings](/ui/settings/index.md) page does exactly this.

## Target size

- **24 × 24px at least** for anything clickable ([SC 2.5.8](https://www.w3.org/TR/WCAG22/#target-size-minimum), AA, new in 2.2). A smaller target passes only when a 24px circle on its centre touches no other target.
- **36 × 36px on touch**, around every control and between neighbouring targets. Apple's [Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/accessibility) give a control 44 × 44pt by default and 28 × 28pt at the least, and count the room between controls as much as their size; [SC 2.5.5](https://www.w3.org/TR/WCAG22/#target-size-enhanced) (AAA) asks 44 × 44px of every target. @orz/ui takes the room rather than drawing a dense screen larger ([Touch & mobile](/ui/guidelines/platforms/touch-and-mobile/index.md#hit-areas)).
- **Drags have a click.** Anything done by dragging can also be done with single clicks or taps ([SC 2.5.7](https://www.w3.org/TR/WCAG22/#dragging-movements), AA, new in 2.2): a `Slider` moves to where its track is clicked, and with the arrow keys; every row of a `Reorder` has a pair of move buttons beside its handle ([Reordering](/ui/guidelines/patterns/reordering/index.md)).

On a mouse, @orz/ui's `Button` is 28px tall and its `xs` size 22px; a `Checkbox` and a `RadioGroup` item are 16px, and a `Switch` 20px tall. Those three pass by the spacing exception, so keep other targets out of the 24px around them, and pair each with its `Label`: the words then toggle it too. On a touch screen each control takes a 36px hit area and stands that far from the next; **Pointer** and **Touch** above any example on this site show both.

## Names and roles

```tsx
import { PROFILE } from "@orz/fixtures/account.ts";
import { Button } from "@orz/ui/components/button";
import { FieldDescription, FieldError } from "@orz/ui/components/field";
import { Input } from "@orz/ui/components/input";
import { Label } from "@orz/ui/components/label";
import { useRef, useState } from "react";
import { toast } from "sonner";

const check = (email: string) =>
  /^\S+@\S+\.\S+$/.test(email)
    ? undefined
    : "Enter an email address, like alice@example.com.";

export function ProfileEmail() {
  const [email, setEmail] = useState(PROFILE.email);
  const [error, setError] = useState<string>();
  const input = useRef<HTMLInputElement>(null);
  return (
    <form
      noValidate
      className="grid max-w-sm gap-4"
      onSubmit={(event) => {
        event.preventDefault();
        const problem = check(email);
        setError(problem);
        if (problem) input.current?.focus();
        else toast.success("Profile saved");
      }}
    >
      <div className="grid gap-2">
        <Label htmlFor="a11y-email">Email</Label>
        <Input
          ref={input}
          id="a11y-email"
          type="email"
          autoComplete="email"
          value={email}
          onChange={(event) => {
            setEmail(event.target.value);
            if (error) setError(check(event.target.value));
          }}
          aria-invalid={error !== undefined}
          aria-describedby={error ? "a11y-email-error" : "a11y-email-hint"}
        />
        {error ? (
          <FieldError id="a11y-email-error">{error}</FieldError>
        ) : (
          <FieldDescription id="a11y-email-hint">
            Like name@example.com.
          </FieldDescription>
        )}
      </div>
      <Button type="submit" className="justify-self-start">
        Save profile
      </Button>
    </form>
  );
}
```

Clear the email and press **Save profile**. The error appears beside the field in words, the field is marked invalid and takes the focus, and a screen reader reads the error with the field's name. Fix it and save: the toast that confirms it is announced without moving the focus.

- **Every control has a name** a screen reader can announce ([SC 4.1.2](https://www.w3.org/TR/WCAG22/#name-role-value)). A field gets a `Label` with `htmlFor`; an icon-only button gets an `aria-label`, and the same words in a `Tooltip` for sighted readers. A placeholder is not a name: it is gone once the reader types.
- **The visible words start the name** ([SC 2.5.3](https://www.w3.org/TR/WCAG22/#label-in-name)): a button that shows "Save" is not named "Submit form", or a speech user saying "click Save" misses it.
- **Status is announced** ([SC 4.1.3](https://www.w3.org/TR/WCAG22/#status-messages)) without moving focus. `toast()` goes through the `Toaster`'s live region, and `LoadFailure` is a `role="status"`; a message of your own that appears after an action needs one of the two. A `FilterMenu`, or a submenu with a filter box, says what the typing left once it rests: how many rows, or its empty state's words, or while a `loading` menu's rows are on their way its `loadingLabel`.
- **An error says what to fix** ([SC 3.3.1](https://www.w3.org/TR/WCAG22/#error-identification)), in text beside the field, and the field gets `aria-invalid`, which @orz/ui's inputs draw in red.
- **Structure is markup.** Headings are `h1`–`h3` in order, lists are lists, and a table of data is a `Table`, so a screen reader's headings and table navigation work. A `Markdown` under the page's own `h1`, such as an issue's body under its title, takes `headingLevel={2}`, so the body's `#` is not a second `h1`; a document embedded in it moves a level further down by itself.

## Motion and zoom

- **Motion stops on request.** Under `prefers-reduced-motion`, a slide, zoom or parallax is turned off and a fade may stay ([SC 2.3.3](https://www.w3.org/TR/WCAG22/#animation-from-interactions), AAA, and Apple's [HIG](https://developer.apple.com/design/human-interface-guidelines/motion)). @orz/ui's overlays already do this; motion an app adds is gated as [Motion](/ui/guidelines/foundations/motion/index.md#reduced-motion) describes.
- **Zoom is the reader's.** Never set `maximum-scale` or `user-scalable=no` in the viewport tag. Text reaches 200% without loss ([SC 1.4.4](https://www.w3.org/TR/WCAG22/#resize-text)) and a page works 320px wide without scrolling sideways ([SC 1.4.10](https://www.w3.org/TR/WCAG22/#reflow)); a log, a diff or a table may scroll inside its own box.

## On each platform

|               | Pointer and keyboard                                      | Touch and screen reader                                              |
| ------------- | --------------------------------------------------------- | -------------------------------------------------------------------- |
| Moving around | Tab and the arrow keys, with the focus ring showing where | VoiceOver or TalkBack swipes through the page in DOM order           |
| Hover         | Tooltips appear on hover and on focus                     | There is no hover; a tooltip's words must also be the control's name |
| Target        | 24px, or the spacing around it                            | 36px, and that far apart                                             |
| Shortcuts     | `/` and the menus' own keys                               | None; every shortcut has a visible control too                       |

## Checking a screen

1. Put the mouse away and do the screen's main task with the keyboard alone, watching the focus ring.
2. Go through the built-in themes, light and dark, and read every word; the contrast table above follows each one.
3. Zoom to 200%, then narrow the window to 320px.
4. Turn on VoiceOver or TalkBack and find every control by its name.
5. On a phone, or with **Touch** chosen above an example, reach every control with a thumb.

## In the demos

- [Sign in](/ui/demos/sign-in/index.md): The eye in the password field is a button named Show password that stays pressed while the password shows. Press Use a passkey instead: the whole form's error is announced as it appears.
- [Mail](/ui/demos/mail/index.md): Put the mouse away: Tab reaches every row and control, each icon button is named, and the single-key shortcuts can be turned off.
