ComponentPorchlight CSS

Switch

CSS-only toggle switch built on a native checkbox. No JavaScript for the toggle.

51 components9 patterns46 stable5 experimental

Command

Search Porchlight

Switch

The .pl-c-switch is a toggle switch built on a native checkbox. The thumb slides via CSS transition on inset-inline-start. The :checked state drives the on/off styling. No JavaScript required for the toggle itself.

Semantic HTML

<label class="pl-c-switch">
  <input type="checkbox" role="switch" class="pl-c-switch__input" />
  <span class="pl-c-switch__track">
    <span class="pl-c-switch__thumb"></span>
  </span>
  <span class="pl-c-switch__label">Enable feature</span>
</label>

Accessibility

The native checkbox is visually hidden but accessible to assistive technology. The role="switch" attribute communicates the toggle semantics. Keyboard: Space toggles. Focus ring appears on the track.

RTL support

The thumb slides in the correct logical direction automatically because it uses inset-inline-start (not left), which flips under dir="rtl".

Class contract

Selector Role
.pl-c-switch Container label (flex row).
.pl-c-switch__input Visually hidden checkbox.
.pl-c-switch__track The pill background.
.pl-c-switch__thumb The sliding circle.
.pl-c-switch__label Text label.
[data-size] sm, default, lg.