Star Rating

Hover to preview, click to rate. A radio group with arrow-key support.

no dependenciesMIT · free

You rated 4 of 5.

read-only

Installation

npx shadcn@latest add https://ombakui.com/r/star-rating.json

Usage

import { StarRating } from "@/components/star-rating";

<StarRating label="Rate this product" value={rating} onChange={setRating} />
<StarRating label="Average rating" value={4} readOnly />

Props

PropTypeDefaultDescription
label*string–Accessible name for the group, e.g. "Rate this product".
valuenumber–Rating (controlled).
defaultValuenumber0Starting rating when uncontrolled.
onChange(value: number) => void–Called with the new rating.
maxnumber5Number of stars.
sizenumber28Star size in px.
colorstring"#fbbf24"Star color.
readOnlybooleanfalseShow the rating but don't allow changes.
classNamestring–