Skip to content
easeweb
Search topics

Toggle switches that don't say whether they are on

A switch shows on and off with colour and a sliding knob, but its state is only a CSS class, so assistive technology never hears it.

WCAG 2.2
SC 4.1.2A
Required by
Section 508 · EN 301 549 (EU)
Broken class="is-on"
The accessibility problem illustrated: No vision:Is it on or off?
01

The problem

Screen reader users can find the switch but can't tell whether it is on or off, or whether pressing it did anything

02

Try it

Press Tab to reach the switch, then Space to toggle it

The panel shows what a screen reader announces. Can you tell whether email updates are on?

Broken Can you fix this?

BrokenA button that draws its state

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Make the switch say whether it is on

Before
BrokenA button that draws its state
<button type="button" class="switch" onclick="this.classList.toggle('is-on')">  Email updates</button>
What is wrong3 points

The button can be reached with Tab and pressed with Enter and Space. Its state is where it fails.

  • Nothing says whether the switch is on. The state is only the is-on class.
  • A screen reader announces "Email updates, button" whether it is on or off.
  • A toggle is never announced. No state in the accessibility tree changes with it.
After

A native checkbox styled as a switch

<label class="switch">  <input type="checkbox" name="email-updates" checked>  Email updates</label>
How it is fixed3 steps
  1. Replace the button with a checkbox inside its label. The browser holds the state, exposes it as checked or not checked, and toggles it with Space and a click on the label.
  2. Remove the checkbox's own look with appearance: none, and draw the track on the input.
  3. Draw the knob with ::before, and move it from :checked, so the picture can't drift from what is announced.

This fixes the Before and passes 4.1.2. It also submits with the form, without script. Of the extras a custom switch is kept for, the knob can slide here too, with a transition on translate.

Why this fix: Use native HTML first

04

Design ideas

On and off can be told apart without colour

Five ways to draw the guide’s Email updates switch. Each one works: click it, or Tab to it and press Space. Three show the state by more than colour; two look fine until you can’t tell green from grey, or can’t find the knob.

In the design file

  • Draw on and off side by side and check them in greyscale. They should differ by the knob’s position or a word, not only by colour.
  • Keep the label the same in both states, such as “Email updates”, and show on or off beside it. Don’t write “Turn off email updates”.
  • Write the knob’s contrast ratio against each track colour, at least 3:1. The example has 4.49:1 on grey and 4.27:1 on green.
  • Draw the switch in a Windows contrast theme, where the track keeps its outline and the knob still shows.

Passes

  • On or Off written beside the switch The word On or Off in #555555, 7.46:1 on white, sits between the label and the track, so the state reads at a glance, in greyscale and in forced colors, before anyone looks for the knob. The knob keeps 4.49:1 against the grey track and 4.27:1 against the green.
  • A check on the knob when on On, the white knob slides right and carries a #1f6b3a check, 6.52:1; off, it sits plain on the left. Position and shape both say the state, so it still reads in greyscale.
  • An On | Off pill Both words are always shown, and a solid #1f6b3a block, 6.52:1 on the white pill, sits behind the current one in bold white. Click either half to pick it.

Fails

  • A chip that only changes colourWCAG 1.4.1 Green #2e8b4e when on, grey #7d7a75 when off, white words on both at 4.27:1. The two fills are 1.00:1 apart, so in greyscale, or to someone who can’t tell green from grey, on and off look the same.
  • A pastel switchWCAG 1.4.11 A white knob on a pale mint #cde5d5 track, 1.33:1, and a #ecebe8 track when off, 1.19:1 on the page. Soft in a mock-up, but the knob is what shows on or off, and it needs 3:1 against the track around it.
05

Verify the fix

5 checks.

Test with: Keyboard, Screen reader, Forced colors, Mouse

0 of 5 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the shared switch component changes.

How screen readers handle aria-pressed

Limits

This is a starting pattern, not a guarantee for every application. Screen readers word the switch role differently, and some older ones announce it as a checkbox or toggle button. The CSS is a sketch; check the focus indicator and contrast of the track against your own palette. A state written with a value ARIA doesn't define, such as aria-checked="yes", is a different failure, covered in invalid ARIA that misleads screen readers. A switch drawn beside a checkbox hidden with display: none can't be reached with Tab at all, which is covered in custom checkboxes that keyboards and screen readers skip. Test the complete settings journey with your target assistive technology.

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

EaseWeb service

Fixed it? Keep it from coming back.

I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.

See the service