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)
Heart
Thumbs Up
Sizes
Four size options: sm, md, lg, and xl
Small
Medium (default)
Large
Extra Large
Half Rating
Allow half-star ratings with precise control
Current value: 3.5
States
Different states for various use cases
Read Only
Disabled
With Error
Custom Colors
Override default colors with custom ones
Green Theme
Purple Theme
Custom Maximum
Change the maximum rating value
10 Stars
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-emerald-500"
hoverColor="text-emerald-600"
/>
{/* 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
- Dark mode: Full dark mode support
Accessibility
Accessibility considerations
ARIA Attributes
Uses role="group" for rating containerIndividual stars are keyboard accessiblearia-label describes current ratingKeyboard Navigation
| Key | Action |
|---|---|
| Tab | Focus the rating component |
| Arrow Left/Right | Decrease/increase rating |
| Enter/Space | Set rating on focused star |
Notes
- Label associated with rating group
- Visual and text indicators for selection
- Error state announced to screen readers
- Disabled state prevents interaction