Segmented control
A Segmented control lets users switch between related views or modes within a compact control.
<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
| Aspect | Tabs | Segmented control | Toggle group |
|---|---|---|---|
| What changes | Which content is shown | How the content is displayed | What action is applied to the content |
| Selection model | Always one option selected | Always one option selected | One, several or no options selected |
| "Nothing selected" valid? | No | No | Yes |
| Linkable / routable | Yes | No | No |
| Option count | Many (with overflow) | 2–5, fixed | Small, fixed |
| Overflow handling | "More" button | Automatically switches to Select | None |
| Content | Label, icon or both | Label, icon or both | Label, icon or both |
| Typical placement | Above the section it controls | Above or beside the content it renders | Toolbars, above the content it acts on |
Anatomy
| Item | Name | Description | Optional |
|---|---|---|---|
| 1 | Container | Holds the controls. | no |
| 2 | Control | One option. One control is selected at a time, and one is selected by default. | no |
| 3 | Label | Shown in the icon + text and text only variants. | yes |
| 4 | Icon | Shown 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.
Related components
- 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.
<sl-segmented-control
aria-label="Class report"
emphasis="bold"
fill="outline"
shape="pill"
size="lg"
value="grades">
<sl-segmented-control-item value="overview">Overview</sl-segmented-control-item>
<sl-segmented-control-item value="grades">Grades</sl-segmented-control-item>
<sl-segmented-control-item value="attendance">Attendance</sl-segmented-control-item>
</sl-segmented-control>Segmented control item API
A single option in the segmented control. It can show a label, an icon or both. Use the icon and selected-icon slots to set the icons.
Properties
| Name | Attribute | Type | Default | Description |
|---|---|---|---|---|
ariaDisabledState | aria-disabled | string | undefined | Whether the option is aria-disabled. When set, the option stays focusable but is inactive (disabled). | |
value | value | string | The value of the option. |
Slots
| Name | Description |
|---|---|
default | The label of the option. |
icon | The icon shown before the label. |
selected-icon | The icon shown instead of the icon when the option is selected. |
Segmented control API
The segmented control is the wrapper for the options of one value. Only one option can be selected at a time. Use the properties to set the size, emphasis, fill, shape and so on.
Properties
| Name | Attribute | Type | Default | Description |
|---|---|---|---|---|
emphasis | emphasis | 'subtle' | 'bold' | 'subtle' | The emphasis of the selected option. |
fill | fill | 'outline' | 'solid' | 'solid' | The fill of the control. |
iconOnly | icon-only | boolean | false | Whether the segmented control should hide option labels and render only icons. |
shape | shape | 'pill' | 'rect' | 'rect' | The shape of the control. |
size | size | 'md' | 'lg' | 'md' | The size of the control. |
value | value | string | undefined | The value of the selected option. |
Methods
| Name | Parameters | Return | Description |
|---|---|---|---|
removeAttribute | name: string | void |
Events
| Name | Event type | Description |
|---|---|---|
sl-change | SlChangeEvent<string> | Emits when the selected option changes. |
Slots
| Name | Description |
|---|---|
default | The sl-segmented-control-item elements. |
CSS Parts
| Name | Description |
|---|---|
select | The sl-select that is shown when the options don't fit. Use it to change the width of the select, for example to let it fill the full width of the control. |
Keyboard interactions
Use Tab to move focus into or out of the control. Focus enters on the selected option, or the first option if none is selected. Use the left and right arrow keys to move between options; navigation wraps. Press Space or Enter to activate the focused option.
| Command | Description |
|---|---|
| Tab | Moves focus into the segmented control (to the first element, or selected element when one exists) and out of it. |
| Arrow Left | Moves focus to the previous focusable element in the segmented control. |
| Arrow Right | Moves focus to the next focusable element in the segmented control. |
| Home | Moves focus to the first item. |
| End | Moves focus to the last item. |
| Enter/Space | Activates the focused item. |
Keyboard interactions when options do not fit the screen
When the options don’t fit in the available space, the segmented control switches to a select. Detailed information about keyboard interactions for that component can be found in the select documentation.
WAI-ARIA
In the component itself we use multiple aria-attributes to assure the component works well with a range of assistive technologies. For some attributes however it is not possible for the Design System to add a meaningful value, because it relies on the context or way a component is used.
Attributes that we recommend you add in certain scenarios are mentioned below.
The component sets aria-current="true" on the selected option and aria-current="false" on the other options. This state is managed automatically; you don’t need to set aria-current yourself.
| Attribute | Value | Description |
|---|---|---|
aria-label | string | The aria-label can be added on the segmented control to describe its purpose. Individual button labels are provided with text. For icon only variants this text is not visible, but it's announced by screen readers. There is no need to add aria-label to buttons inside segmented control. |
aria-labelledby | string | Use aria-labelledby to name the segmented control by referencing an existing element, rather than providing a label string with aria-label. |
aria-disabled | boolean | Announces the segmented control item as disabled with a screen reader, prevents it from being selected and dims it while keeping it focusable. |