Skip to content

Toggle Group

Coordinate single or multiple pressed controls. Custom element

Toggle Group
Copy this markup
<ui-toggle-group selection="single" orientation="horizontal" attached aria-label="Text alignment">
<button class="ui-button ui-toggle" type="button" value="left" aria-pressed="true">Left</button>
<button class="ui-button ui-toggle" type="button" value="center" aria-pressed="false">Center</button>
<button class="ui-button ui-toggle" type="button" value="right" aria-pressed="false">Right</button>
</ui-toggle-group>

Install

Styles and registration
import '@timelessui/components/css/tokens.css'
import '@timelessui/components/css/button.css'
import '@timelessui/components/css/toggle.css'
import '@timelessui/components/define/ui-toggle-group'

Anatomy

Parts are authored in your own markup and identified by the selector below, so your CSS can target the same anatomy without loading Timeless styles. Required parts must be present for the component to work. Private data-ui-internal-* hooks are written by the runtime and must never be authored.

<ui-toggle-group>

PartRequiredSelectorPurpose
itemYesbutton[aria-pressed]One toggle button. Author value and aria-pressed; Timeless keeps the pressed set in sync.

Attributes

Every value below is implemented by the stylesheets this component ships. Boolean attributes are presence-based: author the attribute with no value, or omit it.

<ui-toggle-group>

AttributeValuesDefaultDescription
attachedpresenceabsentPresent to join the buttons into one segmented control. Styling only, resolved by toggle.css.
orientationhorizontal · verticalhorizontalLayout and arrow-key axis.
selectionsingle · multiplesingleWhether pressing one button releases the others (single) or toggles independently (multiple).

ui-toggle

AttributeValuesDefaultDescription
data-ui-variantprimary · secondary · outline · ghost · danger · danger-outline · linkprimaryVisual intent, resolved by button.css. Author class="ui-button ui-toggle" so the shared button styling applies.
data-ui-sizesm · md · lgmdControl height, padding, and font size. Resolved by button.css.

Element API

Attributes above are the authoring surface. These are the DOM properties and events the registered element adds once it upgrades.

<ui-toggle-group>

PropertyTypeNotes
orientation'horizontal' | 'vertical'Reflects the orientation attribute, documented above.
selection'single' | 'multiple'Reflects the selection attribute, documented above.
EventDetailDescription
ui-before-changeCustomEvent<ToggleGroupChangeDetail>Cancelable proposal dispatched before the pressed set changes. Call preventDefault() to reject the transition and keep the current value.
ui-changeCustomEvent<ToggleGroupChangeDetail>Dispatched after the pressed set has changed. Bubbles and is composed.

State

Native attributes, ARIA, and platform pseudo-classes are authoritative. Style state through the selectors below rather than adding your own state classes.

StateSourceHow to express it
pressedariaAuthor aria-pressed="true" or "false"; never omit it.
disablednativeNative disabled.

Styling

Root identity: ui-toggle-group, ui-toggle. Required stylesheets: tokens.css, button.css, toggle.css.

This component adds no custom properties of its own. Restyle it through the design tokens or your own CSS.

Design tokens this component reads (24)

These are global Atmosphere tokens. Change them once at the theme level rather than per component.

--ui-accent · --ui-accent-soft · --ui-bg-accent · --ui-bg-accent-active · --ui-bg-accent-hover · --ui-bg-control · --ui-bg-control-active · --ui-bg-control-hover · --ui-bg-control-muted · --ui-bg-danger · --ui-bg-danger-active · --ui-bg-danger-hover · --ui-duration-fast · --ui-ease-standard · --ui-fg · --ui-focus · --ui-line · --ui-radius-control · --ui-shadow-control-accent · --ui-shadow-control-active · --ui-shadow-control-danger · --ui-shadow-control-hover · --ui-shadow-outline-control · --ui-space-2

Accessibility

Keep the native elements, roles, and relationships shown in the example. Timeless adds only the state and keyboard coordination the platform does not already provide, and it never supplies your accessible names — those depend on your content.

Follows the Button pattern from the ARIA Authoring Practices Guide.

KeyAction
Arrow keysMove focus to the previous or next button, following the orientation and skipping disabled ones.
Home / EndMove focus to the first or last enabled button.
Page Up / Page DownJump ten buttons at a time.

Each button keeps native activation, and aria-pressed carries the state. With selection="single" pressing one button releases the others.

Before JavaScript runs

The markup above is complete and usable on its own: native controls submit, labels associate, and authored ARIA is already correct. Registration adds state synchronisation, focus management, and keyboard coordination on top of it.

More examples

Open Toggle Group in StoryLite for variants, controls, and manual testing.