Selection

Rating

Five squares, not stars. Pure CSS fill via :has(), with a hover preview.

Examples

Rating

Anatomy

fieldset.ratingThe row. Name it with aria-label or a <legend>.
> labelOne square per value, in ascending order.
label > input[type=radio]Covers the square, invisible. All share a name; value is the score.
label > span.sr-onlyThe number, as the radio's accessible name.

API

AttributeValuesDescription
checkedbooleanOn one radio: that square and every one before it fill with the warning colour.
value<n>The score the form submits.

Accessibility

  • Each radio needs a name: the visually hidden number (or "3 of 5") in span.sr-only.
  • Hovering previews a value by filling up to the pointer; the checked value shows again when the pointer leaves.
  • Once a value is checked it can't be cleared with the keyboard. Add a separate reset if "no rating" must be possible.
KeyEffect
← / →Lowers or raises the rating by one.
TabEnters the rating at the checked square; the rating is one tab stop.
Jump to
ProportionFoundations
MaterialFoundations
PresetsFoundations
ShellLayouts · Application
Container and stacksLayouts · Pages
SplitLayouts · Pages
Grid, bento, masonryLayouts · Pages
Switcher and rowLayouts · Pages
↑↓Move↵OpenescClose