Shadcn Star Rating
Star rating components: a half-star picker with a note, a review breakdown and a compact score pill.
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
Hand your agent this brief or the Markdown page, not a screenshot.
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 or Action Button (
StarButton)
Agent notes
- Named exports:
StarRating,RatingPicker,RatingSummary,RatingChipfrom@/components/custom/blocks/StarRatingBlock activeColorandinactiveColortake Tailwind text colour classes ("text-amber-400"), not hexStarRatingis controlled: hold the value and update it inonRatingChange.RatingPickerholds its own value and reports throughonChangeandonSubmit- An interactive
StarRatingis a slider: arrow keys step bystep(or 0.5 / 1), Home and End jump to the ends
For AI agents3 variants. Ask the user which one.
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
Rating picker picker
A card: hover to preview a score and its word, click to pick, then add a note and send.
- 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 - Docs section
Rating summary summary
The average, its stars and a bar per level that fills as the card scrolls into view.
- 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 - Docs section
Rating chip chip
A compact score pill with a star chip, the stars and a count.
- 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 - Docs section
- Markdown
- /docs-md/nextjs-star-rating.md
- Install
npx shadcn@latest add https://avaraui.com/r/star-rating.json- Registry name
@avara-ui/star-rating, through the shadcn MCP server- Index
- llms.txt lists every page, or add the agent skill once
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:
Works with other components
- Embed
StarRatinginside Card (ProductCard) layouts, or beside testimonials in a Reviews section. - Pair
RatingPickeror an interactiveStarRatingwith Form for review submission dialogs. - Book Appointment shows named scores out of 5 with
StarRating. - For a like or upvote toggle rather than a score, use Action Button (
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.