---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Rating

A row of stars to give a score, or to show an average with halves, for reviews and feedback, for React and Tailwind CSS. Part of Goop Pro.

Pro. Its export: `Rating`.

## Try it

Click a star (its start half for a half with half stars on), or Tab in and use the arrows, Home, End or a number key; Backspace clears. Look puts the stars in a form’s field, an average in a card’s line (Size sm as a card shows it), or a row beside Send and a filter. Switch the sizes, the value words, read-only, disabled and invalid.

The score is kept in the page only: nothing is sent, and the filter beside it filters nothing.

## When to use

- A row of stars to give a score, or to show an average with halves, for reviews and feedback.
- Also called: star rating.

## Installation

Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Rating on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing. As a Pro part, its command comes from Goop's server once you sign in, with a one-time link that lasts ten minutes.

```sh
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-rating.json --yes
```

```text
Add the Goop Rating to this project. The install steps are at https://goop.so/docs/install.md
```

## Usage

```tsx
import { Rating } from '@/components/ui/goop/rating';
import { Field } from '@/components/ui/goop/field';

<>
  <Field orientation="vertical" label="How did we do?">
    <Rating name="score" />
  </Field>
  <Field orientation="vertical" label="Your review">
    <Rating name="review" size="lg" allowHalf valueLabels />
  </Field>
  <Rating readOnly size="sm" value={4.5} count={128} />
</>
```

- Fits: record, list: row.
- Also known as: StarRating, Stars, ReviewScore, ScoreInput, RatingInput.
- Ask for a 1-to-5 score with Rating inside a vertical Field and show an average with Rating readOnly size sm; use Slider for continuous values and RadioGroup for named options.
- height, width, gap, corner, text: add no class for these.

## API reference

### Rating: every option

```tsx
import { Rating } from '@/components/ui/goop/rating';
```

### Options

- value?: number — The chosen score, 0 for not rated (with `onValueChange`); read-only, the average.
- defaultValue?: number = 0 — The score at first render, for a rating that holds its own.
- onValueChange?: (value: number) => void — Called with the new score, or 0 when cleared.
- max?: number = 5 — How many stars.
- readOnly?: boolean = false — Show the value only: one image named "Rated 4.5 out of 5", halves drawn, no tab stop.
- size?: 'sm' | 'md' | 'lg' = 'md' — `md`: 20 px stars in 28 px cells; `sm`: 14 px stars, read-only beside 12 px words; `lg`: 24 px stars in 32 px cells, a rating that is the page's question.
- allowHalf?: boolean = false — Half stars may be given: the pointer on a star's start half gives the half, the arrows move by a half.
- optional?: boolean = true — The score may be none: a second press on the chosen star, Backspace or Delete clears it.
- name?: string — The radios' name, sent with the form (nothing while not rated).
- disabled?: boolean = false — Every star off and dimmed: none takes the focus, a press or a key.
- label?: string — The rating's name where no `Field` label and no `aria-label` names it.
- starLabel?: (value: number, max: number) => string — Each star's name for a reader ("1 star", "n stars" by default).
- valueLabels?: boolean | readonly string[] — Words for the scores, shown after the stars in place of the number: `true` for "Poor", "Fair", "Good", "Very good", "Excellent" (five stars), or one word per star.
- showValue?: boolean = true — Whether the value stands after the stars: the score ("4", "4.5") or its word; at 0 an en dash named `empty` (read-only, `empty` itself).
- empty?: string = 'Not rated' — The words for not rated: interactive, the name of the en dash shown in their place; read-only, shown after the stars.
- count?: number — Read-only: how many ratings the average holds ("4.5 (128)").
- State: value (value / defaultValue / onValueChange); drawn by data-disabled

## Keyboard

- Tab: move to the chosen star (the first when not rated), then out of the group
- ArrowRight / ArrowUp: choose the next star (the next half with allowHalf), wrapping
- ArrowLeft / ArrowDown: choose the previous star (the previous half with allowHalf), wrapping
- Space: choose the focused star
- Home / End: choose the lowest score (one star, or a half with allowHalf) or the highest, the focus with it
- 1-9: choose that many stars, the focus with it (a number past the stars does nothing)
- Backspace / Delete: clear the score

## Accessibility

- The native element answers the keyboard.
- disabled: the attribute data-disabled
- invalid: the attribute aria-invalid

## Notes for AI

Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.

## Related

- [Field](/themes/trail/components/field): A form row that ties one control to its label, its description and its error line, as a settings row or a stacked form field.
- [Color picker](/themes/trail/components/color-picker): A painted area and channel sliders that choose one colour.
- [File upload](/themes/trail/components/file-upload): A drop zone or a button to choose files, with a list of the chosen files and their sizes, for attachments, imports or a photo.
- [Calendar](/themes/trail/components/calendar): A month always in view, to choose a date or a range of dates.
