A wider screen, please

This page features interactive demos and side-by-side code samples that need at least 340 pixels of horizontal space. Please widen your browser window, or rotate your device, to continue.

Morpheus v0.1.0
v0.1.0

Switch#

Component <neo-switch> is a two-state on/off control rendered as a sliding pill. Participates in a wrapping <label> like a native checkbox.

Default
States
Small size
Disabled
With label
Settings group
Deactivate Rename Duplicate
Delete
New state Toggle autoplay
HTML CSS

The selected state's markup and its scoped CSS. The CSS is wrapped in <style>@scope { ... }</style> and applies to the preview only. Edits change the preview above, applied live while Sync is on, or when you click Patch or Replace. Patch morphs the preview; Replace swaps it outright.

Replace Patch

Signals

Datastar signals declared in the selected state's markup. Change a value to drive the preview, applied live while Sync is on, or when you click Patch.

Patch

Reference#

Attributes #

NameTypeDefaultDescription
checkedboolean reflected observedfalseMirrored to aria-checked.
disabledboolean observedfalseNon-interactive state.
size"sm"noneCompact size. Omit for the default size.

Events #

NameDetailBubblesDescription
neo-switch-change{ checked: boolean }yesFires after a click or Space / Enter activation.

CSS variables #

NameDefaultDescription
--neo-switch-width2remTrack width. Drops to 1.5rem at size="sm".
--neo-switch-height1.15remTrack height. Drops to 0.875rem at size="sm".
--neo-switch-thumb-size1remThumb diameter. Drops to 0.75rem at size="sm".
--neo-switch-track-radius999pxTrack corner radius. Defaults to a pill.
--neo-switch-thumb-radius50%Thumb corner radius. Defaults to a circle.
--neo-switch-border-width1pxBorder width. Surfaced so the checked travel stays symmetric.
--neo-switch-track-offvar(--btn-border)Track color when unchecked.
--neo-switch-track-onvar(--accent)Track color when checked.
--neo-switch-thumbvar(--btn-bg)Thumb color.
--neo-switch-transition-durationcalc(150ms * var(--neo-duration-scale, 1))Duration of the track and thumb transitions.

Examples#

States#

Both states, each paired with a visible label via a wrapping <label>. Click the pill or the text, or focus with Tab and toggle with Space.

Small size#

The size="sm" variant has a 1.5rem × 0.875rem track and 0.75rem thumb, for dense rows where the default 2rem pill would dominate.

Disabled#

disabled blocks pointer events, drops the host from the tab order, and fades it to 50% opacity. Both states stay distinct so the value is still readable.

With label#

Wrapping a switch in a <label> makes the whole row clickable: the host forwards clicks on its closest <label> ancestor and moves focus to itself, keeping the keyboard target in sync.

Settings group#

A typical settings panel: each row is its own <label>, with the switch pinned to the right and the description on the left. The disabled row still shows its current value but resists interaction.

Settings

Theme

Default Sunshine Ocean Matrix Rose

Accessibility

Playgrounds

Server Simulator