Switch
ds-switch draws a switch around a native button: a pill two control heights
wide less 4px (28 × 16px), with a white round thumb 12px across, 2px in, travelling
12px. Off it is grey; on it is a darker green whatever the page’s
accent, so the white thumb stays clear in light and dark. There is one switch;
there is no square one. Its measures follow the shared scale and it keeps its
focus ring visible.
<code><span class="line"><span style="color:var(--docs-code-ink)"><</span><span style="color:var(--docs-code-tag)">ds-switch</span><span style="color:var(--docs-code-ink)">><</span><span style="color:var(--docs-code-tag)">button</span><span style="color:var(--docs-code-keyword)"> type</span><span style="color:var(--docs-code-ink)">=</span><span style="color:var(--docs-code-string)">"button"</span><span style="color:var(--docs-code-keyword)"> role</span><span style="color:var(--docs-code-ink)">=</span><span style="color:var(--docs-code-string)">"switch"</span><span style="color:var(--docs-code-keyword)"> aria-checked</span><span style="color:var(--docs-code-ink)">=</span><span style="color:var(--docs-code-string)">"false"</span><span style="color:var(--docs-code-keyword)"> aria-label</span><span style="color:var(--docs-code-ink)">=</span><span style="color:var(--docs-code-string)">"Sharing"</span><span style="color:var(--docs-code-ink)">></</span><span style="color:var(--docs-code-tag)">button</span><span style="color:var(--docs-code-ink)">></</span><span style="color:var(--docs-code-tag)">ds-switch</span><span style="color:var(--docs-code-ink)">></span></span></code>
The native button keeps activation for both Space and Enter, its label, ref and
disabled state, and never submits a form. Product state sets its aria-checked
value after a change is accepted.
Disabled and busy state are distinct: aria-busy announces work, while disabled blocks activation when the product requires it. Use aria-label when the switch has no visible text. In React, the product’s state drives the native button inside ds-switch:
<code><span class="line"><span style="color:var(--docs-code-ink)"><</span><span style="color:var(--docs-code-tag)">ds-switch</span><span style="color:var(--docs-code-ink)">></span></span><span class="line"><span style="color:var(--docs-code-ink)"> <</span><span style="color:var(--docs-code-tag)">button</span><span style="color:var(--docs-code-keyword)"> type=</span><span style="color:var(--docs-code-string)">"button"</span><span style="color:var(--docs-code-keyword)"> role=</span><span style="color:var(--docs-code-string)">"switch"</span><span style="color:var(--docs-code-keyword)"> aria-label=</span><span style="color:var(--docs-code-string)">"Sharing"</span><span style="color:var(--docs-code-keyword)"> aria-checked=</span><span style="color:var(--docs-code-ink)">{sharing} </span><span style="color:var(--docs-code-keyword)">disabled=</span><span style="color:var(--docs-code-ink)">{saving}</span></span><span class="line"><span style="color:var(--docs-code-keyword)"> onClick=</span><span style="color:var(--docs-code-ink)">{() </span><span style="color:var(--docs-code-keyword)">=></span><span style="color:var(--docs-code-tag)"> setSharing</span><span style="color:var(--docs-code-ink)">(</span><span style="color:var(--docs-code-keyword)">!</span><span style="color:var(--docs-code-ink)">sharing)} /></span></span><span class="line"><span style="color:var(--docs-code-ink)"></</span><span style="color:var(--docs-code-tag)">ds-switch</span><span style="color:var(--docs-code-ink)">></span></span></code>On Apple it is .toggleStyle(.ds1Switch) (the same pill).
Compact control panels
Section titled “Compact control panels”Use compact monochrome for a dense control panel: a 24 × 12px pill with an 8px thumb and 12px travel, inside a 40 × 20px native button. All measures follow the shared scale. On uses the text colour with a paper-colour thumb; off uses a quiet grey track. Focus and disabled states remain visible. Normal switches retain their 32 × 16px green face.
<code><span class="line"><span style="color:var(--docs-code-ink)"><</span><span style="color:var(--docs-code-tag)">ds-switch</span><span style="color:var(--docs-code-keyword)"> compact</span><span style="color:var(--docs-code-keyword)"> monochrome</span><span style="color:var(--docs-code-ink)">><</span><span style="color:var(--docs-code-tag)">button</span><span style="color:var(--docs-code-keyword)"> type</span><span style="color:var(--docs-code-ink)">=</span><span style="color:var(--docs-code-string)">"button"</span><span style="color:var(--docs-code-keyword)"> role</span><span style="color:var(--docs-code-ink)">=</span><span style="color:var(--docs-code-string)">"switch"</span><span style="color:var(--docs-code-keyword)"> aria-checked</span><span style="color:var(--docs-code-ink)">=</span><span style="color:var(--docs-code-string)">"true"</span><span style="color:var(--docs-code-keyword)"> aria-label</span><span style="color:var(--docs-code-ink)">=</span><span style="color:var(--docs-code-string)">"Spacing"</span><span style="color:var(--docs-code-ink)">></</span><span style="color:var(--docs-code-tag)">button</span><span style="color:var(--docs-code-ink)">></</span><span style="color:var(--docs-code-tag)">ds-switch</span><span style="color:var(--docs-code-ink)">></span></span></code>
Native platform switches retain their standard size and appearance.
Design examples
Section titled “Design examples”Switches remain aligned at the ends of their label rows.
<code data-source="html"><section class="specimen">
<ds-row class="line" ><ds-text literal class="grow">Remember my place</ds-text><ds-switch><button type="button" role="switch" aria-label="Remember my place" aria-checked="true"></button></ds-switch></ds-row><ds-row class="line" ><ds-text literal class="grow">Show annotations</ds-text><ds-switch><button type="button" role="switch" aria-label="Show annotations" aria-checked="false"></button></ds-switch></ds-row><ds-row class="line" ><ds-text literal class="grow">Use compact rows</ds-text><ds-switch><button type="button" role="switch" aria-label="Use compact rows" aria-checked="true"></button></ds-switch></ds-row>
</section>
<style>
.specimen { width: 100%; min-width: 0; --cell: calc(20px * var(--ds-sf, 1)); }
.specimen .line { width: 100%; }
.specimen .grow { flex: 1; min-width: 0; }
.specimen .muted { color: var(--ds-text-color-muted); }
.specimen .mono { --ds-typeface-regular: var(--ds-typeface-mono); font-variant-numeric: tabular-nums; }
.specimen .value { width: calc(4 * var(--cell)); text-align: right; }
.specimen .mark { display: inline-flex; align-items: flex-end; width: var(--cell); height: var(--ds-control-height); flex: 0 0 var(--cell); }
.specimen .columns { display: flex; flex-wrap: wrap; gap: var(--cell); }
.specimen .columns > * { min-width: 0; }
.specimen fieldset { border: 0; padding: 0; margin: 0; }
.specimen legend { padding: 0; }
.specimen label { display: flex; align-items: flex-end; gap: calc(var(--cell) / 2); min-height: var(--cell); }
.specimen ds-panel { height: calc(10 * var(--cell)); }
</style></code> Click or press Space to change the local setting. No settings are saved.
<code data-source="html"><label style="display:flex;align-items:center;gap:20px">Notifications <ds-switch><button type="button" role="switch" aria-label="Notifications" aria-checked="true"></button></ds-switch></label> <label style="display:flex;align-items:center;gap:20px">Unavailable <ds-switch><button type="button" role="switch" aria-label="Unavailable" aria-checked="false" disabled></button></ds-switch></label></code>
<code data-source="script">document.querySelectorAll('ds-toggle button').forEach(button => {
button.addEventListener('click', () => {
button.setAttribute('aria-checked', String(button.getAttribute('aria-checked') !== 'true'));
});
});</code> Its own tokens
Section titled “Its own tokens”--ds-switch-size (its height: two heights wide less 4px, the thumb and its travel following), --ds-switch-track-on and --ds-switch-track-off. They are unset by default: each face reads its token first and falls back to its own measure, so a page that sets none draws exactly as before. Lengths are unscaled pixels, multiplied by the surface scale (--ds-sf) where the component is drawn. Design system 1’s component editor sets them live for every page that links the base sheet; a page can also set them itself. The compact face keeps its own measures.