Components

Rating

An accessible React star rating component built with Tailwind CSS and Motion: hover to preview, click or use the arrow keys to rate, half-star steps, and a small pop as the stars fill. Read-only mode fills fractional averages precisely, any lucide icon, count, size or color works, and a hidden input submits the value with your form.

  • Hover preview
  • Half stars
  • Pop on select
  • Read-only averages
  • Custom icons
  • Form-ready
  • Slider a11y

Installation

$ npx shadcn@latest add https://duskui.com/r/rating.json

Usage

review.tsx
"use client"

import * as React from "react"
import { Rating } from "@/components/dusk/rating/rating"

export function Review() {
  const [stars, setStars] = React.useState(0)
  return <Rating value={stars} onValueChange={setStars} label="Rate this product" />
}

Examples

Half stars & read-only

allowHalf picks the left or right half of each star. With readOnly any fraction — like an average of 4.7 — fills to the exact width.

Your rating

3.5 / 5

  • Aurora Hotel

    4.7 · 1,284
  • Harbor Loft

    4.2 · 312
  • Cedar Cabin

    3.6 · 89

Icons, count, size & color

Pass any lucide icon to icon, change count, set size to a preset or pixels, and tint it with color. getValueText customises what screen readers hear.

Hearts
Energy
Spice

In a form

Give it a name and the value is submitted through a hidden input, so it works with FormData and server actions.

Food

Service

API Reference

Also accepts any div attribute.

PropTypeDefaultDescription
valuenumber—Controlled value.
defaultValuenumber0Starting value when uncontrolled.
onValueChange(value: number) => void—Called when the user picks a value.
countnumber5Number of icons.
allowHalfbooleanfalseAllow 0.5 steps.
readOnlybooleanfalseDisplay only; renders as an image with a spoken value.
disabledbooleanfalseDims the rating and removes it from the tab order.
clearablebooleantrueClicking the current value again resets to 0.
size"sm" | "md" | "lg" | number"md"Icon size preset (18 / 24 / 32px) or pixels.
colorstringvar(--color-primary)Fill color.
iconComponentType<LucideProps>StarIcon to render.
namestring—Renders a hidden input with this name.
labelstring"Rating"Accessible name.
getValueText(value, count) => string"3 out of 5 stars"Spoken value text.

Accessibility

  • Interactive ratings are a single focusable role="slider" with aria-valuenow, aria-valuemax and value text like “3.5 out of 5 stars”.
  • Arrow keys change the value by one step (half a star with allowHalf), Home clears it, End fills every star, and number keys jump straight to a value.
  • Read-only ratings render as role="img" with a label such as “Aurora Hotel: 4.7 out of 5 stars”, so averages are read once instead of star by star.
  • The icons are decorative and hidden from assistive technology.
  • Hover preview is mouse-only; touch taps set the value directly.
  • With prefers-reduced-motion the pop and fill transitions are skipped.