Skip to content
Kimenpre-v1
Color scheme

Component

ki-switch

A token-styled switch for binary settings whose change takes effect immediately — always with a slotted label.

Email notifications
<ki-switch checked>Email notifications</ki-switch>
Off On Disabled
<ki-switch>Off</ki-switch>
<ki-switch checked>On</ki-switch>
<ki-switch disabled>Disabled</ki-switch>

The composed change event fires at the host; read checked from the target:

import type { KiSwitch } from '@kimen/elements/ki-switch';
const kiSwitch = document.querySelector('ki-switch');
kiSwitch?.addEventListener('change', (event) => {
console.log((event.target as KiSwitch).checked);
});

When to use: binary settings whose change takes effect immediately, always with a slotted label.

When not to use: selections collected for later form submission; use ki-checkbox for recorded choices, ki-radio-group for mutually exclusive choices, and ki-button for actions.

Properties & attributes

AttributePropertyTypeDefaultDescription
checkedcheckedbooleanfalseLive on/off state. Boolean presence semantics apply: any present checked attribute value, including checked="false" or malformed agent output, means on. Omit the attribute to express off. When to use: set the initial on state for a setting that applies immediately. When NOT to use: do not use a switch for choices saved only on submit; use ki-checkbox for that pattern.
disableddisabledbooleanfalsePrevents toggling, removes the switch from keyboard reach, excludes it from form data, and exposes the unavailable state to assistive technology. When to use: make a setting temporarily unavailable while preserving its current state. When NOT to use: do not use disabled for pending or loading states.
namenamestring | undefinedForm-data key contributed while the switch is on. When to use: include the immediate setting in native form data when on. When NOT to use: omit when no form entry should be submitted.
valuevaluestring | undefinedForm-data value submitted while on. Omit for native checkbox parity: the submitted value defaults to on. When to use: submit a domain-specific value instead of the default on. When NOT to use: do not set a value to represent off; off contributes nothing.

Slots

SlotDescription
(default)Label content. This is the accessible name source.

CSS parts

PartDescription
labelLabel wrapper around the default slot.
thumbTraveling handle.
trackOn/off channel.

CSS custom properties

The public styling contract of ki-switch: reassign these tokens at :root or on a subtree — never override internals.

