CenturyLink
Lumen
Lumen Enterprise Portal
  • Getting Started
    • Introduction
    • Installation
    • Development workflow
    • Browser support
    • What's new
  • Foundations
      • Overview
      • Using the keyboard
      • Page structure
      • Color and sensory
      • Images
      • Text
      • Links and forms
      • Tables
      • Other
      • Color
      • Design tokens
      • Grid
  • Components
    • Accordion
    • Activity
    • Alert
    • Avatar
    • Badge
    • Brand
    • Breadcrumb
    • Button
    • Button group
    • Cache Loader
    • Card
    • Carousel
    • Checkbox
    • Copy text
    • Data table
    • Date picker
    • Divider
    • Drawer
    • Dropdown
    • Expansion panel
    • File input
    • Flag icon
    • Footer
    • Header
    • Icon
    • Label
    • Link
    • Marketing icon
    • Mobile navigation
    • Modal
    • Number input
    • Pagination
    • Phone Input
    • Picker
    • Picker group
    • Popover
    • Price
    • Progress
    • Radio button
    • Range slider
    • Search input
    • Select
    • Sidenav
    • Skeleton
    • Spinner
    • Stat
    • Steps
    • Table
    • Tabs
    • Tags
    • Text input
    • Textarea
    • Time picker
    • Toggle switch
    • Toolbar
    • Tooltip
    • Transfer list
  • Utilities
    • Border
    • Color
    • Display
    • Flex
    • Image
    • Opacity
    • Overflow
    • Position
    • Shadow
    • Sizing
    • Spacing
    • Text
    • Vertical-align
    • Z-index
  • Templates
    • App Layout
    • Card
    • Error 404
    • Error 500
    • State

Toggle switch

Toggle switches are used to switch between two possible states.
  • Examples
  • Properties
  • Accessibility
Loading...

Web Component

Accessibility

Keyboard Navigation

KeyFunction
TabMoves keyboard focus to the switch.
Space,EnterChanges state of the switch to checked or not checked.

For comprehensive details on keyboard support for toggle switch, refer to our Keyboard Control Guide.

Visit WebAIM for keyboard techniques.

Guidance for developers
  • Ensure each toggle switch is accompanied by a label. Use the aria-labelledby attribute on the toggle switch that matches the id of the label element. This is crucial for screen reader users to understand the purpose of the switch.
  • Use aria-checked to indicate whether the toggle switch is in the "on" or "off" state. This attribute should dynamically change as the toggle state changes to keep assistive technologies informed.
  • Toggles should be operable using keyboard alone. Ensure that users can tab to the toggle switch and change its state using keyboard keys like Space or Enter.
  • Implement the toggle using a button element assigned with a role="switch". This approach ensures that the element is recognized correctly by assistive technologies.
Guidance for designers
  • Ensure that the toggle switch includes non-color visual indicators (e.g., text labels or distinctive shapes) to convey its state. This helps users with color vision deficiencies.
  • According to WCAG Success Criterion 3.2.2 (On Input), avoid designs where flipping a switch causes immediate changes in context or navigation. If such changes are necessary, provide clear warnings before the switch is used, or offer a way to undo the change.
  • Maintain high contrast ratios for all textual and graphical elements of the toggle switch to ensure legibility and visibility under various lighting conditions.
  • Ensure that toggle switches are large enough to be easily manipulated by users with limited dexterity, and spaced sufficiently to prevent accidental activation.

Find live examples in the A11y Style Guide.

Roles and attributes

The following list provides essential roles and attributes you should consider to ensure our components are fully accessible across various interface scenarios.

AttributeElementUsage
aria-labeldivDefines a string value that labels an interactive element. It is required props for controls without text content.
aria-labelledbydivThe aria-labelledby attribute identifies the element (or elements) that labels the element it is applied to. It is required props for controls without text content.

Resources

  • W3 Switch Example: Contains comprehensive details regarding the accessibility behavior of the switch .
  • Mozilla Resources for Developers: Find examples of accessible switches.

Other recommendations

Explore additional accessibility tips in the general Accessibility Guide.

WCAG 2.2 Guidelines

  • Non-text Content: All non-text content that is presented to the user has a text alternative that serves the equivalent purpose. (Level A)
  • Info and Relationships: Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text. (Level A)
  • Headings and Labels: Headings and labels describe topic or purpose. (Level AA)
  • Labels or Instructions: Labels or instructions are provided when content requires user input. (Level A)
  • Name, Role, Value: For all user interface components (including but not limited to: form elements, links and components generated by scripts), the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies. (Level A)