The Toggle component renders a switch to toggle between enabled or disabled states.
Toggles and Checkboxes are both form controls that give the user the option to enable or disable a setting or feature. However, it's important to understand the difference between the two as they are not interchangeable:
Set Toggles to the default state that is safest or most common for the user. Avoid enabling destructive or data-sharing settings by default.
Toggles are available in three sizes: medium, small, and extra small. Use the size most appropriate to the given layout constraints.
Medium is the default size, used in the majority of contexts including settings pages and form layouts.
Small Toggles are used in tighter layouts such as table rows, inline controls, or condensed settings panels.
Extra small Toggles are used in the most space-constrained contexts.
The default unchecked and checked states. The unchecked track uses a neutral surface color, while the checked track uses the active accent color.
On mouse hover, the track background darkens to indicate interactivity.
On keyboard focus, the track receives the standard 2px focus ring.
Disabled Toggles cannot be interacted with. Both the track and thumb adopt muted colors to indicate the control is unavailable.
Labels are truncated with an ellipsis by default when they overflow the available space. Truncation can be disabled to allow the label to wrap to multiple lines. Be mindful as truncated text may be harder to read.
By default, long labels are clipped with an ellipsis.
When truncation is disabled, the label wraps to multiple lines.
When writing labels, it's best to phrase them in a way that makes it clear what will happen when the Toggle is turned on, not what is prevented when it's turned off. Labels should be self-explanatory without relying on surrounding context.
Descriptions provide extra context when the label alone doesn't fully explain the Toggle's effect. Keep descriptions to a short phrase without end punctuation.
Error messages communicate validation issues with the Toggle. Frame errors as an actionable step the user can take to resolve the issue.