# Rating

> Stars out of five: a score to read, or one to give. Lit stars in the warning yellow, the rest in Input's edge grey.

| | |
|---|---|
| Kind | component |
| Contract | `review` · [rating.contract.yaml](https://github.com/Runceanu/rost/blob/master/contracts/rating.contract.yaml) |
| Guidance | `proposed` |
| Source | [Figma 773:127](https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=773-127) · read 2026-11-30 · frozen 2026-11-30 |
| Implemented in | nowhere yet |

## Install

It lands in `src/rost/rating/`, with what it needs and its contract:

```sh
npx github:Runceanu/rost add rating
```

Then import `src/rost/fonts.css` and `src/rost/tokens.css` once, at the root of the app. More on this in [Install](https://rost.build/docs/install.md).

## Props

| Prop | Type | Values | Default |
|---|---|---|---|
| `value` | number |  |  |
| `label` | string |  |  |
| `onValueChange` | node |  |  |

## States

`Default` · `Focus`

## Anatomy

- `root`: Five 24px tiles of Rost's star icon in a row, 120px by 24px.
- `track`: All five stars, unlit.
- `fill`: The lit stars: the same row in yellow, as wide as `value` of the five, set inline.
- `options` (optional): When you can give a score: five invisible radio buttons over the stars, one per star.
- `option` (optional): One star's button, 24px square, with nothing of its own to see. Pointing at it lights the stars up to it.
- `focus-ring` (optional): Input's ring around the five stars, while a star has the keyboard's focus.

## When to use

- **A score to read.** A review's stars next to its text, an average next to a count: 4.5 from 120 reviews.
- **A score to give.** Asking how something went, in one tap, at the end of a flow.

## When not to use

- **More than five steps.** Ten points or a percentage is a **Slider** or a number, not more stars.
- **The only way to say it.** Stars say how much, not why. When the why matters, put a **Textarea** after them.

## Behaviour

Read-only, it lights `value` of five stars, halves included. Giving a score, pointing at a star lights the stars up to it, and a press gives that score; pressing the score already given takes it back to 0.

## Accessibility

- **Element**: Read-only, the stars are `role="img"` named 3 out of 5. Giving a score, it's `role="radiogroup"` of five `role="radio"` buttons named 1 star to 5 stars, the ARIA pattern for one choice in a row.
- **Name**: `label` names the group.
- **Keyboard**: Tab reaches the given score, or the first star when there's none. Left and Right, Up and Down move the score by one, Home and End to 1 and 5.
- **Focus**: `focus-ring` around all five, on `:focus-visible`, while the lit stars show where the focus is.
- **Colour**: The lit yellow is 9:1 on the dark page, the unlit grey 4.3:1, so an unlit star still reads as a star.

## Content

Pair a read-only score with its number and its count, since five stars can't show 4.3.

## Tokens

Every token this component uses, across all its variants.

| Token | Resolves to |
|---|---|
| `rating/focus-ring` | `#00d669` |
| `rating/off` | `#747573` |
| `rating/on` | `#fda50d` |
| `spacing/outline/medium` | `2px` |
| `spacing/radius/small` | `8px` |
| `spacing/size/small` | `24px` |

## No token, on purpose

| Part | Property | Value | Why |
|---|---|---|---|
| `track` | `mask` | `url(./icon-star.svg) left center / var(--spacing-size-small) var(--spacing-size-small) repeat-x` | The icon file, repeated at spacing/size/small. |
| `fill` | `mask` | `url(./icon-star.svg) left center / var(--spacing-size-small) var(--spacing-size-small) repeat-x` | The icon file, repeated at spacing/size/small. |
| `focus-ring` | `inset` | `calc(-1 * var(--spacing-gap-2xsmall))` | Composed from a token: the ring sits spacing/gap/2xsmall outside the stars. |

See it live, with every value of every variant: [rost.build/components/rating/](https://rost.build/components/rating/)
