Rating
Forms
Feedback
Star rating input with multiple variants and half-value support. Ideal for reviews, feedback forms, and product ratings.
Preview
Click the stars to rate
Variants
Three icon variants: star, heart, and thumbs
Star (default)
Star Rating
Heart
Heart Rating
Thumbs Up
Thumbs Rating
Sizes
Four size options: sm, md, lg, and xl
Small
Small
Medium (default)
Medium
Large
Large
Extra Large
Extra Large
Half Rating
Allow half-star ratings with precise control
Allow half values
Click on left half of star for 0.5 increments
Current value: 3.5
States
Different states for various use cases
Read Only
Read Only
Disabled
Disabled
With Error
With Error
Please select a rating
Custom Colors
Override default colors with custom ones
Green Theme
Custom Star Colors
Purple Theme
Purple Theme
Custom Maximum
Change the maximum rating value
10 Stars
10 Stars
3 Hearts
3 Hearts
Props
Rating component API reference
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | — | Current rating value |
onChange | (value: number) => void | — | Callback when rating changes |
max | number | 5 | Maximum rating value |
size | 'sm' | 'md' | 'lg' | 'xl' | 'md' | Icon size |
variant | 'star' | 'heart' | 'thumbs' | 'star' | Icon variant |
allowHalf | boolean | false | Allow half-value selection |
showValue | boolean | false | Display numeric value |
disabled | boolean | false | Disable interaction |
readOnly | boolean | false | Make read-only |
label | string | — | Label text |
error | string | — | Error message |
helperText | string | — | Helper text |
emptyColor | string | — | Custom empty state color (Tailwind class) |
fillColor | string | — | Custom fill color (Tailwind class) |
hoverColor | string | — | Custom hover color (Tailwind class) |
Usage
Import and implementation example
import { Rating } from '@/components/ui/rating'
export default function Example() { const [rating, setRating] = useState(3)
return ( <> {/* Basic rating */} <Rating value={rating} onChange={setRating} />
{/* With label and value display */} <Rating label="Rate this product" value={rating} onChange={setRating} showValue size="lg" />
{/* Half-star rating with hearts */} <Rating value={rating} onChange={setRating} allowHalf variant="heart" />
{/* Custom colors */} <Rating value={4} showValue emptyColor="text-slate-200" fillColor="text-success-default" hoverColor="text-success-default" />
{/* Read-only display */} <Rating value={4.5} readOnly allowHalf /> </> )}Features
Built-in functionality
- Multiple variants: Star, heart, and thumbs icons
- Half-value support: Enable precise half-star ratings
- Four sizes: Small, medium, large, and extra large
- Custom colors: Override empty, fill, and hover colors
- Configurable max: Set custom maximum rating value
- Value display: Show numeric value alongside icons
- Hover preview: Visual feedback on hover
Accessibility
Accessibility considerations
ARIA Attributes
role="radiogroup" on the container, role="radio" with aria-checked on each iconEach icon is named like "3 of 5 stars" (half values read as "2.5 of 5 stars")Read-only mode renders role="img" with the value as its label and is not focusablearia-describedby links the helper or error text, aria-invalid marks an errorKeyboard Navigation
| Key | Action |
|---|---|
| Tab | Focus the rating (one tab stop, on the selected icon) |
| Arrow Right / Arrow Up | Increase by one step (0.5 with allowHalf) |
| Arrow Left / Arrow Down | Decrease by one step, down to the lowest step |
| Home / End | Jump to the lowest step / the maximum |
| Enter / Space | Select the focused icon, or clear it when already selected |
Notes
- Label is linked to the radiogroup with aria-labelledby
- Focus follows the selected value while using the arrow keys
- Disabled ratings are skipped by Tab
- Without onChange the rating is focusable but the value does not change