JSFiddle - React, Tailwind, and code Playground
by Pangur Ban
HTML
<div id="rating">
<input id="star-5" type="radio" name="reviewStars">
<label title="gorgeous" for="star-5"></label>
<input id="star-4" type="radio" name="reviewStars">
<label title="good" for="star-4"></label>
<input id="star-3" type="radio" name="reviewStars">
<label title="regular" for="star-3"></label>
<input id="star-2" type="radio" name="reviewStars">
<label title="poor" for="star-2"></label>
<input id="star-1" type="radio" name="reviewStars">
<label title="bad" for="star-1"></label>
</div>
CSS
#rating {
overflow: hidden;
position: relative;
display: inline-block;
border: 1px solid #888;
border-left: none;
}
#rating input {
opacity: 0;
position: absolute;
top: 0;
z-index: 0;
width: 43px;
height: 40px;
}
#rating label{
position: relative;
z-index: 1;
float: right;
height: 40px;
width: 43px;
border-left: 1px solid #888;
cursor: pointer;
}
#rating input:checked ~ label,
#rating label:hover,
#rating label:hover ~ label{
background: #ccc;
}