GooseUI

Components

Rating

New

Rating works in two modes. Interactive mode is a group of native radio inputs: hover previews a score, a click or the arrow keys pick it, and the stars light up one after another with a ring around the chosen one. The fill, the preview and the flash are CSS through :has() and sibling selectors, so the component is a Server Component and ships no JavaScript. Read-only mode shows fractional values like 4.7 and gives screen readers a plain text summary.

Browser Support

:has()

Styles elements based on their contents

Your browser:
:user-valid and :user-invalid

Styles validation after interaction

Your browser:
color-mix()

Colors unselected stars

Your browser:

Preview

Hover, click or tab into the stars and use the arrow keys. Works with JavaScript turned off.

Not rated yet

Installation

npx shadcn@latest add @gooseui/rating
pnpm dlx shadcn@latest add @gooseui/rating
yarn dlx shadcn@latest add @gooseui/rating
bunx --bun shadcn@latest add @gooseui/rating

Usage

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

// A Server Component: the score lives in the radio inputs
export default function Example() {
  return <Rating name="score" defaultValue={4} />
}

// Inside a client component you can still listen to changes
<Rating value={value} onValueChange={setValue} />

Examples

Read-only with fractions

With readOnly the top layer of each star is cropped to its share of the value, so 4.7 shows four full stars and most of the fifth.

4.71,284 reviews
3.496 reviews
1.812 reviews
<Rating readOnly value={4.7} />
<Rating readOnly value={3.4} />

Shapes, sizes and scale

shape switches between a five-pointed star and an eight-pointed sparkle. max changes the scale, and the color follows the text color, so a text-* class recolors it.

<Rating shape="sparkle" defaultValue={3} size="lg" />
<Rating shape="sparkle" max={10} defaultValue={7} size="sm" className="text-foreground" />

In a form

name becomes the name of the radio group, so the score is sent with the form, even before hydration. allowClear adds a hidden "no rating" radio and lays its label over the selected star, so a second click clears the score without JavaScript.

Quality
Delivery
Support

Click the selected star again to clear

import { Button } from "@/components/ui/button"

<form action={submit}>
  <Rating name="quality" allowClear />
  <Button type="submit">Send</Button>
</form>

Props

PropTypeDefaultDescription
valuenumber | null-Selected score in controlled mode, null when empty
defaultValuenumber | nullnullInitial score in uncontrolled mode
onValueChange(value: number | null) => void-Called with the new score or null after clearing. Only inside client components
maxnumber5Number of stars
size"sm" | "md" | "lg""md"Star size
shape"star" | "sparkle""star"star is five-pointed, sparkle is eight-pointed
readOnlybooleanfalseDisplay mode with fractional fill
disabledbooleanfalseTurns off interaction
namestring-Name of the radio group for form submission
requiredbooleanfalseThe form is not sent until a score is picked
allowClearbooleanfalseA second click on the selected star clears the score
labelsPartial<RatingLabels>-Accessible texts: group name, per-star name, read-only summary, no rating option
classNamestring-Additional CSS classes. A text-* class sets the star color

Features

  • No JavaScript: native radio inputs and CSS, works in Server Components and before hydration
  • Keyboard: native radio group: Tab enters it once, the arrow keys move the score
  • Touch friendly: the hover preview sits behind @media (hover: hover), so stars do not get stuck
  • Reduced motion: the ring and the flash are turned off when the system asks for less motion
  • No dependencies: shapes are inline SVG, keyframes live in the component