Switch
BetaFormsOpen in the workshop
A setting that takes effect the moment it is flipped.
.xg-switch > input[type=checkbox][role=switch] + textExample and markup
Live, from xg-ui.css and xg-ui.js. Switch the brand and mode on the example itself, or for the whole site in the header.
Markup
<div class="xg-stack" style="gap:12px">
<label class="xg-switch">
<input type="checkbox" role="switch" checked>Bid shading</label>
<label class="xg-switch">
<input type="checkbox" role="switch">Auto-pause on fraud share above 2%</label>
<label class="xg-switch">
<input type="checkbox" role="switch" disabled>Floor optimization (on request)</label>
</div>States
Hover, focus and pressed are forced here with .is-hover, .is-focus and .is-active so they can be seen side by side; in a product they come from :hover, :focus-visible and :active.
| State | Switch |
|---|---|
| Off | |
| On | |
| Disabled off | |
| Disabled on |
When to use it
Use it for
turning a feature on or off immediately: bid shading, auto-pause, email alerts.
Not for
choices inside a form that is saved later (Checkbox); pausing a live campaign (a Button with confirmation).
Rules
- The label names the setting, not the state (“Bid shading”, not “On”).
- If flipping it costs money or traffic, confirm first or show a toast with Undo.
Accessibility
- role="switch" on a native checkbox; state is read as on/off. Track uses primary-control: 3:1 on card.
Every color pair this component uses is measured for both brands in light and dark on the Accessibility page.
Related
Also in Forms: Input, Textarea, Select, Checkbox, Radio, Segmented control, Search field, Date-range picker, Form layout. Used in the patterns Onboarding and sign-up, Forms and overlays.
Status Beta: usable; class names may still change in a minor release, with a note (see Releasing).