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.
Powered by
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.
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:
Interactive States
Controlled, read-only, and interactive rating examples:
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.
Prop | Type | Default | Description |
---|---|---|---|
defaultValue | number | 0 | Initial rating value for uncontrolled mode |
value | number | - | Current rating value for controlled mode |
onValueChange | (value: number) => void | - | Callback when rating value changes |
max | number | 5 | Maximum rating value (number of stars) |
readOnly | boolean | false | Disables interaction and shows display-only mode |
disabled | boolean | false | Disables all rating interactions |
name | string | - | Form input name for form integration |
required | boolean | false | Makes rating selection required for forms |
className | string | - | Additional CSS classes for container |
RatingButton
Individual star button component for rating selection.
Prop | Type | Default | Description |
---|---|---|---|
size | number | 24 | Icon size in pixels for consistent scaling |
className | string | - | Additional CSS classes for star styling |
icon | React.ElementType | Star | Custom icon component (must accept size prop) |
filledIcon | React.ElementType | Star | Icon for filled/selected state |
emptyIcon | React.ElementType | Star | Icon for empty/unselected state |
...props | ButtonHTMLAttributes | - | All native button props supported |
Rating States
State | Visual | Interaction | Use Case |
---|---|---|---|
empty | Outlined stars | Clickable, hoverable | Unrated content |
filled | Solid stars | Clickable, hoverable | Current rating display |
hover | Preview fill | Temporary highlight | Selection preview |
readOnly | Static display | No interaction | Display existing ratings |
disabled | Muted appearance | No interaction | Unavailable rating |
Keyboard Navigation
Key | Action | Description |
---|---|---|
Arrow Right | Next star | Increases rating by 1 |
Arrow Left | Previous star | Decreases rating by 1 |
Home | First star | Sets rating to 1 |
End | Last star | Sets rating to maximum |
Space/Enter | Confirm | Confirms 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:
Icon Button
Animated icon buttons with particle burst effects
Counter Button
Animated counter with increment/decrement buttons
Flip Button
3D flip animations with smooth physics transitions
Liquid Button
Animated buttons with fluid fill effects
Questions developers actually ask
React Magnetic Button
React magnetic button with animated particles that attract to center on hover. Features Framer Motion spring physics and customizable particle effects with TypeScript and shadcn/ui.
React Ripple Button
React ripple button with Material Design click animations. Position-aware ripple effects and multiple color variants with TypeScript and shadcn/ui styling.