Skip to content
Alpha

Hololink UI is under active development. Components, APIs and these docs may change without notice.

Holo Switch

The <holo-switch> component is a form-associated toggle control that exposes role="switch" semantics instead of checkbox semantics.

Use it for:

  • Turning a setting on or off with an immediate effect: “Dark mode”, “Email notifications”.
  • A single binary state where “on” and “off” are clear.

Don’t use it for:

  • Choices that apply only after a form is submitted. Use Checkbox.
  • Choosing among more than two options. Use Radio or Select.
  • Triggering an action. Use Button.
<holo-switch label="Enable notifications"></holo-switch> <holo-switch label="Enable notifications" checked></holo-switch>
<holo-switch label="Enable notifications" disabled></holo-switch>

The component renders a native <button type="button" role="switch"> with aria-checked, named by the label through aria-labelledby. Clicking the label text also toggles it. disabled is applied to the native button. The component is form-associated through ElementInternals: the value is submitted only while on, and required with the switch off reports “This field is required.”.

Key Action
Tab Moves focus to or from the switch
Space, Enter Toggles the switch
  • A visible focus ring is shown on the switch track with :focus-visible.
  • The track uses border-control so its boundary meets 3:1 against the surface. State is shown by the thumb position as well as colour.
  • The thumb transition only runs when prefers-reduced-motion: no-preference.

You provide:

  • A label. Without it the switch has no accessible name.
  • A label that stays the same whether the switch is on or off (“Notifications”, not “Turn notifications on”).

Importing

import '@philbob-sideprojects/hololink-ui/holo-switch';

Properties

PropertyAttributeTypeDefaultDescription
checkedcheckedbooleanfalseWhether the switch is on (checked).
disableddisabledbooleanfalseIf true, the switch is disabled and non-interactive.
labellabelstring—The visible label text for the switch.
namenamestring—The form field name submitted with the owning form.
requiredrequiredbooleanfalseIf true, the owning form cannot submit unless the switch is on.
valuevaluestring'on'The form value submitted when the switch is on.

Events

EventDetailDescription
holoChangebooleanEmitted when the on/off state changes.

CSS custom properties

PropertyDescription
--holo-switch-off-bgTrack color when off.
--holo-switch-on-bgTrack color when on.
--holo-switch-radiusCorner radius of the track.
--holo-switch-text-colorText color of the label.
--holo-switch-thumb-colorColor of the thumb.