Segmented control

A Segmented control lets users switch between related views or modes within a compact control.

UsageCodeAccessibility
DayWeekMonth
<sl-segmented-control aria-label="Timetable view" value="week">
  <sl-segmented-control-item value="day">
    <sl-icon name="far-calendar-day" slot="icon"></sl-icon>
    <sl-icon name="fas-calendar-day" slot="selected-icon"></sl-icon>
    Day
  </sl-segmented-control-item>
  <sl-segmented-control-item value="week">
    <sl-icon name="far-calendar-week" slot="icon"></sl-icon>
    <sl-icon name="fas-calendar-week" slot="selected-icon"></sl-icon>
    Week
  </sl-segmented-control-item>
  <sl-segmented-control-item value="month">
    <sl-icon name="far-calendar-days" slot="icon"></sl-icon>
    <sl-icon name="fas-calendar-days" slot="selected-icon"></sl-icon>
    Month
  </sl-segmented-control-item>
</sl-segmented-control>

Similar components

Segmented control has similar behaviour to 2 other components: Tabs and Toggle group. To ensure good user experience and accessibility it is important to choose the appropriate component for a given scenario.

Differences

  • Segmented control changes how the content is presented. One section is always active.
  • Tabs change which content is shown. One section is always active. Can be linked to.
  • Toggle group applies an action to content, or filters the content (chips variant). Any number of sections can be active, including none.

How to decide

Most important:

  • Does choosing an option show a type of content that wasn't on the page before? Yes → Tabs
  • Could a user want to select two of the options at once, or none at all? Yes → Toggle group (actions) / to be decided (filters)
  • Can the user apply different actions to content between options? Yes → Tabs

Also check:

  • Is each option an action being applied, rather than a value being chosen? Yes → Toggle group
  • Do you need a URL to a selected option? Yes → Tabs
  • Do you need more than 5 options? Yes → Tabs / Select

Use a segmented control only when all answers are no.

Comparison table

AspectTabsSegmented controlToggle group
What changesWhich content is shownHow the content is displayedWhat action is applied to the content
Selection modelAlways one option selectedAlways one option selectedOne, several or no options selected
"Nothing selected" valid?NoNoYes
Linkable / routableYesNoNo
Option countMany (with overflow)2–5, fixedSmall, fixed
Overflow handling"More" buttonAutomatically switches to SelectNone
ContentLabel, icon or bothLabel, icon or bothLabel, icon or both
Typical placementAbove the section it controlsAbove or beside the content it rendersToolbars, above the content it acts on

Anatomy

ItemNameDescriptionOptional
1ContainerHolds the controls.no
2ControlOne option. One control is selected at a time, and one is selected by default.no
3LabelShown in the icon + text and text only variants.yes
4IconShown in the icon + text and icon only variants.yes

Content

Sets what each control shows.

  • Icon + text (default): icon and label.
  • Text only: label only.
  • Icon only: icon only. Has a shorter selection indicator.

Emphasis

  • Subtle (default): the selected control has a short selection indicator under it.

  • Bold: use to put more visual emphasis on the component, when:

    • it's the page's main view switch,
    • it's the only segmented control on the screen,
    • it isn't placed under tabs, and
    • it isn't next to a primary button.

    Bold emphasis can be also used in applications targeting younger users.

Size

  • Medium (md) (default)
  • Large (lg): use in touch-first and child-facing products, and for a page's single main view switch in a spacious layout.

Width

  • Hug (default): width of each control is set by the control with longest content
  • Fill: component fills the width of its parent container. use to put more visual emphasis on the component, or to fit it better within page layout.

Shape

Visual treatment of the segmented control. Use the value that matches the context.

  • Rect (default)
  • Pill

Fill

Visual treatment of the segmented control. Use the value that matches the context.

  • Solid (default)
  • Outline

Number of controls

  • 2 to 5 controls. Controls 3, 4 and 5 can be turned on or off; all 5 are on by default.

Content guidelines

  • Use short, clear labels.
  • Keep labels to 1–2 words. They may be longer in other languages and break the layout.
  • Use the icon-only variant only when icons for the provided options are universally recognizable.
  • Replace with Select when there isn't enough horizontal space for a Segmented control.
  • Tabs: change which content is shown. Use for navigation, linkable options or a different subject.
  • Toggle group: applies actions to content. Any number of options can be active, including none.
  • Select: for more than 5 options, and the fallback when the segmented control doesn't fit.
  • Radio group: for a choice that is part of a form.
  • Switch: for a single on/off setting.
  • Combobox: for long option labels.