Avara UI

Shadcn Star Rating

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

Applies to this page's previews only

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

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
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

  1. 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
  2. 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
  3. 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
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

ComponentPropTypeDefaultDescription
StarRatingratingnumberRequiredThe current rating value to display (e.g., 3.5 or 4.8).
StarRatingmaxStarsnumber5The total number of stars to display.
StarRatingsizenumber24The width and height of each individual star in pixels.
StarRatingactiveColorstring"text-primary"Tailwind text color class for the filled (active) portion of the stars.
StarRatinginactiveColorstring"text-foreground/15"Tailwind text color class for the empty (inactive) portion of the stars.
StarRatingshowTextbooleantrueIf true, displays the numerical rating text next to the stars (e.g. 4.8 / 5).
StarRatinginteractivebooleanfalseIf true, enables hover states and clicking to change the rating.
StarRatingallowHalfbooleantrue(Legacy) If true and interactive is true, allows users to select 0.5 increments.
StarRatingstepnumberallowHalf ? 0.5 : 1Defines the precision increment (e.g. 0.1 for continuous). Overrides allowHalf.
StarRatingonRatingChange(rating: number) => voidundefinedCallback function fired when a user clicks to set a new rating.
StarRatingonHoverChange(rating: number) => voidundefinedCallback function fired when a user hovers over the stars, updating the temporary display rating.
StarRatingclassNamestringundefinedOptional Tailwind CSS classes to override or extend the outer container's styling.
RatingPickertitle, descriptionstringa stay promptThe heading and the line under it.
RatingPickerlabelsstring[]Poor to ExcellentA word per whole star, lowest first.
RatingPickerallowHalfbooleantruePick in 0.5 steps.
RatingPickerwithCommentbooleantrueAsk for a note once a rating is chosen.
RatingPickeronChange, onSubmitfunction-Fire on every pick, and on Send with { rating, comment }.
RatingSummaryrating, distributionnumber, number[]RequiredThe average and the count per star, five stars first.
RatingChiprating, count, label, distributionnumber, number, string, number[]rating requiredThe 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 StarRating inside Card (ProductCard) layouts, or beside testimonials in a Reviews section.
  • Pair RatingPicker or an interactive StarRating with 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.