# Segmented control

A small set of mutually exclusive choices, with a deliberate selected state.

## Usage

Use for two to four related options. The parent should update the associated view or filter. This is a radio group, not an ARIA tab widget.

Save the JSX and CSS Module in the same folder in a React project with CSS Modules support. Controlled components need parent state and change handlers.

## JSX

```jsx
"use client";
import styles from "./SegmentedControl.module.css";
import { useId } from "react";
export default function SegmentedControl({
  label = "View",
  options = ["Overview", "Activity", "Notes"],
  value = "Overview",
  onChange,
}) {
  const name = useId();
  return (
    <fieldset className={styles.field}>
      <legend>{label}</legend>
      <div className={styles.segments}>
        {options.map((option) => (
          <label key={option}>
            <input
              type="radio"
              name={name}
              value={option}
              checked={value === option}
              onChange={() => onChange?.(option)}
            />
            <span>{option}</span>
          </label>
        ))}
      </div>
    </fieldset>
  );
}

```

## CSS

```css
.field {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
  font: 14px var(--tdp-font, "DM Sans", system-ui, sans-serif);
  color: var(--tdp-text, #302e2b);
}
.field legend {
  padding: 0 0 10px;
  font-weight: 600;
}
.segments {
  display: flex;
  flex-wrap: wrap;
  padding: 5px;
  gap: 4px;
  background: var(--tdp-subtle, #eee8e1);
  border-radius: var(--tdp-radius, 8px);
}
.segments label {
  position: relative;
  flex: 1;
  cursor: pointer;
}
.segments input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.segments span {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: var(--tdp-control-height, 48px);
  padding: 9px 15px;
  border-radius: var(--tdp-radius, 8px);
  transition:
    background 0.2s,
    box-shadow 0.2s;
}
.segments input:checked + span {
  background: var(--tdp-surface, #fffdfa);
  box-shadow: 0 1px 2px #00000012;
}
.segments input:focus-visible + span {
  outline: 3px solid var(--tdp-focus, #7851a9);
  outline-offset: 2px;
}
.field:focus-visible,
.field :where(button, input, summary):focus-visible {
  outline: 3px solid var(--tdp-focus, #7851a9);
  outline-offset: 4px;
}
@media (prefers-reduced-motion: reduce) {
  .field,
  .field :where(button, input, summary, span) {
    transition: none !important;
    animation: none !important;
  }
}

```

## Props

- label (string): Group label, rendered as a legend.
- options (string[]): Unique option labels.
- value (string): Selected option.
- onChange (function): Receives the selected string.

## Accessibility

Native radios provide arrow-key movement and one selection per group. Each instance gets its own name through useId, and the legend labels the group.

Check accessibility again after customizing the component.

[Browse all components](/resources/components/)

Canonical: https://designproject.io/resources/components/segmented-control/

## Keep learning

- [How to create a UI color palette, step by step](https://designproject.io/resources/guides/create-ui-color-palette/)
- [Product design glossary: 44 terms explained](https://designproject.io/resources/glossary/)
- [How to choose font pairings for a product interface](https://designproject.io/resources/guides/choose-font-pairings/)
