Toggle Switch

View in Lexicon

Toggle provide users with different selection and activation tools.

installyarn add @clayui/form
versionNPM Version
useimport {ClayToggle} from '@clayui/form';

Example

Snippet

Behavioral

You may want the Toggle Switch to behave with a Radio or Checkbox but have the appearance of a switch.

Checkbox

Snippet

Radio

Snippet

Disabled

Snippet

Composable

With Text

You can display additional text with the toggle switch by adding the .toggle-switch-text class to the text element. Use the .toggle-switch-text-left and .toggle-switch-text-right classes to position the text on the left and right side of the toggle switch, respectively.

Snippet

With Icons

Add <span className="button-icon button-icon-on icon-volume-up toggle-switch-icon"/> to add an icon to the switch for the on position.

Add <span className="button-icon button-icon-off icon-volume-off toggle-switch-icon"/> to add an icon to the switch for the off position.

Alternatively, you can add <span className="icon-ok toggle-switch-icon toggle-switch-icon-on"/> to add an icon to the switch for the on position.

Alternatively, you can add <span className="icon-remove toggle-switch-icon toggle-switch-icon-off"/> to add an icon to the switch for the off position.

Snippet

Extending Toggles

This section explains how to customize toggles. Use at your own risk.

explaining how switch works
  • Customize the toggle-switch button in the off position with .toggle-switch-check:empty ~ .toggle-switch-bar:after {} .
  • Customize the toggle-switch button icon in the off position with .toggle-switch-check:empty ~ .toggle-switch-bar .toggle-switch-icon.button-icon {} .
  • Customize the toggle-switch bar in the off position with .toggle-switch-check:empty ~ .toggle-switch-bar:before {} .
  • Customize the toggle-switch bar icon in the off position with .toggle-switch-check:empty ~ .toggle-switch-bar .toggle-switch-icon-off {} .
  • Customize the toggle-switch button in the on position with .toggle-switch-check:checked ~ .toggle-switch-bar:after {} .
  • Customize the toggle-switch button icon in the on position with .toggle-switch-check:checked ~ .toggle-switch-bar .toggle-switch-icon.button-icon.
  • Customize the toggle-switch bar in the on position with .toggle-switch-check:checked ~ .toggle-switch-bar:before {} .
  • Customize the toggle-switch bar icon in the on position with .toggle-switch-check:checked ~ .toggle-switch-bar .toggle-switch-icon-on {} .
Edit this page on GitHub

Contributors

Matuzalém Teles

Last edited May 12, 2025 at 7:56:02 PM