Forms
Rating
Capture a quick opinion with stars.
Basic
Hover to preview, click to choose. The chosen star pops slightly. Underneath are native radio inputs, so it works in forms and with the arrow keys.
How was your stay at Harbour House?
When to use
- A quick opinion on a product, stay, article or support chat.
- Showing an average score next to a review count (read-only).
- Not for precise measurements (use a slider) or when you need written feedback (add a textarea).
Half steps
allowHalf splits every star into two halves: the left half picks .5. Values step by 0.5.
3.5 / 5
Read-only
readOnly turns the stars into an image with a text alternative and shows fractional values: 4.3 fills 30% of the fifth star.
- Aurora desk lamp4.3 (218)
- Fjord wool throw4.8 (1042)
- Slate ceramic mug3.6 (87)
In a form
Give it a name: the checked radio submits its value with the form. required works natively.
API
Rating
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue | number | 0 | Current rating. 0 means none. |
| onValueChange | (value: number) => void | — | Called when the rating changes. |
| max | number | 5 | Number of stars. |
| allowHalf | boolean | — | Half-star steps. |
| allowClear | boolean | — | Clicking the chosen star again, or Backspace/Delete, clears it. |
| readOnly | boolean | — | Display only; supports fractional values. |
| disabled | boolean | — | Not interactive, dimmed. |
| size | 'sm' | 'md' | 'lg' | 'md' | Star size 16 / 24 / 32px. |
| name / required | string / boolean | — | Form field name and native required. |
| aria-label | string | 'Rating' | Name of the group. |
Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus to the rating (the chosen star, else the first). |
| Arrow keys | Choose the previous / next value (native radio behaviour; 0.5 steps with allowHalf). |
| Backspace / Delete | Clear the rating (when allowClear). |
Accessibility
- A radiogroup of native radio inputs, each named “3 stars”, “2.5 stars”.
- Read-only ratings are role="img" with a label like “Rating: 4.3 out of 5”.
- Stars have an amber fill and a darker amber outline, so they stay visible on light and dark surfaces.
- Keyboard focus shows a ring around the star.
Motion
- Hovering previews the value instantly; the fill tracks in 150ms.
- The chosen star pops from .72 to 1 on the snappy spring.
- Reduced motion: no pop; fills still change.