Setup took ten minutes and the team picked it up on day one.
Rating
Stars for reviews and feedback. The stars you click are real radio buttons, so arrow keys work and forms get the value. A read-only score can show any fraction, like 4.3. The stars are Moey Icons star and star-filled.
Basic
A fieldset.rating with one label.rating-star per star. Every input shares a name and has its own aria-label.
<fieldset class="rating">
<legend class="visually-hidden">Rate this course</legend>
<label class="rating-star"><input type="radio" name="rt-course" value="1" aria-label="1 star"></label>
<label class="rating-star"><input type="radio" name="rt-course" value="2" aria-label="2 stars"></label>
<label class="rating-star"><input type="radio" name="rt-course" value="3" aria-label="3 stars" checked></label>
<label class="rating-star"><input type="radio" name="rt-course" value="4" aria-label="4 stars"></label>
<label class="rating-star"><input type="radio" name="rt-course" value="5" aria-label="5 stars"></label>
</fieldset>With a label
Add data-momo-rating-clear to let a second click on the picked star clear it (no rating).
Click the same star again to clear it.
<div class="form-field">
<span class="form-label" id="rt-q">How was your support call?</span>
<fieldset class="rating rating-lg" aria-labelledby="rt-q" data-momo-rating-clear>
<label class="rating-star"><input type="radio" name="rt-call" value="1" aria-label="1 star, bad"></label>
<label class="rating-star"><input type="radio" name="rt-call" value="2" aria-label="2 stars"></label>
<label class="rating-star"><input type="radio" name="rt-call" value="3" aria-label="3 stars"></label>
<label class="rating-star"><input type="radio" name="rt-call" value="4" aria-label="4 stars"></label>
<label class="rating-star"><input type="radio" name="rt-call" value="5" aria-label="5 stars, great"></label>
</fieldset>
<p class="form-hint">Click the same star again to clear it.</p>
</div>Read-only score
A .rating-static with data-value (and data-max, 5 by default). It fills any fraction and names itself for screen readers ("4.3 out of 5"). Put text next to it in a .rating-row.
<div class="rating-row">
<span class="rating-static" data-value="4.3"></span>
<span class="rating-text">4.3 <span class="rating-count">(128 reviews)</span></span>
</div>Colors and sizes
Stars are yellow by default. .rating-<color> for any color, .rating-sm and .rating-lg for both kinds.
<div class="form-grid">
<span class="rating-static rating-sm rating-pink" data-value="3.5"></span>
<span class="rating-static rating-green" data-value="4"></span>
<span class="rating-static rating-lg rating-violet" data-value="2.5"></span>
</div>In a review card
<article class="card card-body">
<div class="person">
<span class="avatar bg-cyan" role="img" aria-label="Mara Lindqvist">ML</span>
<span class="person-text"><span class="person-name">Mara Lindqvist</span><span class="person-sub">2 days ago</span></span>
</div>
<span class="rating-static rating-sm" data-value="5"></span>
<p>Setup took ten minutes and the team picked it up on day one.</p>
</article>Disabled and read-only
disabled on the fieldset grays it out. .rating-readonly keeps the colors but ignores clicks (use .rating-static when it never changes).
<fieldset class="rating rating-sm" disabled>
<legend class="visually-hidden">Disabled rating</legend>
<label class="rating-star"><input type="radio" name="rt-off" value="1" aria-label="1 star" checked></label>
<label class="rating-star"><input type="radio" name="rt-off" value="2" aria-label="2 stars"></label>
<label class="rating-star"><input type="radio" name="rt-off" value="3" aria-label="3 stars"></label>
<label class="rating-star"><input type="radio" name="rt-off" value="4" aria-label="4 stars"></label>
<label class="rating-star"><input type="radio" name="rt-off" value="5" aria-label="5 stars"></label>
</fieldset>JavaScript
Read the value like any radio group: form.elements['rt-course'].value, and listen to change. If you change data-value on a score, call Momo.slider.refresh(el).
Variables
| Variable | Default |
|---|---|
--rating-color | yellow |
--rating-empty | surface |
--rating-size | 1.75rem (score: 1.25rem) |