Interactive star rating components for collecting user ratings and feedback. Perfect for product reviews, service quality assessments, satisfaction surveys, and any scenario where you need visual rating input.
Every code snippet below is fully editable! Feel free to modify the code, experiment with different values, and see your changes reflected instantly in the live preview on the right.
Use the play button to run different snippet, or the refresh button to restore the original example.
Let's start with an empty form function. This is where we'll build our star rating form step by step.
Add a simple 5-star rating field. By default, star ratings display 5 stars that users can click to select their rating.
addStarRating() to add a star rating field. Click any star to set the rating - all stars up to and including the clicked one will be filled. Need a 10-point scale? Use maxStars to set any number of stars. You can also set a defaultValue for pre-selected ratings.
maxStars property controls how many stars are displayed. Use defaultValue to pre-select a rating (e.g., 7 out of 10). Enable half-star precision for more granular ratings. When enabled, clicking on the left half of a star selects a half value (e.g., 3.5 stars).
allowHalf: true to enable half-star ratings. Users can click on the left half of a star for .5 values (like 2.5, 3.5, etc.). Great for movie or product reviews! Customize the appearance with different sizes and colors. Choose from four sizes (sm, md, lg, xl) and set custom colors for filled and empty states.
size: 'sm' | 'md' | 'lg' | 'xl' for small, medium, large, or extra large stars. Customize colors with filledColor and emptyColor using any valid CSS color. Control horizontal alignment of stars and toggle the counter display. Perfect for different layout requirements.
alignment: 'left' | 'center' | 'right' to position stars. Set showCounter: false to hide the "3/5" counter. Add a fun confetti animation when users select the maximum rating! Works with both user input and computed values.
showConfettiOnMax: true to trigger confetti when max is reached. This also works with computedValue - try setting both Quality and Value to 5 stars! Use computedValue to display a calculated rating as read-only output. This is useful for showing averages, aggregated scores, or any derived rating.
computedValue, the star rating becomes read-only and automatically updates when the source ratings change. Perfect for showing average ratings! Control whether users can change their mind by clicking the same star again to clear their selection.
allowDeselect: true lets users clear their selection by clicking the same rating twice. Set to false to make the choice permanent - once a rating is selected, it cannot be removed. Make star ratings required to ensure users provide feedback before submitting the form. Required ratings show a validation error until a selection is made.
isRequired: true to require a rating. The field will show a red asterisk (*) next to the label and display an error message if the user tries to submit without selecting a rating. Try clicking Submit without selecting any stars to see the validation in action! Let's build a complete service feedback form with multiple rating categories. This demonstrates how star ratings work alongside other form fields, including required validation.
Great job! You've learned how to add interactive star ratings to your forms. Ready to explore more form components?
Continue to Slider TutorialOther learning paths: