Star Rating
Interactive star rating with hover fill.
<div class="flex items-center gap-1" role="radiogroup" aria-label="Rate this product">
<button aria-label="1 star" class="text-slate-300 hover:text-amber-400 hover:scale-110 transition-all">
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 20 20"><path d="M10 15l-5.9 3.6 1.6-6.8L.9 7.2l7-0.6L10 0l2.1 6.6 7 .6-4.8 4.6 1.6 6.8z"/></svg>
</button>
<button aria-label="2 stars" class="text-slate-300 hover:text-amber-400 hover:scale-110 transition-all">
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 20 20"><path d="M10 15l-5.9 3.6 1.6-6.8L.9 7.2l7-0.6L10 0l2.1 6.6 7 .6-4.8 4.6 1.6 6.8z"/></svg>
</button>
<button aria-label="3 stars" class="text-slate-300 hover:text-amber-400 hover:scale-110 transition-all">
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 20 20"><path d="M10 15l-5.9 3.6 1.6-6.8L.9 7.2l7-0.6L10 0l2.1 6.6 7 .6-4.8 4.6 1.6 6.8z"/></svg>
</button>
<button aria-label="4 stars" class="text-amber-400 hover:scale-110 transition-all">
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 20 20"><path d="M10 15l-5.9 3.6 1.6-6.8L.9 7.2l7-0.6L10 0l2.1 6.6 7 .6-4.8 4.6 1.6 6.8z"/></svg>
</button>
<button aria-label="5 stars" class="text-amber-400 hover:scale-110 transition-all">
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 20 20"><path d="M10 15l-5.9 3.6 1.6-6.8L.9 7.2l7-0.6L10 0l2.1 6.6 7 .6-4.8 4.6 1.6 6.8z"/></svg>
</button>
<span class="ml-2 text-sm font-bold text-slate-600 dark:text-slate-300">4.0</span>
</div>Free to use in personal and commercial projects. No attribution required.
Variants
Same component, different looks. Preview each one live and copy the code you like.
Small
Use the small stars in table rows and compact review lists.
Hearts
Hearts suit favorites and wishlists better than review scores.
With review count
Show the review count on product pages where social proof drives clicks.
About this star rating
Star ratings are the universal shorthand for quality: 4.8 stars tells the story faster than any paragraph. This css star rating shows the display variant (4 of 5 filled) with hover states that hint at interactivity. The amber-400 fill on a slate-300 base is the classic rating look.
For a truly interactive rating, add JavaScript that fills stars up to the hovered one and locks the selection on click. The buttons already have aria-labels; add aria-pressed or a radiogroup pattern for screen readers.
Show the numeric score next to the stars (4.0) and the review count when space allows ("4.8 · 2.3k reviews"). Stars without context feel decorative; stars with numbers feel trustworthy.
Few symbols carry as much meaning as five stars: a 4.8 with 2.3k reviews next to it tells the quality story faster than any paragraph, in any language. The display variant compresses social proof into a glance; the input variant harvests opinions with almost zero effort from the user. Both work because five stars are understood everywhere without explanation.
Five buttons sit in a flex row with role=radiogroup. Each star is an inline SVG using fill=currentColor, so Tailwind text colors control it: text-slate-300 empty, text-amber-400 filled, with hover:scale-110 transition-all for tactility. Interactive JavaScript fills every star up to the hovered one as a preview and locks the selection on click. Each button carries an aria-label like 3 stars for screen readers.
Half stars come from layering: a slate star with an amber star clipped to 50% width via overflow-hidden on top. Use w-4 stars inline in cards and w-8 for dedicated rating inputs. Always show the numeric score beside the stars; stars without numbers feel decorative, stars with 4.8 beside them feel trustworthy.
The data-quality mistake is letting users submit with zero stars selected because the control defaults to all-empty and nothing validates it. You end up with blank ratings polluting the average. Require a selection before submit, or preselect the current average so the control always holds a meaningful value.
Where to use it
- ✓ Product reviews
- ✓ App store listings
- ✓ Testimonial scores
- ✓ Service ratings
Customization tips
For half stars, overlay two stars with overflow hidden at 50% width. Use smaller stars (w-4) inline in cards and larger (w-8) for input. The numeric label is optional but recommended.
Design notes
When to use
Star ratings fit moments when you want a quick opinion with almost no effort, like rating a product after purchase or a support chat after it ends. The hover fill that previews the score before clicking makes the control feel playful and forgiving. Showing the current average next to the input, as this one does with 4.0, sets expectations before the user commits.
What to avoid
Do not use stars where you need a precise answer, they compress everything into five buckets and hide why someone picked three instead of four. Avoid tiny tap targets on mobile, stars smaller than a fingertip cause mis-taps and angry re-taps. Also skip the hover preview on touch devices where hover does not exist, or the control will feel dead.
Accessibility
This set already uses radiogroup and labeled buttons, which is the right pattern, keep it. Make sure the selected value is announced on change and that the control works fully from the keyboard with arrow keys.
Frequently asked questions
How do I make an interactive star rating?
Use buttons for each star. On hover, fill stars up to the hovered index with JavaScript. On click, lock the selection. Use SVG stars with fill: currentColor so text-amber-400 controls the fill.
How do I show half stars?
Layer two stars: a gray star behind and an amber star clipped to 50% width in front using overflow-hidden. This is the standard half-star technique.
Should I use emoji stars or SVG?
SVG. Emoji stars render inconsistently across platforms and cannot be precisely colored. SVG gives you full control.
How do I make a star rating with radio buttons?
Render five radio inputs with labels containing star SVGs, visually hide the radios, and use the :checked ~ label selector to fill the selected star and all before it. The labels act as the clickable targets. This gives you a fully interactive rating with zero JavaScript that also submits in a form.
How do I show an average rating like 4.3 stars?
For read-only averages, layer two rows of five stars: gray stars underneath and gold stars on top clipped to (rating / 5 * 100)% width with overflow hidden. This renders fractional fills like 4.3 precisely. Add an aria-label such as "Rated 4.3 out of 5" for screen readers.
How do I add hover preview to star ratings?
In the radio-button technique, add a label:hover ~ label rule that fills stars up to the hovered one, giving a live preview before clicking. With JavaScript, listen for mouseover on each star and fill up to that index, clearing on mouseleave if nothing is selected. Keep the preview color slightly lighter than the selected state.
Related elements
Saved successfully
Your changes are live.
Toast Notification
Slide-in toast notification with icon and close button.
Progress Bar
Animated progress bar with striped variant.
Success. Your profile has been updated.
Warning. Your trial ends in 3 days.
Error. Payment failed. Try again.
Info. New features are available.
Alert Banner
Dismissible alert banner in 4 variants.