Intro
The toggle button is a UI component that switches between two states: active and inactive.
Use the toggle button for secondary actions like showing or hiding a screen element or providing a filtered view of a dataset.
Toggle button
Component availability
The toggle button is available in the following libraries:
When to Use
Use the toggle button to:
- Switch between two states.
- Activate or deactivate an element in a toolbar.
Don’t use the toggle button to:
- Trigger an activity, flow, or process (such as Create, Edit, or Save). Use a button instead.
- Display a large number of options. Use a menu button instead.
- Use the standard toggle button for secondary actions.
- Use the transparent toggle button for tertiary actions.
- Always pair icon-only toggle buttons with a tooltip that labels them.
Anatomy
The toggle button component consists of the following elements:
- Background: Different background colors indicate the state of the toggle button.
- Text or icon: Describes or visualizes the action triggered by the toggle button.
Toggle button anatomy
Types
Display types
The toggle button supports three display types:
A: Text only
B: Icon only
C: Text and icon
Display types
Hierarchy types
The toggle button has two hierarchy types:
A. Standard: The standard toggle button appears with a white background and subtle gray border and is used for secondary actions.
B. Transparent: The transparent toggle button appears with a transparent background and no border and is used for tertiary actions.
Hierarchy types
States
Component states
The toggle button supports two component states: enabled and disabled. Each state can appear as untoggled or toggled.
A. Enabled: The toggle button is interactive, enabling the user to select it and trigger its associated action.
B. Disabled: The toggle button is not interactive and cannot be selected or triggered by the user.
Component states: enabled (A) and disabled (B)
For more information, see Component States.
Interaction states
The toggle button supports three interaction states: regular, hover, and down. Each state appears as untoggled or toggled.
Regular states
B. Regular toggled: Displays the selected state.
Regular states: untoggled (A) and toggled (B)
Hover states
B. Hover toggled: Displays a hover state when the cursor moves over an enabled, selected toggle button.
Hover states: untoggled on hover (A) and toggled on hover (B)
Down state
Down untoggled state
For more information, see Interaction States.
Focus state
The focus state indicates that the toggle button is focused and displays a visible focus highlight.
The focus state appears with an additional border.
When interaction begins, the focus state appears on the active toggle button.
Focused untoggled (A) and focused toggled (B) states
For more information, see Focus States.
Behavior and Interaction
Mouse interaction
Toggling a toggle button
Clicking an untoggled toggle button switches it to the toggled state.
A: The user starts pressing an untoggled toggle button.
B: When the user releases the toggle button, it toggles, triggers its action, and retains focus.
C: After the user moves the cursor away from the toggle button, it becomes regular toggled.
Toggling interaction
Untoggling a toggle button
Clicking a toggled toggle button switches it to the untoggled state.
Touch interaction
On touch devices, tapping the toggle button toggles its state. Hover and focus states are not supported.
Tooltips
When designing icon-only toggle buttons, always pair them with a tooltip that labels them.
Icon-only toggle button with tooltip
For more information, see Using Tooltips.
Responsiveness
By default, the toggle button expands and shrinks with the width of the text or icon.
Toggle button with different lengths
The toggle button supports cozy and compact content densities.
Compact (A) and cozy (B) content densities
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 Toggle Button component.
Screen reader support
For additional details on screen reader support and Accessible Rich Internet Applications (ARIA), see UI5 Screen Reader Support and WAI-ARIA Authoring.
Content
Localization
The toggle button supports left-to-right (LTR) and right-to-left (RTL) reading directions.
Toggle button – left-to-right
Toggle button – right-to-left
Framework Comparison
There are no differences between SAPUI5 and SAP Web Components regarding thе component's behaviors and framework-specific patterns.
Related Links
Guidelines
Components
Button
Implementation
SAPUI5
Toggle Button (samples)
Toggle Button (API reference)
SAP Web Components
Toggle Button
Guidelines
Components
Button
Implementation
SAPUI5
Toggle Button (samples)
Toggle Button (API reference)
SAP Web Components
Toggle Button
UI Kit (Figma)
SAP Fiori for Web UI Kit / Toggle Button