HTML

Switch

Use a switch to toggle the state of a setting (between on and off). Switches and checkboxes can often be used interchangeably, but the switch provides a more explicit, visible representation on a setting. Related design guidelines: Data input

ExamplesDocumentationCSS Variables

Examples

Switch



Copied to clipboard

Switch no label

Copied to clipboard

Switch disabled



Copied to clipboard

Documentation

Overview

A Switch is an alternative to the checkbox component.

Use a switch when your user needs to perform instantaneous actions without confirmation.

Use checkbox if your user has to perform additional steps for changes to become effective.

Accessibility

Attribute Applied To Outcome
aria-labelledby="..." or aria-label="..." .pf-c-switch__input Indicates the action triggered by the switch. If an additional text label is included with the switch besides .pf-c-switch__label.pf-m-on, then aria-labelledby can reference the id of this text, or this text can be used as the value for aria-label. If the text included for .pf-c-switch__label.pf-m-on provides additional meaning to the primary label that's referenced, then it can also be represented as part of the aria-labelledby or aria-label attribute. Required
for <label> Each <label> must have a for attribute that matches its input id. Required
id <input type="checkbox"> Each <input> must have an id attribute that matches its label's for value. Required
id .pf-c-switch__label Each .pf-c-switch__label must have an id attribute that matches the aria-labelledby on .pf-c-switch__input.
checked .pf-c-switch__input Indicates that the input is checked
disabled .pf-c-switch__input Indicates that the input is disabled
aria-hidden="true" .pf-c-switch__label Hides the text from the screen reader.

Usage

Class Applied To Outcome
.pf-c-switch <label> Initiates a switch. Required
.pf-c-switch__input <input type="checkbox"> Hide the checkbox inside the switch. Required
.pf-c-switch__toggle <span> Initiates the toggle inside the switch. Required
.pf-c-switch__toggle-icon <i> Initiates an icon inside the switch toggle. Required when the switch is used without a label
.pf-c-switch__label <span> Initiates a label inside the switch.
.pf-m-on .pf-c-switch__label Modifies the switch label to display the on message.
.pf-m-off .pf-c-switch__label Modifies the switch label to display the off message.

CSS Variables

--pf-c-switch--Heightc_switch_Heightcalc(1rem * 1.5)
--pf-c-switch--LineHeightc_switch_LineHeight1.5
--pf-c-switch--Widthc_switch_Widthcalc(calc(1rem * 1.5) * 1.681)
--pf-c-switch__input--checked__label--Colorc_switch__input_checked__label_Color#151515
--pf-c-switch__input--checked__toggle--BackgroundColorc_switch__input_checked__toggle_BackgroundColor#06c
--pf-c-switch__input--checked__toggle--before--Transformc_switch__input_checked__toggle_before_TransformtranslateX(calc(calc(calc(1rem * 1.5) * 1.681) - calc(calc(1rem * 1.5) / 1.681) - 2 * calc(calc(1rem * 1.5) / 2 * (1 - 1 / 1.681))))
--pf-c-switch__input--disabled__label--Colorc_switch__input_disabled__label_Color#72767b
--pf-c-switch__input--disabled__toggle--BackgroundColorc_switch__input_disabled__toggle_BackgroundColor#72767b
--pf-c-switch__input--disabled__toggle--before--BackgroundColorc_switch__input_disabled__toggle_before_BackgroundColor#d2d2d2
--pf-c-switch__input--not-checked__label--Colorc_switch__input_not_checked__label_Color#72767b
--pf-c-switch__label--Colorc_switch__label_Color#151515
--pf-c-switch__label--FontSizec_switch__label_FontSize1rem
--pf-c-switch__label--FontWeightc_switch__label_FontWeight400
--pf-c-switch__label--LineHeightc_switch__label_LineHeight1.5
--pf-c-switch__label--PaddingLeftc_switch__label_PaddingLeft1rem
--pf-c-switch__toggle--BackgroundColorc_switch__toggle_BackgroundColor#d2d2d2
--pf-c-switch__toggle--BorderRadiusc_switch__toggle_BorderRadiuscalc(1rem * 1.5)
--pf-c-switch__toggle--before--BackgroundColorc_switch__toggle_before_BackgroundColor#fff
--pf-c-switch__toggle--before--BorderRadiusc_switch__toggle_before_BorderRadius30em
--pf-c-switch__toggle--before--BoxShadowc_switch__toggle_before_BoxShadow0 0.0625rem 0.0625rem 0rem rgba(3,3,3,.05),0 0.25rem 0.5rem 0.25rem rgba(3,3,3,.06)
--pf-c-switch__toggle--before--Heightc_switch__toggle_before_Heightcalc(calc(1rem * 1.5) / 1.681)
--pf-c-switch__toggle--before--Leftc_switch__toggle_before_Leftcalc(calc(1rem * 1.5) / 2 * (1 - 1 / 1.681))
--pf-c-switch__toggle--before--Topc_switch__toggle_before_Topcalc(calc(1rem * 1.5) / 2 * (1 - 1 / 1.681))
--pf-c-switch__toggle--before--Widthc_switch__toggle_before_Widthcalc(calc(1rem * 1.5) / 1.681)
--pf-c-switch__toggle-icon--Colorc_switch__toggle_icon_Color#fff
--pf-c-switch__toggle-icon--FontSizec_switch__toggle_icon_FontSize0.625rem
--pf-c-switch__toggle-icon--PaddingLeftc_switch__toggle_icon_PaddingLeft0.5rem
--pf-c-switch__toggle-icon--Topc_switch__toggle_icon_Top0.4375rem