HomeGetting StartedColor SystemTypographySpacingIconographyLayoutInstallationUsageAngularBlazorReactSvelteVueThemingTypographyCustomizationCSS-Only ComponentsFormsIconsIllustrationsAccessibilityGlobal ConfigurationTailwind CSSSass LibraryForge MCP ServerDropdown OptionsFocus Indicator ClippingAll componentsButtonButton AreaChipFloating Action ButtonIcon ButtonSplit ButtonAutocompleteButton ToggleCalendarCheckboxChip FieldColor PickerDate PickerDate Range PickerFile PickerLabelRadioSelectSliderSwitchText FieldTime PickerApp BarApp LauncherDrawerMenuPaginatorSkip LinkStepperTabsView SwitcherAccordionApp LayoutCardDividerExpansion PanelScaffoldSplit ViewStackStructured CardToolbarBadgeBannerBusy IndicatorCircular ProgressDialogInline MessageLinear ProgressPage StateSkeletonToastTooltipAvatarIconKeyLabel ValueListMeterSecretTableTimelineTimestampTreeKeyboard ShortcutPopoverIntroductionColorTypographySpacingShapeBorderElevationLayeringAnimationUsageIcon LibraryBlocksRoadmapChangelogBlog

Switch

Switches toggle the state of a single setting on or off.

EnabledDisabled

Overview

Switches are selection controls that allow users to toggle a single setting between two states: on/off, show/hide, etc. They appear as a sliding toggle with a marker that moves between positions to indicate the current state.

Switches provide immediate feedback and typically take effect instantly when toggled, making them ideal for settings that users want to control in real-time without requiring form submission.

Usage

forge-switch toggles a single, independent setting on or off through checked, participates natively in form submission and validation (required, readonly, name, value), and supports dense, icon, and label-position. It’s the third of three selection controls: reach for a checkbox instead when a user can select zero, one, or many options from a list, or a radio button instead when exactly one option in a visible set must be chosen.

Rules

Do
Use clear, non-neutral labels that describe what the control will do when the switch is on.Match label text to switch state so turning the switch on activates the labeled feature, and turning it off deactivates it.Use a switch for a setting that takes effect immediately, with no separate submit step.Write a label that describes what happens when the switch is on — say it aloud with "on/off" appended and it should make sense.Keep each switch independent of every other control on the screen.
Don't
Don't use a switch for an action that needs review or confirmation, like Save or Submit — use a button instead.Don't use a switch for a setting with a neutral or indeterminate state — use a checkbox instead.Don't use a switch for two opposing options, like list view vs. map view — use a button toggle instead.Don't nest switches — use checkboxes instead so a parent control can show an indeterminate state.

Label position

Set label-position to control whether the label sits before or after the switch.

label-position controls whether the label sits before or after the switch.

Dense

Set dense to reduce the switch’s size.

Dense reduces the switch's size.

Icons

Pass custom icons through the icon-on and icon-off slots.

Custom icons passed through the icon-on and icon-off slots.

Disabled and readonly

disabled excludes the switch from the form; readonly keeps it in the form but locks its value.

Disabled excludes the switch from the form; readonly keeps it in the form but locks its value.

Switches toggle the state of a single setting on or off.

