</> ConvertAtlas Developer Tools
Bootstrap 5 · Beginner

Hover Star Rating Input

A star rating with hover preview, selection and a label.

Requires Bootstrap 5. Add the CDN tags below to your page (styles in <head>, scripts before </body>). The downloaded file already includes them.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<div class="card border-0 shadow-sm text-center" style="max-width:280px"><div class="card-body"><div class="fs-3" id="riStars" style="cursor:pointer;color:#ffc107"><span data-v="1">★</span><span data-v="2">★</span><span data-v="3">★</span><span data-v="4">★</span><span data-v="5">★</span></div><small class="text-secondary" id="riOut">Click to rate</small></div></div>
var stars=document.querySelectorAll("#riStars span"),out=document.getElementById("riOut"),sel=0;function paint(n){stars.forEach(function(s,i){s.style.opacity=i<n?"1":".3"})}stars.forEach(function(s){s.onmouseenter=function(){paint(+s.dataset.v)};s.onclick=function(){sel=+s.dataset.v;out.textContent="Rated "+sel+"/5"}});document.getElementById("riStars").onmouseleave=function(){paint(sel)};paint(0);
Free to use.This component uses Bootstrap 5 (linked above). Copy any file, or download a ready-to-open .html page with the CDN links already included.