Skip to content

Toggle

Toggles are used to switch between two states, such as on/off or enabled/disabled. They are commonly used in settings, preferences, and other interactive elements. Click the interactive toggle preview below to test its state changes.

Loading Code Block...
Loading Code Block...
Loading Code Block...

Adjust the size prop to render the toggle as sm or md.

sm
md
Loading Code Block...

title is the primary label rendered next to the track. subtext adds supporting copy. titleBold (default true) controls emphasis on the title.

Loading Code Block...

Use alignment to place the toggle left or right of the label stack.

Loading Code Block...

Use stretch so the label row spans its container with space distributed between the toggle and the label (useful in settings rows). The prop has the same name and semantics in both frameworks.

Loading Code Block...

Set the disabled prop to prevent user interaction. The demo below demonstrates both unchecked and checked disabled states.

Loading Code Block...

Use the textLayout="horizontal" prop to render the title inline next to the toggle with the subtext on the far side. This is useful for compact settings rows where the toggle should sit alongside its label rather than below it.

Loading Code Block...

  • The component renders a real <input type="checkbox" class="sr-only"> inside the outer <label>, so AT picks up the input’s role and checked state natively. Clicking the label or hitting Space while it is focused toggles the input.
  • The title prop becomes the visible label text inside the same <label> element, associating the copy with the control without needing explicit for / id wiring.
  • The visible track and thumb are presentational; on-state and off-state are signalled both by the position of the thumb and by the track background colour.