Skip to content
Nana UI

Switch

View .md Download

A form-associated on/off switch. Works inside a native <form>, supports keyboard toggling, and mirrors native checkbox semantics for submission.

Enable notifications
Terminal window
npm install @nana-tec/ui-components
import "@nana-tec/ui-components/switch";
<nana-switch>Enable notifications</nana-switch>
Small Medium Large
On Off Disabled on Disabled off

Properties

PropertyAttributeTypeDefaultDescription
checkedbooleanfalseOn/off state.
descriptionstring | undefinedSecondary descriptive text.
disabledbooleanfalseDisable the control.
labelstring | undefinedConvenience label text (slotted content wins).
namestring''Form field name.
requiredbooleanfalseMark as required for form validation.
sizeSwitchSize'md'Control size.
valuestring'on'Submitted value when checked (default "on").

Events

EventDescription
nana-changeFired on toggle (`detail.checked`).

Slots

SlotDescription
(default)The label (overrides the `label` attribute).
descriptionSecondary descriptive text.

CSS parts

PartDescription
::part(base)The clickable row.
::part(control)The track.
::part(thumb)The sliding thumb.
::part(label)The label text.

CSS custom properties

PropertyDescription
--nana-switch-accentChecked track colour.
--nana-switch-thumbThumb colour.
EventTypeDescription
nana-changeCustomEventFired on toggle (detail.checked).
SlotDescription
(default)The label (overrides the label attribute).
descriptionSecondary descriptive text.
VariableDefaultDescription
--nana-switch-accentChecked track colour.
--nana-switch-thumbThumb colour.
PartDescription
baseThe clickable row
controlThe track
thumbThe sliding thumb
labelThe label text
  • Keyboard accessible
  • Screen-reader labels
  • Focus-visible states
  • ARIA roles and states
  • WCAG 2.2 AA contrast
Explore Switch interactively Every state, prop, and edge case — with live controls — in Storybook.
View in Storybook