Rating

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

PropTypeDefaultDescription
valuenumber—Current rating value
onChange(value: number) => void—Callback when rating changes
maxnumber5Maximum rating value
size'sm' | 'md' | 'lg' | 'xl''md'Icon size
variant'star' | 'heart' | 'thumbs''star'Icon variant
allowHalfbooleanfalseAllow half-value selection
showValuebooleanfalseDisplay numeric value
disabledbooleanfalseDisable interaction
readOnlybooleanfalseMake read-only
labelstring—Label text
errorstring—Error message
helperTextstring—Helper text
emptyColorstring—Custom empty state color (Tailwind class)
fillColorstring—Custom fill color (Tailwind class)
hoverColorstring—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 error

Keyboard Navigation

KeyAction
TabFocus the rating (one tab stop, on the selected icon)
Arrow Right / Arrow UpIncrease by one step (0.5 with allowHalf)
Arrow Left / Arrow DownDecrease by one step, down to the lowest step
Home / EndJump to the lowest step / the maximum
Enter / SpaceSelect 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