Intro
The switch is a UI component used to toggle a setting on or off with a button. It lets users turn individual features on or off to adjust display settings or personalize the application’s appearance.
Switch with label
Component availability
This component is available in the following libraries:
When to Use
Use the switch to:
- Set a setting as active or inactive (for example, in a dialog).
- Clearly show the current mode or state of a setting.
- Apply changes that take effect immediately.
Don't use the switch to:
- Allow selection of multiple options or require extra steps for changes to take effect.
- Show a state or action when it's unclear which one the component is displaying. Use a checkbox instead.
- Include text inside the switch component, as this can cause localization issues.
- Use a default switch when you need a simple on/off component with predefined icons and standard colors.
- Use a semantic switch when the action represents a positive or negative state.
- Add a descriptive label either above or directly before a switch component. This helps users understand which value or feature it controls.
- If the main label doesn't fully explain what "active" and "inactive" mean in your context, add a short text element (such as "On"/"Off" or status by using text or object status) next to the switch to clarify.
Anatomy
The switch consists of a background track and a movable handle.
- Track: Displays the container for the handle.
- Handle: Indicates whether the switch is on or off, depending on its position within the track.
Switch anatomy
Types
There are four switch types: default, semantic, switch with label, and switch with optional text. While switches don’t typically support value states, the semantic type uses color to add specific meaning to the on or off states.
Default switch
Default switch
Semantic switch
Switch with semantic colors
Switch with label
Switch with label
Switch with optional text
Switch with label and optional text
States
States define how components look and behave in different scenarios, helping users predict interaction outcomes.
Component states
The switch has two component states – enabled and disabled. When enabled, the switch is interactive and can be toggled. When disabled, the switch is not interactive and only displays its current value, either unselected (off) or selected (on).
A. Enabled state: The switch is interactive and the user can turn it on or off.
B. Disabled state: The switch is not interactive, but remains visible so the user can view its current state.
Enabled and disabled switch component states
For more information, see Component States.
Interaction states
The switch has two interaction states – regular and hover. The regular and hover interaction states are supported in both the on and off modes.
A: Regular state: The default state of the component.
B: Hover state: The state when the cursor is positioned over the switch.
Regular and hover switch interaction states
For more information, see Interaction States.
Focus state
The focus state indicates which component is currently in focus.
A: Unfocused state: The switch is not in focus and does not display a focus indicator.
B: Focused state: The switch displays an additional border around the track to indicate focus.
Unfocused and focused switch states
For more information, see Focus States.
Behavior and Interaction
The switch toggles between on and off when the user clicks or taps it. Visual feedback updates immediately to reflect the new state. The component supports interaction through mouse, touch, and keyboard.
Turning a switch on or off
A switch toggles between on and off states through user interaction. The component supports multiple interaction methods:
- Clicking: Single click toggles the state.
- Dragging: Hold and drag the handle to transition between states.
- Tapping (on touch devices): Tap to toggle the state.
When toggled, the switch updates its visual appearance with a new color, icon, and handle position. A focus indicator appears during keyboard or interaction focus.
Turning switch on
Note: Hover states are not supported on touch devices. For more information, see tap gesture and drag gesture.
Tooltips
Provide a tooltip when no label is available to give context for the switch. The label identifies what the switch controls and the effect of toggling it.
Switch with tooltip
Responsiveness
The switch does not adapt responsively, but it supports two content density modes depending on the device:
- Compact (mouse and keyboard input)
- Cozy (touch input)
Switch in compact and cozy modes
For more information, see Content Density.
Accessibility
SAP follows international standards, such as WCAG and WAI-ARIA, and strives to make our business solutions accessible and inclusive.
For more information, see Accessibility in SAP Fiori and the Accessibility Design Tools Handbook.
Keyboard navigation
The following keyboard combinations are supported by the SAPUI5 Switch component.
Screen reader support
For additional details on screen reader support and Accessible Rich Internet Applications (ARIA), see the UI5 Screen Reader Support and WAI-ARIA Authoring.
Content
Localization
The switch component supports both left-to-right (LTR) and right-to-left (RTL) reading directions.
Switch in left-to-right mode
Switch in right-to-left mode
Wrapping and Truncation
By default, label text wraps automatically. Use truncation only when space is limited. Apply a hybrid approach when needed: allow the label to wrap for up to N lines, then truncate any remaining text. Keep labels concise, and reserve truncation for edge cases when no other option is available.
For more information, see Wrapping & Truncation.
Label on top
For top labels, when the text wraps, the switch is pushed down by the additional lines. The number of wrapped lines depends on the label’s length.
Switch with top label wrapping
Label and optional text
By default, the optional text wraps. Avoid truncation and keep both the label and optional text short and concise.
Switch with wrapping and truncation of optional text
Label to the side
When a side label cannot fit horizontally, the switch moves below the label. The text wraps by default.
Switch with side label repositioning
Framework Comparison Overview
There are no differences between SAPUI5 and SAP Web Components regarding thе component's behaviors and framework-specific patterns.
Related Links
Guidelines
Components
Select
Radio Button
Checkbox
UI Kit (Figma)
SAP Fiori for Web UI Kit / Switch