cnippet/ui
  1. ui
  2. forms
  3. rating

forms

Rating

Star rating input for reviews and feedback, keyboard accessible, plus a read-only display that shows fractional averages. Copy-paste ready.

Installation

Usage

Good to know

  • Rating is a radio group: Tab moves into it, the arrow keys change the value, and each star is announced as "3 stars" and so on. Give the group a name with aria-label or aria-labelledby.
  • Hovering previews the value; moving the pointer away shows the selected value again.
  • A value of 0 means nothing is selected yet. Once a star is picked it can't be cleared by clicking, since radios don't uncheck. Add a "Clear" button that sets the value back to 0 if you need one.
  • Pass name to submit the value with a native form.
  • RatingDisplay is for showing scores, not editing them. It fills stars partially, so 3.7 shows 70% of the fourth star, and screen readers hear "3.7 out of 5 stars".
  • The stars are amber in every theme on purpose, because that's what people expect from reviews.

API Reference

Rating

RatingDisplay

Examples

Review summary

The average with a fractional RatingDisplay and a breakdown per star.

Sizes and states

Ten-point scale

Use max for longer scales, such as a survey.