Skip to content
IndexRequest a UIAboutContact

Segmented Control

A pill of options with a sliding thumb; arrow keys move between options and the content below changes.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a four-option segmented control (Day, Week, Month, Year) as a radiogroup. A near-black rounded thumb with white label slides beneath the selected segment using transform translateX with a 220 millisecond ease-out; unselected labels are grey. Arrow Left and Right (and Up and Down) move the selection and focus, Home and End jump to ends, each segment is a role radio with aria-checked and a roving tabindex. Below the control show a short panel whose text changes with the selection, for example "Showing the last 7 days". Light minimal style, 40 pixel tall pill, 1 pixel border, prefers-reduced-motion fallback. Plain HTML, CSS and JavaScript.

About this pattern

Definition

A segmented control is a row of mutually exclusive options styled as one pill. A thumb slides to the chosen segment, which makes the single choice obvious.

Purpose & UX principles

  • Use for two to five short, related options that change a view (Day, Week, Month) or a setting; not for navigating between pages.
  • Implement as a radio group so screen readers announce "1 of 4" and arrow keys move the choice.
  • Keep labels short and equal in weight; do not mix icons and text inconsistently.

Interaction states

  • Selected, unselected, hover, focus-visible, disabled.

Motion specification

  • The thumb slides over 220ms with a gentle ease-out; text colour crossfades 150ms.
  • Reduced motion: the thumb jumps with no slide.

Responsive behaviour

  • Segments share the width equally; on narrow screens shorten labels or allow horizontal scroll rather than wrapping.
  • Minimum segment height 36px for touch.

Code

HTML
<div class="bx"><div class="sg" id="sg" role="radiogroup" aria-label="Range"><i class="th" id="th" aria-hidden="true"></i></div><p class="pn" id="pn" aria-live="polite"></p></div>

Related patterns

Tab Navigation

↗
Tab NavigationNavigation

Radio Button

↗
Radio ButtonInputs & Forms

Toggle Switch

↗
Toggle SwitchInputs & Forms