---
title: "Shadcn Star Rating"
description: "Star rating components: a half-star picker with a note, a review breakdown and a compact score pill. Free shadcn/ui component for React and Tailwind CSS."
url: https://avaraui.com/docs/nextjs/star-rating
---

# Shadcn Star Rating

Star rating components: a half-star picker with a note, a review breakdown and a compact score pill.

## Installation

Add the component by URL — no setup needed:

```bash
npx shadcn@latest add https://avaraui.com/r/star-rating.json
```

Or register the @avara-ui registry once per project and add it by name:

```bash
npx shadcn@latest registry add @avara-ui=https://avaraui.com/r/{name}.json
npx shadcn@latest add @avara-ui/star-rating
```

## Rating picker

Hover to preview a score and its word, click to pick, then add a note and send.

- `allowHalf` picks in 0.5 steps by default; pass `{false}` for whole stars.
- `onSubmit` receives the rating and the note.

```tsx
"use client";

import { RatingPicker } from "@/components/custom/blocks/StarRatingBlock";

export default function StayRating() {
  return (
    <RatingPicker
      title="How was your stay?"
      onSubmit={({ rating, comment }) => console.log(rating, comment)}
    />
  );
}
```

## Rating chip

A compact score for product cards and page headers.

- `count` and `label` set the text after the stars.

```tsx
import { RatingChip } from "@/components/custom/blocks/StarRatingBlock";

export default function ProductScore() {
  return (
    <RatingChip
      rating={4.8}
      count={1284}
      label="reviews"
      // Optional: ratings per star, five stars first. Click the chip to open the breakdown.
      distribution={[1284, 402, 96, 31, 18]}
    />
  );
}
```

## Rating summary

The average, its stars and a bar per level that fills as the card scrolls into view.

- `distribution` is the count of ratings per star, five stars first.

```tsx
import { RatingSummary } from "@/components/custom/blocks/StarRatingBlock";

export default function ProductReviews() {
  return (
    <RatingSummary
      rating={4.6}
      // Ratings per star, five stars first.
      distribution={[1284, 402, 96, 31, 18]}
    />
  );
}
```

## About Shadcn Star Rating

**What it is.** Four exports share one star: `RatingPicker` (a card to collect a rating and a note), `RatingSummary` (average and breakdown), `RatingChip` (a score pill) and `StarRating`, the row of stars they are built from.

**How it is built.** React and inline SVG, no dependencies. Each star is an empty glyph under a filled one clipped to the rating, so any decimal fills exactly and the fill glides when the value changes. Cards reveal with a blur, and the picker's note makes room instead of popping in.

**When to use it.** Product pages, review lists, feedback prompts after a booking or an order.

## For AI agents

**When to use**

- Collecting a rating with an optional note (`RatingPicker`), showing a review breakdown (`RatingSummary`) or a compact score (`RatingChip`)
- A bare row of stars at any decimal (`StarRating`), read-only or interactive

**When not to use**