TokenDescription
--ki-effect-small-dark-shadowMarsUI Small_dark_shadow: drop 0/2/3/-1.5 in Elevation/shadow_dark (Black/32 light, Black/48 dark). Lifts small light glyphs off saturated fills — the radio selected dot and the switch pointer carry it in the masters.
--ki-motion-duration-fastFast interaction transition duration.
--ki-motion-easing-outDecelerating interaction transition easing curve.
--ki-motion-easing-standardStandard interaction transition easing curve.
--ki-switch-border-widthdimension used by the switch component for border width (MarsUI tracks are borderless; the 1px hairline in ki.outline.control is the declared WCAG 1.4.11 deviation at half the former weight, so the control stops reading as an outlined pill).
--ki-switch-checked-active-bordercolor used by the switch component for checked active border.
--ki-switch-checked-active-thumbcolor used by the switch component for checked active thumb.
--ki-switch-checked-active-trackcolor used by the switch component for checked active track.
--ki-switch-checked-disabled-bordercolor used by the switch component for checked disabled border.
--ki-switch-checked-disabled-thumbcolor used by the switch component for checked disabled thumb (MarsUI pointer keeps its light construction in every state including disabled).
--ki-switch-checked-disabled-trackcolor used by the switch component for checked disabled track (MarsUI disabled track keeps the OFF rest fill surface/disabled_med_em; the disabled signal lives in the glyph in the master).
--ki-switch-checked-hover-bordercolor used by the switch component for checked hover border.
--ki-switch-checked-hover-thumbcolor used by the switch component for checked hover thumb.
--ki-switch-checked-hover-trackcolor used by the switch component for checked hover track.
--ki-switch-checked-rest-bordercolor used by the switch component for checked rest border.
--ki-switch-checked-rest-thumbcolor used by the switch component for checked rest thumb.
--ki-switch-checked-rest-trackcolor used by the switch component for checked rest track.
--ki-switch-focus-ring-colorcolor used by the switch component for focus ring color.
--ki-switch-focus-ring-offsetdimension used by the switch component for focus ring offset.
--ki-switch-focus-ring-shadowshadow used by the switch component for the focus ring glow (MarsUI Focus/primary: 3px spread ring at 20% — see ki.focus.primary. specs/002-ki-button/design-extraction.md §2.5 recorded 40%, having read the alpha off the Dark canvas mode, same double mechanism as ki-button: glow plus the opaque indicator).
--ki-switch-focus-ring-widthdimension used by the switch component for focus ring width.
--ki-switch-gapdimension used by the switch component for gap (MarsUI sm label pairing: Space/md 8px).
--ki-switch-glyph-dash-heightdimension used by the switch component for the disabled dash glyph block size (Figma pointer exports: 8x2 rounded dash).
--ki-switch-glyph-heightdimension used by the switch component for the thumb state glyph block size (Figma pointer exports: 4px check ink height).
--ki-switch-glyph-widthdimension used by the switch component for the thumb state glyph inline size (Figma pointer exports: 8px check/dash ink box inside the thumb).
--ki-switch-min-targetdimension used by the switch component for min target (MarsUI component frame is 28px tall for sm/md — the designed interactive footprint).
--ki-switch-thumb-insetdimension used by the switch component for thumb inset.
--ki-switch-thumb-radiusdimension used by the switch component for thumb radius (MarsUI pointer corner radius is half the height with corner smoothing; radius_round clamps to the smoothed pill).
--ki-switch-thumb-sizedimension used by the switch component for thumb size.
--ki-switch-thumb-widthdimension used by the switch component for thumb inline size (MarsUI md pointer is 22x18 — wider than tall; thumb-size remains the block size).
--ki-switch-track-heightdimension used by the switch component for track height.
--ki-switch-track-radiusdimension used by the switch component for track radius.
--ki-switch-track-widthdimension used by the switch component for track width.
--ki-switch-unchecked-active-bordercolor used by the switch component for unchecked active border.
--ki-switch-unchecked-active-thumbcolor used by the switch component for unchecked active thumb.
--ki-switch-unchecked-active-trackcolor used by the switch component for unchecked active track (one step beyond hover; the master defines no pressed variant).
--ki-switch-unchecked-disabled-bordercolor used by the switch component for unchecked disabled border.
--ki-switch-unchecked-disabled-thumbcolor used by the switch component for unchecked disabled thumb (MarsUI pointer keeps its light construction in every state including disabled).
--ki-switch-unchecked-disabled-trackcolor used by the switch component for unchecked disabled track (MarsUI disabled track keeps the OFF rest fill surface/disabled_med_em; the disabled signal lives in the glyph in the master).
--ki-switch-unchecked-hover-bordercolor used by the switch component for unchecked hover border.
--ki-switch-unchecked-hover-thumbcolor used by the switch component for unchecked hover thumb.
--ki-switch-unchecked-hover-trackcolor used by the switch component for unchecked hover track (Kimen-invented one-step ramp over the corrected rest fill; the master defines no hover variant).
--ki-switch-unchecked-rest-bordercolor used by the switch component for unchecked rest border.
--ki-switch-unchecked-rest-thumbcolor used by the switch component for unchecked rest thumb.
--ki-switch-unchecked-rest-trackcolor used by the switch component for unchecked rest track (MarsUI OFF track = surface/disabled_med_em #dddfe4 light / White-18 dark — a solid soft fill, not an outlined pill).
--ki-text-base-emsemantic color for text base em.
--ki-text-high-emsemantic color for text high em.
--ki-text-primary-on-primary-lightsemantic color for text primary on primary light.
--ki-typography-family-bodysemantic font family for typography family body.
--ki-typography-line-height-body-2semantic dimension for typography line height body 2.
--ki-typography-size-body-2semantic dimension for typography size body 2.
--ki-typography-weight-body-normalsemantic font weight for typography weight body normal.

The default slot is the accessible-name source — unlabeled usage is invalid. The thumb travel follows the writing direction in RTL, and the transition is gated behind prefers-reduced-motion. For selections collected for later form submission use ki-checkbox; for mutually exclusive choices use ki-radio-group.

Open ki-switch in Storybook