ClickorAltL

Dragto resize

Nord Design System SearchDeveloperDeveloperGetting startedUsing Web ComponentsWebfontsCDNLocalizationCSS Framework Legacy ESLint PluginWorking with AIFAQDesignDesignGetting startedFoundationsThemesBrand assetsToolsComponentsComponentsAccordion New Aside New Autocomplete New AvatarBadgeBanner Updated ButtonButton GroupCalendar Updated CardCheckbox Updated Collapsible New Combobox New Command MenuDate Picker Updated Date Range Picker New DividerDrawerDropdownEmpty StateField New FieldsetFilter Bar New FooterHeaderIconInput Updated Item New Kbd New LayoutMessageMeter New ModalNavigationNotificationNumber Field New Otp Field New Outline New Pagination New Popout Updated ProgressProgress BarQrcodeRadio Updated Range Updated Scroll Area New Segmented ControlSelect Updated SkeletonSpinnerStackTabTableTagTextarea Updated Time Picker New ToastToggle Updated TooltipTop BarTruncate New Visually HiddenDesign TokensDesign TokensTailwind CSSTailwind CSSBlocksBlocksTemplatesTemplatesIconsIconsPlaygroundPlaygroundLatest UpdatesLatest UpdatesChangelogChangelogMigration guidesMigration guides
GitHub

Toggle Updated

Open in Storybook

A switch control for turning a single setting on or off.

Loading...

Usage

A Toggle is a switch for an on/off setting that takes effect immediately, such as enabling a feature. Reach for a Checkbox instead when the choice is part of a list that is confirmed on submit.

Toggle is a compact control, so wrap it in a horizontal Field: set orientation="horizontal" on the Field and place a Field Label beside the switch. The Field owns the label, helper text and error. The toggle also renders its own built-in label/hint/error when used standalone; inside a Field those step aside automatically.

Copy code
import "@nordhealth/components/lib/Toggle"
import "@nordhealth/components/lib/Field"
import "@nordhealth/components/lib/FieldLabel"
import "@nordhealth/components/lib/FieldDescription"

Standalone or inside a Field

Use the control on its own with its built-in label, hint and error, or wrap it in a Field — the Field then provides the labelling. Both render the same control:

InlineWith Field

Examples

States

A toggle can be on (checked) or off.

Sizes

The size attribute accepts s, m (default) and l.

Reverse order

Use reverse to place the label before the switch, which works well in full-width settings rows.

Disabled

Use disabled to prevent interaction.

Hidden label

Use a visually hidden label when the surrounding context already names the toggle, keeping it available to assistive technology.

With a hint

Add a Field Description to explain what the toggle controls.

Error

Show validation with a Field Error and mark the Field invalid.

RTL

Toggles follow the document or container direction. Toggle the direction to see the switch and label mirror.

Accessibility

  • Always give the toggle an accessible name with a Field Label connected via for.
  • A toggle should take effect immediately. If the setting is only applied after submitting a form, prefer a Checkbox so the interaction matches user expectations.
  • Convey validation with a Field Error rather than colour alone — it is associated with the toggle and announced to assistive technology.
  • The toggle exposes a checkbox-style on/off state to assistive technology and is operable with the keyboard like any other form control.

API reference

Toggle

Toggle switch gives control over a feature or option that can be turned on or off. If a physical switch would work for the action, a toggle is probably the best component to use.

<nord-toggle></nord-toggle>

Props

PropertyAttribute Description TypeDefault
checkedcheckedControls whether the toggle is checked or not.booleanfalse
reversereverseControls whether the contents are displayed in reverse order, putting the label before the toggle.booleanfalse
sizesizeThe size of the toggle switch.'s' | 'm' | 'l''m'
placeholderplaceholderPlaceholder text to display within the control.string | undefined
requiredrequiredDetermines whether the control is required or not. A required control is announced as such to assistive technology and, inside a <nord-field>, drives the required indicator on the <nord-field-label>. When using this property you need to also set “novalidate” attribute on a form element to prevent browser from displaying its own validation errors.booleanfalse
disableddisabledMakes the component disabled. This prevents users from being able to interact with the component, and conveys its inactive state to assistive technologies.booleanfalse
namenameThe name of the form component.string | undefined
valuevalueThe value of the form component.string''
formformGets the form, if any, associated with the form element. The setter accepts a string, which is the id of the form.HTMLFormElement | null

Field properties

PropertyAttribute Description TypeDefault
labellabelLabel for the control. Ignored when the control is wrapped in a <nord-field>, which provides the label via <nord-field-label>.string''
hinthintOptional hint text shown with the control. Ignored inside a <nord-field>, which provides it via <nord-field-description>.string | undefined
hintBelowhint-belowRenders the hint below the control and any error instead of below the label.booleanfalse
hideLabelhide-labelVisually hide the label, but still expose it to assistive technologies.booleanfalse
errorerrorOptional error shown with the control. Ignored inside a <nord-field>, which provides it via <nord-field-error>.string | undefined
hideRequiredhide-requiredVisually hide the required indicator, but still expose the required state to assistive technologies.booleanfalse

Slots

Slot name Description
labelUse when a label requires more than plain text.
hintOptional slot that holds hint text for the input.
errorOptional slot that holds error text for the input.

Methods

Method nameParameters Description
focus(options?: FocusOptions) => voidoptions: An object which controls aspects of the focusing process.Programmatically move focus to the component.
blur() => voidN/AProgrammatically remove focus from the component.
click() => voidN/AProgrammatically simulates a click on the component.
EventDetail TypeDescription
inputNordEventFired as the user types into the input.
changeNordEventFired whenever the input's value is changed via user interaction.

CSS Properties

CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.

PropertyDescriptionDefault
--n-label-colorControls the text color of the label, using our color tokens.var(--n-color-text)
Design guidelinesFor designers

Usage

This section includes guidelines for designers and developers about the usage of this component in different contexts.

Do

  • Use toggles when your intent is to turn something on or off instantly.
  • Use for any feature or option that can be turned on or off.
  • If a physical switch would work for the action, the toggle is probably the best component to use.
  • Use for making it possible to choose one or more options from a limited number of options.

Don’t

  • Toggles should never require users to click a button to apply or save the setting.
  • Avoid using when you have more than 10 options to choose from.
  • Don’t change the selection of another toggle when another one is clicked. Only exception is when a toggle is used to make a bulk selection of multiple items.

Hint placement

Hint text is rendered above the control by default to preserve existing behavior for current consumers. Use the hint-below property to opt in to rendering the hint below the control and any error.

This is a non-breaking rollout for teams adopting the new layout gradually. Existing integrations keep the current placement unless hint-below is explicitly set.

Content guidelines

Toggle labels should be clear, accurate and predictable. It should be possible for the user to understand what they are selecting:

User settings
Option 1

When writing toggle labels, always write them in sentence case, not title case. The first word should be capitalized and the rest lowercase (unless a proper noun):

User settings
User Settings

Avoid ending in punctuation if it’s a single sentence, word, or a fragment:

Show dashboard
Show dashboard.

Do not use commas or semicolons at the end of each line

Patients
Patients;