import "@tylertech/forge/switch";
Properties
PropertyAttributeTypeDefaultDescription
checkedcheckedbooleanfalseGets/sets whether the switch is checked or not.
ononbooleanfalseAlias for `checked` _(deprecated)_. Gets/sets whether the switch is checked or not.
selectedselectedbooleanfalseAlias for `checked` _(deprecated)_.
defaultCheckeddefault-checkedbooleanfalseGets/sets whether the switch is checked by default.
defaultOndefault-onbooleanfalseAlias for `defaultChecked` _(deprecated)_. Gets/sets whether the switch is checked by default.
valuevaluestring'on'Gets/sets the value of the switch.
densedensebooleanfalseControls whether the switch is dense.
disableddisabledbooleanfalseControls whether the switch is disabled.
requiredrequiredbooleanfalseControls whether the switch is required.
readonlyreadonlybooleanfalseControls whether the switch is readonly.
iconiconSwitchIconVisibility'both'Controls the presence of the off and on icons.
labelPositionlabel-positionSwitchLabelPosition'end'Controls whether the label appears before or after the switch.
Events
NameTypeDescription
changeEventDispatches when the switch's value changes.
forge-switch-changeCustomEvent<boolean>Dispatches when the switch's value changes.
CSS Parts
NameDescription
::part(switch)Styles the switch container element.
::part(track)Styles the track element.
::part(handle)Styles the handle element.
::part(icon-on)Styles the on icon element.
::part(icon-off)Styles the off icon element.
::part(label)Styles the label element.
::part(state-layer)Styles the state layer root element.
::part(focus-indicator)Styles the focus indicator root element.
CSS Custom Properties
NameDescription
--forge-theme-primaryThe primary color of the switch.
--forge-theme-on-primaryThe color of elements placed on top of the primary color (the handle icons for example).
--forge-switch-handle-on-colorThe color of the handle in the switch's on state.
--forge-switch-handle-off-colorThe color of the handle in the switch's off state.
--forge-switch-handle-active-on-colorThe color of the handle when the switch is active (pressed) in its on state.
--forge-switch-handle-active-off-colorThe color of the handle when the switch is active (pressed) in its off state.
--forge-switch-handle-sizeThe inline and block size of the handle.
--forge-switch-handle-widthThe inline size of the handle.
--forge-switch-handle-heightThe block size of the handle.
--forge-switch-handle-scaleThe scale transformation applied to the handle.
--forge-switch-handle-on-scaleThe scale transformation applied to the handle in the switch's on state.
--forge-switch-handle-off-scaleThe scale transformation applied to the handle in the switch's off state.
--forge-switch-handle-active-scaleThe scale transformation applied to the handle when the switch is active (pressed).
--forge-switch-handle-active-on-scaleThe scale transformation applied to the handle when the switch is active (pressed) in its on state.
--forge-switch-handle-active-off-scaleThe scale transformation applied to the handle when the switch is active (pressed) in its off state.
--forge-switch-handle-shapeThe shape of the handle.
--forge-switch-handle-elevationThe handle's shadow.
--forge-switch-handle-on-elevationThe handle's shadow in the switch's on state.
--forge-switch-handle-off-elevationThe handle's shadow in the switch's off state.
--forge-switch-handle-active-elevationThe handle's shadow when the switch is active (pressed).
--forge-switch-handle-active-on-elevationThe handle's shadow when the switch is active (pressed) in its on state.
--forge-switch-handle-active-off-elevationThe handle's shadow when the switch is active (pressed) in its off state.
--forge-switch-track-on-colorThe color of the track in the switch's on state.
--forge-switch-track-off-colorThe color fo the track in the switch's off state.
--forge-switch-track-active-on-colorThe color of the track when the switch is active (pressed) in its on state.
--forge-switch-track-active-off-colorThe color fo the track when the switch is active (pressed) in its off state.
--forge-switch-track-widthThe inline size of the track.
--forge-switch-track-heightThe block size of the track.
--forge-switch-track-shapeThe shape of the track.
--forge-switch-track-border-widthThe width of the track border.
--forge-switch-track-on-border-widthThe width of the track border in the switch's on state.
--forge-switch-track-off-border-widthThe width of the track border in the switch's off state.
--forge-switch-track-active-on-border-widthThe width of the track border when the switch is active (pressed) in its on state.
--forge-switch-track-active-off-border-widthThe width of the track border when the switch is active (pressed) in its off state.
--forge-switch-track-border-colorThe color of the track border.
--forge-switch-track-on-border-colorThe color of the track border in the switch's on state.
--forge-switch-track-off-border-colorThe color of the track border in the switch's off state.
--forge-switch-track-active-on-border-colorThe color of the track border when the switch is active (pressed) in its on state.
--forge-switch-track-active-off-border-colorThe color of the track border when the switch is active (pressed) in its off state.
--forge-switch-icon-colorThe color of the handle icons.
--forge-switch-icon-on-colorThe color of the handle icon in the switch's on state.
--forge-switch-icon-off-colorThe color of the handle icon in the switch's off state.
--forge-switch-icon-active-on-colorThe color of the handle icon when the switch is active (pressed) in its on state.
--forge-switch-icon-active-off-colorThe color of the handle icon when the switch is active (pressed) in its off state.
--forge-switch-icon-sizeThe size of the handle icon.
--forge-switch-icon-on-sizeThe size of the handle icon in the switch's on state.
--forge-switch-icon-off-sizeThe size of the handle icon in the switch's off state.
--forge-switch-icon-scaleThe scale transformation applied to the handle icons.
--forge-switch-icon-on-scaleThe scale transformation applied to the handle icons in the switch's on state.
--forge-switch-icon-off-scaleThe scale transformation applied to the handle icons in the switch's off state.
--forge-switch-icon-active-on-scaleThe scale transformation applied to the handle icons when the switch is active (pressed) in its on state.
--forge-switch-icon-active-off-scaleThe scale transformation applied to the handle icons when the switch is active (pressed) in its off state.
--forge-switch-gapThe space between the switch and label.
--forge-switch-justifyHow the switch and label are distributed along their main axis.
--forge-switch-alignHow the switch and label are distributed along their cross axis.
--forge-switch-directionWhether the switch and label are arranged along the inline or block axis.
--forge-switch-state-layer-sizeThe inline and block size of the handle's state layer.
--forge-switch-state-layer-widthThe inline size of the handle's state layer.
--forge-switch-state-layer-heightThe block size of the handle's state layer.
--forge-switch-state-layer-on-colorThe color of the handle's state layer when the switch is in its on state.
--forge-switch-state-layer-off-colorThe color of the handle's state layer when the switch is in its off state.
--forge-switch-state-layer-dense-sizeThe inline and block size of the handle's state layer when the dense switch is used.
--forge-switch-state-layer-dense-widthThe inline size of the handle's state layer when the dense switch is used.
--forge-switch-state-layer-dense-heightThe block size of the handle's state layer when the dense switch is used.
--forge-switch-disabled-opacityThe opacity of the switch when disabled.
--forge-switch-animation-durationThe duration of animations.
--forge-switch-animation-timingThe timing function used in most animations.
--forge-switch-active-animation-timingThe timing function used in active state animations.
Methods
NameReturnsDescription
toggle(force)voidToggles the switch on or off.

Keyboard interaction

Ensure the switch is reachable by the tab key and can be toggled with the keyboard, not just a pointer.

Screen reader behavior

The switch automatically applies role="switch" and aria-checked to the input, so assistive technology announces its state without any extra wiring.

Loading Forge chat…