Components
Segmented control
Mutually exclusive choices. The current segment carries aria-pressed=true, aria-current or aria-selected=true.
Live example
Rendered with the real classes from /site/chitransit.css, light (left) and dark (right).
.ct-segmented [aria-pressed].ct-segmented--fillCode
<div class="ct-segmented" role="group" aria-label="Theme"><button aria-pressed="true">System</button><button aria-pressed="false">Light</button><button aria-pressed="false">Dark</button></div>
<div class="ct-segmented ct-segmented--fill" style="--count:2" role="group" aria-label="Time display"><button aria-pressed="true">Minutes</button><button aria-pressed="false">Arrival time</button></div>
Tokens
From tokens/components.tokens.json. Override one instance by setting the property without the ct- prefix.
| Custom property | Value | Alias |
|---|---|---|
--ct-segmented-background | var(--card-2) | {colors.card2} |
--ct-segmented-background-selected | var(--paper) | {colors.paper} |
--ct-segmented-color | var(--muted) | {colors.muted} |
--ct-segmented-color-selected | var(--ink) | {colors.ink} |
--ct-segmented-font-size | var(--fs-sub) | {type.sub} |
--ct-segmented-font-weight | var(--weight-medium) | {weight.medium} |
--ct-segmented-font-weight-selected | var(--weight-semibold) | {weight.semibold} |
--ct-segmented-gap | var(--space-2) | {space.s2} |
--ct-segmented-height | 36px | |
--ct-segmented-padding | var(--space-2) | {space.s2} |
--ct-segmented-radius | var(--r-control) | {radius.control} |
--ct-segmented-segment-padding-x | var(--space-12) | {space.s12} |
--ct-segmented-segment-radius | var(--radius-segment) | {radius.segment} |
--ct-segmented-shadow-selected | var(--shadow-control) | {shadows.control} |
Usage
Do
- Use for two to four mutually exclusive choices, such as the theme switch.
- Use
--fillwhen the control spans its container.
Don't
- Don't use for more than four options or for actions.
Accessibility
- Wrap the buttons in
role="group"with anaria-label. - The current segment carries
aria-pressed="true"(oraria-currentfor navigation).