Noctis

Switch

A toggle between two opposing on/off states. The thumb slides across the track when on and the track fills with the accent signal — the indigo reserved for active, checked controls.

Basic

Pair a Switch.Label with a Switch.Root inside a Switch.Field: the label becomes the accessible name, clicking it toggles the switch, and the whole row reads as one control. Switch.Root owns the checked state — drive it with checked / onCheckedChange, or omit them and pass defaultChecked to let it own its state.

In a settings row

Switches are most at home in settings lists, where each row is a labelled, immediate-effect toggle. The label sits at the inline start and the switch at the inline end, mirroring under RTL by construction.

Sizes

size sets the scale — sm for compact rows, md (the default), or lg. Setting it on Switch.Field scales the label text and cascades to the switch inside, so the label and control always read at the same weight; setting it on a standalone Switch.Root scales just the track and thumb.

In a form

Give Switch.Root a name (and an optional value, defaulting to "on") and it participates in form submission through a hidden input. Add required to demand it be on before the form submits.

Validation

A required switch that has not been turned on reads its error through the danger border. Reflect the state with aria-invalid and point aria-describedby at the error message so assistive tech announces it.

Read-only

readOnly keeps the switch legible and focusable but not editable — it drops the pointer and the hover affordance while staying at full opacity, since the value is valid, just not yours to change.

Disabled

disabled dims the switch and blocks interaction in either state, keeping the off/on rendering legible.

Keyboard

KeyAction
TabMove focus to the switch.
Shift + TabMove focus to the previous control.
SpaceToggle the switch between off and on.
EnterToggle the switch between off and on.

Anatomy

Compose the switch from its parts. Switch.Root is a Base UI Switch.Root, so the toggle behaviour, focus management, and the hidden form input come for free; Switch.Field is a Base UI Field.Root, which wires the label to the control.

  • Switch.Root — the track; owns the checked state (checked / onCheckedChange, or uncontrolled defaultChecked) and the shared size. Disable it with disabled, freeze it with readOnly, submit it with name / value, demand it with required; name a standalone switch with aria-label.
  • Switch.Thumb — the sliding knob inside the track. Its diameter re-points off the root's size through the cascade.
  • Switch.Field — the row that frames a label and a switch as one control; hugs its content by default, and a full-width row is w-full with a justify-between. Set size here to scale the label and the switch together.
  • Switch.Label — the visible label; clicking it toggles the switch and its text supplies the accessible name.

Every rendered part carries a data-slot (noctis-switch on the track, noctis-switch-thumb on the knob, noctis-switch-field on the row, noctis-switch-label on the label) for host-side styling — pair it with the Base UI state attributes (data-checked, data-unchecked, data-disabled, data-readonly, data-invalid).

On surfaces

The same control re-tuned across the elevation scopes — the root canvas, an elevated panel, a menu, and a sunken well. It stays legible on every layer.

root
elevated
menu
sunken

Design tokens

Generated from the component's declaration — the same graph that mints the CSS, so a variable name or its resolution default can't drift. The minted tokens are the public override seam: set one on any ancestor and every switch in that region retunes — e.g. .dense { --noctis-switch-block-size: 0.75rem; } shrinks the track beneath it. The checked and unchecked track colours flow from the accent and field roles, retuned by a retheme. See Customization for the full override ladder and Tokens for the whole graph.

Token

API reference

Generated from the component's types — every prop, type, default, and description comes straight from the source. Each part gets its own table; the Root forwards the Base UI Switch.Root props it owns its state through, and the Field forwards Base UI's Field.Root. Expand a row for the full type and description.

Switch.Root

Prop

Switch.Thumb

Prop

Switch.Field

Prop

Switch.Label

Prop

AttributeDescription
data-slotThe stable styling/testing hook on each rendered part.
data-checkedPresent on the track and thumb when the switch is on.
data-uncheckedPresent on the track and thumb when the switch is off.
data-disabledPresent when the switch is disabled.
data-readonlyPresent when the switch is read-only.
data-invalidPresent when the switch is in an invalid state (also honours `aria-invalid`).
data-sizeThe size axis, stamped on the track; the thumb diameter re-points off it.