Skip to content
Theme
endue.ai

Components, Forms

Toggle

A switch that turns a setting on or off, for settings that apply the moment you press.

Name in code Toggle

A switch that turns something on or off. Use it only for settings that apply the moment you press.

When to use

Use a toggle when the change takes effect immediately, with no Save button.

Size Track
md (default) 40×22
sm 36×20

Appearance

  • Track: pill shaped. Off is control-off. On is primary.
  • Thumb: 16, or 14 at sm. Off is control-thumb (white). On is control-thumb-on.
  • When on, light shows an ink track with a white thumb, and dark shows a paper track with an ink thumb.
  • The label is 14px foreground. The description is 12px muted-foreground.
  • The switch button draws the focus ring.

What you provide

  • label: required. Name what it turns on, as a noun (“Email notifications”). In a row that already shows a description next to the switch, use hideLabel.
  • description (optional): one sentence that says what happens when it is on.

Markup

<label class="Toggle_toggle">
  <button type="button" role="switch" aria-checked="true" aria-label="Email notifications" class="Toggle_track" data-checked="true">
    <span class="Toggle_thumb" aria-hidden="true"></span>
  </button>
  <span class="Toggle_text">
    <span class="Toggle_label">Email notifications</span>
    <span class="Toggle_description">…</span>
  </span>
</label>

For the small size, add Toggle_sm to the root. For a disabled toggle, add data-disabled to the root and disabled to the button.

Don’t

  • Don’t use it for a form value that applies only after a Save button is pressed.
  • Don’t leave a switch without a name.