- Binary favorite/like toggles: use [Toggle](https://avaraui.com/docs/nextjs/toggle) or [Action Button](https://avaraui.com/docs/nextjs/action-buttons) (`StarButton`)

**Agent notes**

- Named exports: `StarRating`, `RatingPicker`, `RatingSummary`, `RatingChip` from `@/components/custom/blocks/StarRatingBlock`
- `activeColor` and `inactiveColor` take Tailwind text colour classes (`"text-amber-400"`), not hex
- `StarRating` is controlled: hold the value and update it in `onRatingChange`. `RatingPicker` holds its own value and reports through `onChange` and `onSubmit`
- An interactive `StarRating` is a slider: arrow keys step by `step` (or 0.5 / 1), Home and End jump to the ends

**Ask before you pick.** This page has 3 variants. If the user has not named one and has not asked you to choose for them, ask which they want before you install anything or write code, and show every option with its live link. If they ask you to choose, pick from each variant's best-for and avoid-if lines against their brief, and say why. If the user named a variant, use it and do not ask.

All 3 options as live previews: https://avaraui.com/view/star-rating

**When to use it.** Star ratings: a picker that collects a score and a note, a review breakdown and a compact score pill.

**Gotchas:**

- All three are exports of the one `star-rating` item: `RatingPicker`, `RatingSummary` and `RatingChip`. `StarRating` is the row of stars they share.

### The 3 variants

1. **Rating picker** (`picker`): A card: hover to preview a score and its word, click to pick, then add a note and send.
   - Live: https://avaraui.com/view/star-rating/picker
   - Best for: collecting a rating after a booking, order or support chat
   - Avoid if: you only show an existing score
   - Traits: half steps, labels per score, note and send, thank-you state
   - Install: `npx shadcn@latest add @avara-ui/star-rating`
   - Set these props: `{"component":"RatingPicker"}`
   - Docs: https://avaraui.com/docs/nextjs/star-rating#rating-picker
2. **Rating summary** (`summary`): The average, its stars and a bar per level that fills as the card scrolls into view.
   - Live: https://avaraui.com/view/star-rating/summary
   - Best for: a product or reviews page header
   - Avoid if: you want to collect a rating
   - Traits: average score, distribution bars, reveals on scroll
   - Install: `npx shadcn@latest add @avara-ui/star-rating`
   - Set these props: `{"component":"RatingSummary"}`
   - Docs: https://avaraui.com/docs/nextjs/star-rating#rating-summary
3. **Rating chip** (`chip`): A compact score pill with a star chip, the stars and a count.
   - Live: https://avaraui.com/view/star-rating/chip
   - Best for: product cards and page headers
   - Avoid if: you need the breakdown
   - Traits: one pill, count
   - Install: `npx shadcn@latest add @avara-ui/star-rating`
   - Set these props: `{"component":"RatingChip"}`
   - Docs: https://avaraui.com/docs/nextjs/star-rating#rating-chip

## Props Reference

| Component | Prop | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `StarRating` | `rating` | `number` | Required | The current rating value to display (e.g., `3.5` or `4.8`). |
| `StarRating` | `maxStars` | `number` | `5` | The total number of stars to display. |
| `StarRating` | `size` | `number` | `24` | The width and height of each individual star in pixels. |
| `StarRating` | `activeColor` | `string` | `"text-primary"` | Tailwind text color class for the filled (active) portion of the stars. |
| `StarRating` | `inactiveColor` | `string` | `"text-foreground/15"` | Tailwind text color class for the empty (inactive) portion of the stars. |
| `StarRating` | `showText` | `boolean` | `true` | If true, displays the numerical rating text next to the stars (e.g. `4.8 / 5`). |
| `StarRating` | `interactive` | `boolean` | `false` | If true, enables hover states and clicking to change the rating. |
| `StarRating` | `allowHalf` | `boolean` | `true` | (Legacy) If true and `interactive` is true, allows users to select 0.5 increments. |
| `StarRating` | `step` | `number` | `allowHalf ? 0.5 : 1` | Defines the precision increment (e.g. `0.1` for continuous). Overrides `allowHalf`. |
| `StarRating` | `onRatingChange` | `(rating: number) => void` | `undefined` | Callback function fired when a user clicks to set a new rating. |
| `StarRating` | `onHoverChange` | `(rating: number) => void` | `undefined` | Callback function fired when a user hovers over the stars, updating the temporary display rating. |
| `StarRating` | `className` | `string` | `undefined` | Optional Tailwind CSS classes to override or extend the outer container's styling. |
| `RatingPicker` | `title`, `description` | `string` | a stay prompt | The heading and the line under it. |
| `RatingPicker` | `labels` | `string[]` | Poor to Excellent | A word per whole star, lowest first. |
| `RatingPicker` | `allowHalf` | `boolean` | `true` | Pick in 0.5 steps. |
| `RatingPicker` | `withComment` | `boolean` | `true` | Ask for a note once a rating is chosen. |
| `RatingPicker` | `onChange`, `onSubmit` | `function` | - | Fire on every pick, and on Send with `{ rating, comment }`. |
| `RatingSummary` | `rating`, `distribution` | `number`, `number[]` | Required | The average and the count per star, five stars first. |
| `RatingChip` | `rating`, `count`, `label`, `distribution` | `number`, `number`, `string`, `number[]` | `rating` required | The score, the count and its word. Pass `distribution` and the chip opens into a 1-5 star breakdown. |

## Interface Reference

If you are using TypeScript, you can import the `StarRatingProps` interface for strong typing:

```tsx
interface StarRatingProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
  rating: number;
  maxStars?: number;
  size?: number;
  activeColor?: string;
  inactiveColor?: string;
  showText?: boolean;
  interactive?: boolean;
  allowHalf?: boolean;
  step?: number;
  onRatingChange?: (rating: number) => void;
  onHoverChange?: (rating: number) => void;
}
```

## Works with other components

- Embed `StarRating` inside [Card](https://avaraui.com/docs/nextjs/card) (`ProductCard`) layouts, or beside testimonials in a [Reviews](https://avaraui.com/docs/nextjs/reviews) section.
- Pair `RatingPicker` or an interactive `StarRating` with [Form](https://avaraui.com/docs/nextjs/form) for review submission dialogs.
- [Book Appointment](https://avaraui.com/docs/nextjs/book-appointment) shows named scores out of 5 with `StarRating`.
- For a like or upvote toggle rather than a score, use [Action Button](https://avaraui.com/docs/nextjs/action-buttons) (`StarButton`).

## How do I show a rating like 4.3 with partial stars in StarRating?

Pass the number as `rating`, for example `<StarRating rating={4.3} />`. Each star is clipped to its share of the value, so the fifth star here fills to 30%. Values are clamped between 0 and `maxStars`, and `showText={false}` hides the "4.3 / 5" label.

## How do I make StarRating interactive and save the rating?

Set `interactive` and keep the rating in state, updating it from `onRatingChange`. The component does not store a chosen value itself, so without that update the stars snap back after a click. Hover shows a preview rating, and `onHoverChange` reports it.

## How should I configure step vs allowHalf for interactive ratings?

`allowHalf` (on by default) picks in 0.5 steps, and `allowHalf={false}` picks whole stars. `step` overrides both, so `step={0.1}` allows tenths. For user-submitted ratings, whole or half stars are easier to click accurately than `0.1` precision.

## How do I change the StarRating colour and size?

Use `activeColor` and `inactiveColor` with Tailwind text colour classes such as `text-yellow-400`, not hex values, because the stars use `currentColor`. `size` sets each star's width and height in pixels (24 by default), and `maxStars` changes the scale length from 5.

## Is StarRating keyboard accessible?

Yes. An interactive row is a slider: Tab focuses it, the arrow keys change the value by one step, and Home and End jump to 0 and the maximum. Hover and the click pop are skipped for touch and under reduced motion.

---

Live previews and every example: https://avaraui.com/docs/nextjs/star-rating
