Soracom

Design System
  1. Home
  2. Design system
  3. Elements
  4. Switch

Switch

Overview

  1. Make sure switches take effect immediately and do not require clicking a Save button
Never
  1. Never use a switch if the user needs to click a Save button to save the change – use a ds-radio or ds-checkbox instead

Options

Basic usage

Toggle switch

The preferred structure is to use a label element as the container for a switch.

Never

A toggle switch should only be used to enable or disable a specific option (eg. Enable feature X), it should not be used to choose between two options (eg. Enable feature X OR Enable feature Y).

Example using html <label> container

html
Copy

Alternatively, you can use a div element as the container for a switch, but if possible use the label structure above.

Example using html <div> container

html
Copy

Multiple switch

Multiple switch components use a slightly different structure and html radio inputs.

1. Make sure one input has a default checked state
html
Copy

Hide label

The switch text can be hidden using --hide-label

1. Always include a text description in the switch
html
Copy

When using using --hide-label on a multiple switch, always use icons to indicate what the options do.

html
Copy

Tip Position

By adding the appropriate --tip-* class, the position of the tip can be changed.

html
Copy

The following positions are available - (hover over labels to view examples):

--tip-top-left
--tip-top
--tip-top-right
--tip-left-top
--tip-right-top
--tip-left
default (top)
--tip-right
--tip-left-bottom
--tip-right-bottom
--tip-bottom-left
--tip-bottom
--tip-bottom-right

Size

Small

html
Copy
html
Copy

Icons

Toggle switch icons

Add an icon class to the container ds-switch element to set an icon for both on/off states

html
Copy

Add an icon class to the input element to set an icon for just the on state

html
Copy

Add an icon class to the container ds-switch element and to the input to set different icons for on/off states

html
Copy

Multiple switch icons

Add an icon class to the container ds-switch element to set an icon for all switches in both on/off states

html
Copy

Add an icon class to the label element to set an icon for a switch in both on/off states

html
Copy

Add an icon class to the input element to set an icon for just the on state

html
Copy

Add an icon class to the label element and to the input to set different icons for on/off states

html
Copy

Add an icon class to the container ds-switch, label and input elements to a default icon and different icons for on/off states

html
Copy

Left and Right labels

If the switch contains more than one div element, the first will be displayed before the switch.

html
Copy

Left label

If the switch contains only one div element, you can force the label to the left by using the --left-label class

html
Copy

Styles

Theme style

Theme style has slightly different default coloring used to indicate dark/light mode

html
Copy

Tests

Div structure with hide-label

Example using html <div> container

html
Copy

Div structure with Left and Right labels

Example using html <div> container

html
Copy

Div structure with left-label

Example using html <div> container

html
Copy