Skip to content
easeweb
Search topics

Star ratings that keyboards and screen readers skip

A review form's five stars are clickable spans or radio buttons hidden with display: none, so Tab never reaches them and a screen reader hears no rating.

WCAG 2.2
SC 2.1.1ASC 4.1.2ASC 1.3.1A
Required by
Section 508 · EN 301 549 (EU)
Broken <span class="star" onclick="rate(4)">
The accessibility problem illustrated: Motor:How do I choose the stars?
01

The problem

Keyboard and switch users can't choose a rating, and screen reader users hear neither the stars nor which one is chosen, so they can't rate a product or check the rating they gave

02

Try it

Click a star, then put the mouse aside and give 4 stars with the keyboard

  • Broken 1: click a star, then press Tab to reach the stars and give 4 stars with the arrow keys. With a mouse, both versions fill the stars. The panel shows what a screen reader hears as focus moves and the choice changes: is a star ever announced, or which one is chosen?

  • Broken 2: the stars are real radio buttons, removed with display: none. Try the same: is a star ever announced, or which one is chosen?

  • Apply a fix. Tab to the stars and give 4 stars with the arrow keys: is a star announced now, and which one is chosen?

Broken Can you fix this?

Your rating

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Make the stars one radio group, named by its question

Before

Five spans with onclick

<form action="/reviews" method="post">  <p class="question">Your rating</p>  <div class="stars">    <span class="star" onclick="rate(1)"></span>    <span class="star" onclick="rate(2)"></span>    <span class="star" onclick="rate(3)"></span>    <span class="star" onclick="rate(4)"></span>    <span class="star" onclick="rate(5)"></span>  </div>  <input type="hidden" name="rating">  …  <button type="submit">Post review</button></form>
What is wrong3 points
  • No key reaches or fills a star. The spans take a click and nothing else, and they aren't in the Tab order.
  • A screen reader says nothing for the stars, and nothing says they are controls. The spans have no role, name or state.
  • A screen reader can't tell which rating is chosen. It lives in a class and a hidden form value that no assistive technology reads.
After

Radio buttons over the drawn stars

<form action="/reviews" method="post">  <fieldset class="stars">    <legend class="question">Your rating</legend>    <label class="star">      <input type="radio" name="rating" value="1">      <span class="visually-hidden">1 star</span>    </label>    <label class="star">      <input type="radio" name="rating" value="2">      <span class="visually-hidden">2 stars</span>    </label>    <label class="star">      <input type="radio" name="rating" value="3">      <span class="visually-hidden">3 stars</span>    </label>    <label class="star">      <input type="radio" name="rating" value="4">      <span class="visually-hidden">4 stars</span>    </label>    <label class="star">      <input type="radio" name="rating" value="5">      <span class="visually-hidden">5 stars</span>    </label>  </fieldset>  …  <button type="submit">Post review</button></form>
How it is fixed3 steps
  1. Make each radio button transparent instead of removing it, and lay it over its own star. It stays in the Tab order and the accessibility tree, and a touch on a star lands on its radio button.
  2. Draw a ring around the star from the radio button's own focus, with :has(:focus-visible). It is the only thing new on screen.
  3. Keep the question as the group's legend, and keep filling the stars from the checked radio button itself, so what is drawn can't drift from what is announced. The radio buttons sit in source order, 1 to 5, and :has() fills the stars before the checked one, so nothing is reversed to make the fill work.

The browser does the rest. Tab stops on the rating once, the arrow keys move the choice one star at a time, and a screen reader announces the question, "Your rating", then something like "4 stars, radio button, checked, 4 of 5". The design is kept exactly as drawn: the same stars, the same fill, nothing new on screen but a focus ring. This fixes both Befores and passes 2.1.1, 4.1.2 and 1.3.1. Of the extras a scripted rating is kept for, the radio buttons can show a hover preview too, with the same :has() rules on :hover, and the stars drawn behind them can be any image or SVG.

Why this fix: Use native HTML first

04

Design ideas

A rating can be stars or numbers, as long as a key can choose it

Three ways to draw a rating. Click them, then put the mouse aside and try each with Tab and the arrow keys: two pass, and one gives the mouse a half star that no key can give.

In the design file

  • Mark the stars in the design file as one question with five choices, a radio group, so they are built on radio buttons.
  • Write the question above the stars, and a name for each star, “1 star” to “5 stars”, which a screen reader reads out.
  • Draw a star with its focus ring, as it looks when reached with Tab and moved with the arrow keys.
  • Draw the rating before anything is chosen, and say whether it can be cleared once chosen.

Passes

  • Your rating
    Numbered circles, the ends named Five 40px circles numbered 1 to 5, with “Poor” and “Excellent” under the ends, as survey tools draw them. The number is the rating, so it reads at a glance and in greyscale; the chosen circle fills with #1a1a1a ink, 17.40:1 on white.
  • Your rating
    Stars with a quiet Clear A rating that may stay empty needs a way back, since a chosen star can’t be unchosen by a key. “Clear”, underlined in #4b5563, 7.56:1, appears after the stars once one is chosen, and empties them for the mouse and the keyboard alike.

Fails

  • Your rating
    Half stars set by where the pointer landsWCAG 2.1.1 A click on the left half of the fourth star gives 3.5, but Tab and the arrow keys move only between the five whole stars, so no key gives a half. Draw ten choices if halves matter, or keep whole stars.
05

Verify the fix

5 checks.

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

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 rating component or the theme changes.

Limits

This is a starting pattern, not a guarantee for every application. The CSS is a sketch: check the size of the stars, their contrast and the focus ring against your own palette. Stars told apart only by colour, such as a grey star and a yellow star of the same shape, are a different failure, left to the topic on colour alone, whose guide is in progress. A scale of faces that are buttons with no names is covered in smiley-face ratings announced only as "button". A group of radio buttons whose question isn't tied to them is covered in radio buttons and checkboxes without a group name. Test the whole review form with a keyboard, a screen reader and a phone.

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