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

3 / 5

Variants

Three icon variants: star, heart, and thumbs

Star (default)

3 / 5

Heart

4 / 5

Thumbs Up

2 / 5

Sizes

Four size options: sm, md, lg, and xl

Small

4 / 5

Medium (default)

4 / 5

Large

4 / 5

Extra Large

4 / 5

Half Rating

Allow half-star ratings with precise control

3.5 / 5
Click on left half of star for 0.5 increments

Current value: 3.5

States

Different states for various use cases

Read Only

4 / 5

Disabled

3 / 5

With Error

Please select a rating

Custom Colors

Override default colors with custom ones

Green Theme

4 / 5

Purple Theme

3 / 5

Custom Maximum

Change the maximum rating value

10 Stars

7 / 10

3 Hearts

2 / 3

Props

Rating component API reference

PropTypeDefaultDescription
valuenumberCurrent rating value
onChange(value: number) => voidCallback 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
labelstringLabel text
errorstringError message
helperTextstringHelper text
emptyColorstringCustom empty state color (Tailwind class)
fillColorstringCustom fill color (Tailwind class)
hoverColorstringCustom 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 rating

Keyboard Navigation

KeyAction
TabFocus the rating component
Arrow Left/RightDecrease/increase rating
Enter/SpaceSet 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