Create

Form

Toggle

Copy page View as Markdown Open in ChatGPT Open in Claude

A two-state button that can be either on or off.

Usage#

app.component.ts
import { WdsToggleComponent } from '@wds/angular/toggle';

A toggle switches a setting of the content, like Bold in a toolbar. For a setting that takes effect like a form field use Switch or Checkbox; for a set of toggles use Toggle Group.

Examples#

Default#

A click switches pressed and fires wds-change. An icon-only toggle needs a label.

Outline#

variant="outline" adds a border.

With text#

An icon and text side by side.

Italic

Size#

size is sm, default or lg.

Small Default Large

Pressed#

pressed sets the initial state.

Saved

Disabled#

disabled turns the toggle off.

API References#

wds-toggle#

A two-state button that can be either on or off (aria-pressed), such as Bold in a text toolbar. In a wds-toggle-group the group decides which toggles are pressed and fires wds-change itself.

Attributes

AttributeTypeDefaultDescription
pressedbooleanfalseWhether the toggle is on.
disabledbooleanfalseDisables the toggle.
variantWdsToggleVariant'default'outline adds a border. In a group the group's variant wins.
sizeWdsToggleSize'default'Height: sm, default or lg. In a group the group's size wins.
labelstring | undefinedAccessible name (aria-label); required when the toggle shows only an icon.
valuestring''Value of the toggle in a wds-toggle-group.

Events

EventDescription
wds-changeCustomEvent<WdsTogglePressedChangeDetail>The user pressed or released the toggle.

Slots

SlotDescription
(default)Content: text and/or an <svg> icon.

CSS parts (::part)

PartDescription
buttonThe native <button>.

Accessibility#

Screen reader#

The toggle is a native button with aria-pressed, so screen readers announce it as a toggle button, pressed or not pressed.

Keep the label the same in both states (e.g. "Bold"); the state is announced separately. Name an icon-only toggle with label.

Keyboard support#

KeyFunction
TabMoves focus to the toggle.
SpacePresses or releases the toggle.
EnterPresses or releases the toggle.
Footer