Toggle

A checkbox styled as a toggle button.

Usage

Use a Basecoat style bundle. No JavaScript is required. See Installation.

<label class="btn" data-variant="ghost">
  <input type="checkbox" name="toggle" value="italic" />
  <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 4h-9M14 20H5M15 4 9 20" /></svg>
  Italic
</label>

Put a checkbox directly inside a .btn label. Use data-variant="ghost" or data-variant="outline" and the existing Button data-size options. Use checked to start selected and disabled to prevent changes. The input keeps native checkbox semantics, keyboard activation, form submission, and reset behavior. Read its checked property or listen for the native change event.

Unlike upstream’s pressed button, this control is announced as a checkbox. In forced-colors mode, an inset outline identifies checked controls.

Examples

Outline

With Text

Size

Disabled

RTL