Skip to content
VenusUI
Get started

Rating

A star rating built on native radio buttons, with a read-only display mode.

Preview

Installation

npx shadcn@latest add @venusui/rating

Run this in a project set up with shadcn. If you haven’t set it up yet, run npx shadcn@latest init first.

Files added to your project

Paths use the default shadcn aliases. The CLI follows the aliases in your components.json.

  • @/components/ui/rating.tsx

Usage

The code behind the preview above.

rating-demo.tsx

import { Rating } from "@/components/ui/rating"

export default function RatingDemo() {
  return (
    <div className="flex flex-col items-center gap-4">
      <Rating label="Rate this template" defaultValue={4} />
      <Rating label="Average rating" value={3} readOnly />
    </div>
  )
}

API reference

PropTypeDefaultDescription
labelstring—Accessible name, e.g. “Rate this template”. Required.
valuenumber—Controlled value.
defaultValuenumber0Initial value.
onValueChange(value: number) => void—Called when the rating changes.
maxnumber5Number of stars.
readOnlybooleanfalseDisplay only.

Only the props above, plus className.

Requirements

  • lucide-react, React 19 and Tailwind CSS v4.

Customization

  • Change the star color by editing fill-amber-400 in the file.

Accessibility

  • Native radios in a fieldset: arrow keys change the rating and each star is named “3 stars”.
  • Read-only mode is one labelled image, e.g. “3 out of 5 stars”.

Troubleshooting

Two ratings change together.
Each instance generates its own radio group name; don’t pass the same name to both.
Unknown registry "@venusui"
Your shadcn CLI couldn’t find the namespace in the shadcn registry index. Use the latest CLI (npx shadcn@latest), install by URL, or register it with its address: npx shadcn@latest registry add @venusui=https://venusui.com/r/{name}.json.
No components.json found
Run npx shadcn@latest init in your project first.
Loading preview

A café dial for choosing a drink, with a cup that shows what goes into it.

Loading preview

A wall plate of rocker switches that light a row of pendant bulbs.

Loading preview

A graphic equalizer panel with faders, LED columns, a response curve and presets.