Moey extras
Rating
Stars people can pick — plain radio buttons underneath, so arrow keys, forms and validation work with no JavaScript.
<fieldset class="rating">
<legend class="visually-hidden">Rate this product</legend>
<input type="radio" name="stars" value="1" aria-label="1 star">
<input type="radio" name="stars" value="2" aria-label="2 stars">
<input type="radio" name="stars" value="3" aria-label="3 stars">
<input type="radio" name="stars" value="4" aria-label="4 stars" checked>
<input type="radio" name="stars" value="5" aria-label="5 stars">
</fieldset>
Hover to preview, click to pick. With the keyboard, Tab into it and use the arrow keys. The form sends the chosen value, and required on the first radio makes a rating mandatory.
In a review form
<fieldset class="rating rating-lg" aria-labelledby="rating-label" data-moey-clearable>
<input type="radio" name="rating" value="1" aria-label="1 star" required>
…
</fieldset>
data-moey-clearable lets people click the chosen star again to clear their pick.
Showing a score
.rating-static shows any value, fractions included — for averages and listings. Give it a role="img" and a label so screen readers hear the score.
4.6(1,284 reviews)
3.5
<span class="rating-static" data-value="4.6" role="img" aria-label="4.6 out of 5"></span>
Sizes, colors & hearts
<fieldset class="rating rating-sm">…</fieldset>
<fieldset class="rating theme-blue">…</fieldset>
<fieldset class="rating rating-heart rating-lg">…</fieldset>
Ten steps, read-only and disabled
<fieldset class="rating">…10 radios…</fieldset>
<fieldset class="rating" data-readonly>…</fieldset> <!-- shown and sent, can't be changed -->
<fieldset class="rating" disabled>…</fieldset> <!-- not sent with the form -->
| Class / attribute | What it does |
|---|---|
.rating (on a <fieldset>) + radios | Pickable stars. Any number of radios |
.rating-static + data-value="4.6" | A read-only score, any fraction. data-max="10" for a 10-star scale (default 5). In your CSS: --mo-rating-value / --mo-rating-max. |
.rating-sm · .rating-lg · --mo-rating-size | Sizes |
theme-* · --mo-rating-color · --mo-rating-empty | Colors (default amber) |
.rating-heart · --mo-rating-shape | Hearts, or any shape (an SVG mask) |
data-moey-clearable | Click the chosen star again to clear |
data-readonly · disabled | Can’t change it (still sent) · disabled (not sent) |