# Star Rating

> A clickable five-star rating built from radio buttons, with hover preview.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: rating, stars, review, radio, has
- Live preview: https://copy-css.com/snippets/star-rating
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<div class="rating">
  <label><input type="radio" name="rating" value="5" aria-label="5 stars">★</label>
  <label><input type="radio" name="rating" value="4" aria-label="4 stars" checked>★</label>
  <label><input type="radio" name="rating" value="3" aria-label="3 stars">★</label>
  <label><input type="radio" name="rating" value="2" aria-label="2 stars">★</label>
  <label><input type="radio" name="rating" value="1" aria-label="1 star">★</label>
</div>
```

## CSS

```css
/* Stars are listed 5 → 1 and displayed reversed */
.rating {
  display: inline-flex;
  flex-direction: row-reverse;
  gap: 4px;
  font-size: 34px;
  line-height: 1;
}

.rating input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.rating label {
  color: #d1d5db;
  cursor: pointer;
  transition: color 0.15s ease, transform 0.15s ease;
}

.rating label:hover,
.rating label:hover ~ label,
.rating label:has(input:checked),
.rating label:has(input:checked) ~ label {
  color: #f59e0b;
}

.rating label:hover {
  transform: scale(1.15);
}
```

## Notes

- This CSS Star Rating is 31 lines of pure CSS (0.5 KB) with no JavaScript and no dependencies. It uses transitions, transforms, Flexbox and the :has() selector.
- the :has() selector: Chrome 105+, Safari 15.4+, Firefox 121+.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
