Skip to content

ExpressiveCSS

Browse documentation

Switches

Material Design 3 switches, from the HTML.

View as Markdown

On this page

Wrap an <input type="checkbox"> in a <label class="switch">. Put the label text next to the input as a sibling. You do not need a .lever. Switches are CSS only, so there is no JavaScript component and nothing to AutoInit.

Tokens follow the M3 switch spec. The track is 52×32dp. Unselected is surface-container-highest with a 2dp outline and a 16dp handle. Selected is a primary track and a 24dp on-primary handle. The state layer is 40dp at 8% hover and 10% focus. The touch target is 48dp. The label is body-large / on-surface. Disabled is 38%.

<label class="switch">
  <input type="checkbox">
  Wi-Fi
</label>

<label class="switch">
  <input type="checkbox" checked>
  Bluetooth
</label>

<label class="switch">
  <input type="checkbox" disabled>
  Airplane mode
</label>

Hide on/off captions and name the control itself. The captions are decoration. Left as bare text, they become part of the label, and the switch announces itself as "Off On". A switch whose only text is a caption needs an aria-label, because hiding the captions leaves it with no name at all.

<label class="switch">
  <span aria-hidden="true">Off</span>
  <input type="checkbox" aria-label="Dark mode">
  <span aria-hidden="true">On</span>
</label>

No matching pages

  • Source color

    The seed every generated ramp derives from. Pick one and browse the docs — the whole theme follows. Error does not: it is a fixed hue.

    Default source: Mist Iris.

    ExpressiveCSS presets: Lagoon, Harbor, Breeze, Cobalt, Iris.

    Bold

    Soft

    Mist

    Glow