Join our Discord Community

React Rating Button

React rating button with interactive star ratings and hover effects. Lucide icons with keyboard navigation and form integration using TypeScript and shadcn/ui.

Building rating interactions?

Join our Discord community for help from other developers.


Rating systems are everywhere—product reviews, content feedback, skill assessments. But most are just static star icons that highlight on click. Basic. Uninspiring. No hover previews or smooth transitions. Meanwhile, users expect rich feedback that guides their selection and confirms their choice. This React component gives you interactive star rating buttons with hover previews, smooth animations, and comprehensive accessibility that make every rating feel intentional and satisfying.

Loading component...

Built for React applications with TypeScript and Next.js. Uses Lucide icons for crisp star rendering at any size. The component doesn't just track ratings—it provides hover previews, keyboard navigation, and smooth transitions between states. Form integration works seamlessly with React Hook Form and other libraries. Perfect for shadcn/ui design systems with consistent styling patterns.

Why most rating components feel disconnected

Developers throw five star icons in a row and add click handlers. Maybe they change the fill color if they're being thorough. The problem? Users can't preview their selection before committing. There's no visual feedback during interaction. Keyboard users get ignored entirely. It's functional but not user-friendly.

This component provides hover previews that show exactly what rating you're about to select. Smooth transitions between states create visual continuity. Keyboard navigation with arrow keys feels natural and accessible. The compound component pattern gives you full control over styling while handling all the complex interaction states automatically.

Built with proper ARIA attributes and screen reader support, so all users can provide meaningful feedback regardless of how they interact with your interface.

Installation

npx shadcn@latest add https://www.shadcn.io/registry/rating.json
npx shadcn@latest add https://www.shadcn.io/registry/rating.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/rating.json
bunx shadcn@latest add https://www.shadcn.io/registry/rating.json

Examples

Style Variations

Different colors and sizes for various UI contexts:

Loading component...

Interactive States

Controlled, read-only, and interactive rating examples:

Loading component...

Features

  • Interactive star buttons with click and hover rating selection using JavaScript events
  • Hover preview states showing rating selection before confirmation
  • Keyboard navigation with arrow key support and accessible focus management
  • Form integration with hidden input fields for seamless form library compatibility
  • Customizable appearance with star count, size, colors, and icons using Tailwind CSS
  • Read-only mode for display-only ratings with proper ARIA attributes
  • TypeScript definitions with complete interface definitions and prop validation
  • Accessible design with comprehensive ARIA support and screen reader compatibility
  • Compound component pattern for flexible composition and styling control
  • Lucide icon integration for crisp, scalable star rendering at any size

Use Cases

This free open source React component works perfectly for:

  • Product reviews - Customer feedback and rating collection systems built with Next.js
  • Content rating - Article, video, and media quality assessments using TypeScript
  • Skill assessment - User proficiency and experience level indicators
  • Satisfaction surveys - Service quality and experience feedback forms
  • Course evaluation - Educational content and instructor rating systems
  • Restaurant reviews - Food and service quality rating interfaces
  • App store ratings - Software and mobile app user feedback collection
  • Performance reviews - Employee and team assessment rating tools

API Reference

Rating

The container component providing context for all rating functionality.

PropTypeDefaultDescription
defaultValuenumber0Initial rating value for uncontrolled mode
valuenumber-Current rating value for controlled mode
onValueChange(value: number) => void-Callback when rating value changes
maxnumber5Maximum rating value (number of stars)
readOnlybooleanfalseDisables interaction and shows display-only mode
disabledbooleanfalseDisables all rating interactions
namestring-Form input name for form integration
requiredbooleanfalseMakes rating selection required for forms
classNamestring-Additional CSS classes for container

RatingButton

Individual star button component for rating selection.

PropTypeDefaultDescription
sizenumber24Icon size in pixels for consistent scaling
classNamestring-Additional CSS classes for star styling
iconReact.ElementTypeStarCustom icon component (must accept size prop)
filledIconReact.ElementTypeStarIcon for filled/selected state
emptyIconReact.ElementTypeStarIcon for empty/unselected state
...propsButtonHTMLAttributes-All native button props supported

Rating States

StateVisualInteractionUse Case
emptyOutlined starsClickable, hoverableUnrated content
filledSolid starsClickable, hoverableCurrent rating display
hoverPreview fillTemporary highlightSelection preview
readOnlyStatic displayNo interactionDisplay existing ratings
disabledMuted appearanceNo interactionUnavailable rating

Keyboard Navigation

KeyActionDescription
Arrow RightNext starIncreases rating by 1
Arrow LeftPrevious starDecreases rating by 1
HomeFirst starSets rating to 1
EndLast starSets rating to maximum
Space/EnterConfirmConfirms current rating selection

Common gotchas

Star count changes: Changing the max prop after mount can cause rating value inconsistencies. Either reset the value when changing max or validate that existing values don't exceed the new maximum.

Icon sizing issues: Custom icons must accept a size prop for consistent scaling. Lucide icons work perfectly, but custom SVGs need to implement size-based width/height attributes.

Form integration timing: When using with form libraries, ensure the rating component's name prop matches your form schema. The hidden input updates synchronously with rating changes for proper validation.

Hover state conflicts: On touch devices, hover states can persist after touch. The component handles this, but custom CSS hover styles might interfere with touch interactions.

Accessibility overrides: Custom styling can interfere with accessibility features. Ensure sufficient color contrast and don't remove focus indicators when customizing appearance.

Controlled vs uncontrolled: Mixing controlled and uncontrolled usage patterns can cause state synchronization issues. Choose one pattern and stick with it throughout your component hierarchy.

You might also like

Explore other interactive button components for React applications:

Questions developers actually ask