Segmented

One choice out of a short, fixed set, laid out as a single track with a thumb that slides between the options. A radio group that looks like a switch.

Accessibility

Segmented is a real radio group, not a row of buttons dressed as one. Most of the work here is keeping what the native element already gives you, not adding ARIA.

What you get for free

Each option is an <input type="radio"> inside its own <label>. name gets a generated value when you leave it out, so the inputs always form one browser radio group.
  • One tab stop for the whole control. Tab moves onto the selected option, not onto each of them in turn.
  • Arrow keys move the selection within the group, wrapping at the ends, which is the behavior a screen reader user expects from a radio group.
  • Position is announced (“radio button, 2 of 4, Table”), because the browser knows the group.
  • It is a form control. Inside a <form> it submits like one, and passing name explicitly chooses the submitted key instead of taking a generated one.

Naming an option

A <label>'s accessible name comes from its text content, and that is easy to break.
  • An icon-only option must keep its word. An option with only an icon is allowed, and it leaves an unnamed radio with no warning.
  • Put the hidden word inside icon, not in label. A label beside the icon gets a gap before it, so an sr-only label that shows nothing still pushes the glyph off center. With label unset there is no gap.
  • An option's title is not a name. It lands on an inner div and names nothing.
  • Neither is tooltip on its own. It gives sighted users the word that sr-only hid, and it does not show on touch. Use both.

Naming the group

The options are named, and the group is not. A reader arriving on “Table, radio button, 2 of 4” has no way to know 2 of 4 what.
  • Put a visible label beside the control wherever there is room, and it does the job on its own.
  • Where there is no room, wrap the control in a labeled region instead of naming the track. An aria-label on Segmented lands on its outer div, not on the radio group the browser built.
  • Keep the segment words parallel, because they are read one at a time and out of context.

Disabled segments

  • Disable one option instead of the whole control. A disabled track takes the whole group out of the tab order, so a keyboard reader cannot even find out what it says.
  • Pair a disabled option with a tooltip, which still shows on a disabled option, to say why it is unavailable.
  • Never let disabled be the only way a segment says “unavailable”. Gray text alone is a contrast signal, and a contrast signal alone is not accessible.

Contrast and motion

  • The thumb's fill, its elevation and the text weight show the selection together. A restyle that keeps only a tint usually loses it, so check the selected and unselected text against their own backgrounds, not against the page.
  • Check a solid or colored track twice, once for the unselected text on the track and once for the selected text on the thumb, since those are two different pairs.
  • The focus ring is the browser's own on a real radio. Do not remove it, and do not replace it with a color change on the thumb, which is already doing a different job.
  • The thumb's slide is decoration. Anything you add on top of it belongs behind motion-safe:, the way the stacked label demo's glyph pop does.