---
title: "Rating"
description: "Give a score with stars, in whole or half steps. A display part shows any score, such as 4.3 of 5, with no input."
url: https://gelatinui.com/components/rating
markdown_url: https://gelatinui.com/components/rating.md
access: free
install: "npx shadcn@latest add @gelatin-ui/rating"
registry_item: https://gelatinui.com/r/rating.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Rating

> Give a score with stars, in whole or half steps. A display part shows any score, such as 4.3 of 5, with no input.

Page: https://gelatinui.com/components/rating

## When to use it

Best for: Set a score from 1 to `max` in stars, or show a score of any fraction with `RatingDisplay`.

- Use `Rating` when people set a score: a review, a feedback form.
- Use `RatingDisplay` to show a score that no one can change. It takes any fraction, such as 4.3.
- Use `step={0.5}` for half stars.
- Use `clearable` when people can go back to no score.
- Use `icon` for another shape, such as a heart.

## When not to use it

- To pick a value from a wide range, use a [Slider](https://gelatinui.com/components/slider.md).
- To pick one of a few named values, use a [Segmented Control](https://gelatinui.com/components/segmented-control.md).

## Notes for agents

- `Rating` is a Base UI Radio Group. The keys, the form value, and the Field validation are the ones of a radio group.
- `value` is `null` for no score. `onValueChange` also runs on a clear, with `null`.
- Base UI turns off Home and End in a radio group.
- Right-to-left keys need a `DirectionProvider`.
- Call `eventDetails.cancel()` in `onValueChange` to stop a change.
- Translate the name of each choice with `getItemLabel`. The default is "3 stars".
- Show the number next to `RatingDisplay` ("4.3 · 1,284 reviews"), so the score reads without the icons.
- `RatingDisplay` takes no focus.

## Anatomy

```text
Rating
├─ RatingItem (0..n)
└─ RatingDisplay (0..n)
```

## API reference

### Rating

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | `RatingItem` parts. Leave it out to get `max` items. |
| `size` | `"default" \| "lg" \| "sm"` |  |  |
| `className` | `string` |  |  |
| `value` | `number \| null` |  | The score, or `null` for no score. Controlled. |
| `defaultValue` | `number \| null` | null | The first score when uncontrolled. |
| `onValueChange` | `function` |  | Runs on each change, also on a clear (`null`). Call `eventDetails.cancel` to stop it. |
| `max` | `number` | 5 | The number of stars. |
| `step` | `0.5 \| 1` | 1 | `1`: whole stars. `0.5`: half stars, two radios per star. |
| `clearable` | `boolean` | false | A press on the current score clears it to `null`. |
| `icon` | `Icon` | StarIcon | The icon of a star: any Phosphor icon (`HeartIcon`); it draws in its `fill` and `regular` weights. |
| `getItemLabel` | `function` | starLabel | The accessible name of each choice. Default: "1 star", "2.5 stars". |
| `glow` | `boolean` |  | A soft halo on the filled stars (`glow`, `@gelatin-ui/glow`). Default: `false`. |

Also takes every prop of Base UI `RadioGroup`: https://base-ui.com/react/components/radio-group

### RatingItem

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `value` | `number` |  | The number of the star, 1 to `max`. With `step={0.5}` its halves are `value − 0.5` and `value`. |

Also takes every prop of Base UI `Radio.Root`: https://base-ui.com/react/components/radio

### RatingDisplay

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `"default" \| "lg" \| "sm"` |  |  |
| `value` | `number` |  | The score to show, any fraction (4.3). It is clamped to 0 to `max`. |
| `max` | `number` | 5 | The number of stars. |
| `icon` | `Icon` | StarIcon | The icon of a star, as on `Rating`. |
| `glow` | `boolean` |  | A soft halo on the filled stars (`glow`, `@gelatin-ui/glow`). Default: `false`. |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Rating | `rating` | `data-disabled`, `data-invalid`, `data-readonly` |  | `motion-timing` |
| RatingItem | `rating-item` |  |  |  |
| RatingDisplay | `rating-display` | `data-disabled`, `data-invalid`, `data-readonly` |  | `motion-timing` |

## Usage

Render one `RatingItem` for each star, and show the average next to it with `RatingDisplay`, which no one can change.

```tsx title="stay-rating.tsx"
import { useState } from "react";

import { Rating, RatingDisplay, RatingItem } from "@/components/ui/rating";

const STARS = [1, 2, 3, 4, 5];

export function StayRating() {
  const [score, setScore] = useState<number | null>(null);
  return (
    <div className="flex flex-col gap-3">
      <p className="flex items-center gap-2 text-sm text-muted-foreground">
        <RatingDisplay value={4.3} size="sm" />
        4.3 · 1,284 reviews
      </p>
      <Rating value={score} onValueChange={setScore} clearable aria-label="Rate your stay">
        {STARS.map((star) => {
          return <RatingItem key={star} value={star} />;
        })}
      </Rating>
    </div>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/rating
```

It adds 14 registry items: 12 files, 3284 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@phosphor-icons/react`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Field](https://gelatinui.com/components/field.md)
- [Toggle](https://gelatinui.com/components/toggle.md)
- [Slider](https://gelatinui.com/components/slider.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Arrow Right, Arrow Down | Moves to the next higher score and chooses it. With `step={0.5}`, it moves by half a star. |
| Arrow Left, Arrow Up | Moves to the next lower score and chooses it. |
| Space | With `clearable`, on the current score: clears the score. |
| Tab | Leaves the group. |

## Accessibility

Each star is a radio, and `getItemLabel` translates its name. The default is "3 stars".

`RatingDisplay` takes no focus. Show the number next to it, so the score reads without the icons.

On a coarse pointer each radio is 44px tall.

## Motion

| Part | Motion |
| --- | --- |
| Hover | hover · 150ms · ease-out (0, 0, 0.2, 1) · the stars up to the pointer show at 60% |
| Press | press · 100ms · ease-out (0, 0, 0.2, 1) · the pressed star scales |
