Forms

Switch

Utilize the switch component to toggle between two states (true or false) with a single click. The component comes in multiple sizes, variants, and colors.

Basic example

Default

Basic Switch example.

Type

Solid (Default)

For a switch style, apply the `switch` component class, whereas the default switch appearance is set to a solid color.

Outline

To achieve an outline style for the switch, add component class `switch-outline` alongside `switch`.

Color

Semantic color — Default switch

Example of semantic color in default and outline switch.

Semantic color — Outline switch

Outline switch with semantic-color using `switch-{semantic-color}` modifier class with component classes `switch` & `switch-outline`.

Custom color — Default switch

Example of custom color in default and outline switch.

Custom color — Outline switch

For `switch-outline`, use `--input-color` to set both the border and text color when the switch is checked. This eliminates the need to apply `checked:bg-*` and `checked:border-*` individually. You can still use `text-*` and `border-*` utilities to further customize the ball and border colors separately.

Size

Solid switch

Add responsive class `switch-{size}` where `{size} = xs|sm|md|lg|xl` for switch of different sizes.

Outline switch

Add responsive class `switch-{size}` where `{size} = xs|sm|md|lg|xl` for switch of different sizes.

Validation states

Success state

Success state can be show using `is-valid` class.

Error state

Error state can be show using `is-invalid` class.

Illustrations

Switch with icon

You can also add additional elements, such as icons.

Disabled

Disabled switch

Indeterminate

The `indeterminate` state can be configured using JavaScript. To gain further insight into this concept, you can explore more about it <a href="https://www.w3schools.com/jsref/prop_checkbox_indeterminate.asp" target="_blank" class="link link-primary">here</a>.

Inline switch group

A group of switch components in single line.

Vertical switch group

A vertical group of switch components.

Switch in dropdown

Here’s an example of a switch in dropdown.

Switch list group

This example can be used to show a list of switch inside a grouped list.

Switch to your preferred languages:

Horizontal list group

Use this example to group up switch components inside a list.

Switch to your preferred languages:
Class referenceThe component, style, color, state, size and modifier classes available for this component.
ClassTypeDescription
switchcomponentComponent class for switch.
label-textpartBase class for title label text.
helper-textpartBase class for helper label text.
switch-outlinestyleComponent class outline switch.
switch-primarycolorAdds 'primary' color to switch.
switch-secondarycolorAdds 'secondary' color to switch.
switch-accentcolorAdds 'accent' color to switch.
switch-infocolorAdds 'info' color to switch.
switch-successcolorAdds 'success' color to switch.
switch-warningcolorAdds 'warning' color to switch.
switch-errorcolorAdds 'error' color to switch.
is-validstateAdds success style to the input.
is-invalidstateAdds error style to the input.
switch-xssizeSwitch with extra small size.
switch-smsizeSwitch with small size.
switch-mdsizeSwitch with medium size.
switch-lgsizeSwitch with large size.
switch-xlsizeSwitch with extra large size.