Skip to the content
Konstruktor UI

Actions and inputs

Rating

fieldset.kui-rating is five native radios drawn as stars, for giving a rating. .kui-stars shows a rating that cannot be changed, such as the average of reviews.

CSS only

Examples

Give a rating

Each star is a radio with a hidden label (“4 of 5 stars”). Hover lights the stars up to the one under the pointer; the chosen ones are filled.

Your rating of the service
HTML
<fieldset class="kui-rating">
  <legend>Your rating of the service</legend>
  <label><input type="radio" name="rating-service" value="1"><span class="kui-visually-hidden">1 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" name="rating-service" value="2"><span class="kui-visually-hidden">2 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" name="rating-service" value="3"><span class="kui-visually-hidden">3 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" name="rating-service" value="4" checked><span class="kui-visually-hidden">4 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" name="rating-service" value="5"><span class="kui-visually-hidden">5 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
</fieldset>

With a visible question

The legend is hidden by the class. When the question must be seen, write it in a label next to the group and tie it with aria-labelledby.

How easy was it to find the form?
How easy was it to find the form?
HTML
<div class="kui-field">
  <span class="kui-label" id="rating-q">How easy was it to find the form?</span>
  <fieldset class="kui-rating" aria-labelledby="rating-q">
    <legend>How easy was it to find the form?</legend>
    <label><input type="radio" name="rating-easy" value="1"><span class="kui-visually-hidden">1 of 5 stars, very hard</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
    <label><input type="radio" name="rating-easy" value="2"><span class="kui-visually-hidden">2 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
    <label><input type="radio" name="rating-easy" value="3"><span class="kui-visually-hidden">3 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
    <label><input type="radio" name="rating-easy" value="4"><span class="kui-visually-hidden">4 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
    <label><input type="radio" name="rating-easy" value="5"><span class="kui-visually-hidden">5 of 5 stars, very easy</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  </fieldset>
</div>

A rating shown, not chosen

.kui-stars takes the size of the text around it. Give it role="img" and a name, and write the number and the count next to it.

4.3 · 128 reviews

„Brza i ljubazna usluga, preporučujem.“ Jelena Đurić, Kraljevo

HTML
<p class="kui-cluster"><span class="kui-stars" role="img" aria-label="4 of 5 stars"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg><svg class="kui-icon kui-icon--empty" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></span><span>4.3 · 128 reviews</span></p>
<p class="kui-cluster kui-text-sm kui-text-muted"><span class="kui-stars" role="img" aria-label="5 of 5 stars"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></span><span>„Brza i ljubazna usluga, preporučujem.“ Jelena Đurić, Kraljevo</span></p>

States

Every state

No star chosen: all outlines. Hover fills the stars up to the pointer. Keyboard focus rings the focused star. Disabled fades the group and it cannot be changed.

Not rated yet
Disabled
HTML
<fieldset class="kui-rating">
  <legend>Not rated yet</legend>
  <label><input type="radio" name="rating-s1" value="1"><span class="kui-visually-hidden">1 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" name="rating-s1" value="2"><span class="kui-visually-hidden">2 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" name="rating-s1" value="3"><span class="kui-visually-hidden">3 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" name="rating-s1" value="4"><span class="kui-visually-hidden">4 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" name="rating-s1" value="5"><span class="kui-visually-hidden">5 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
</fieldset>
<fieldset class="kui-rating">
  <legend>Disabled</legend>
  <label><input type="radio" disabled name="rating-s2" value="1"><span class="kui-visually-hidden">1 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" disabled name="rating-s2" value="2"><span class="kui-visually-hidden">2 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" disabled name="rating-s2" value="3" checked><span class="kui-visually-hidden">3 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" disabled name="rating-s2" value="4"><span class="kui-visually-hidden">4 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
  <label><input type="radio" disabled name="rating-s2" value="5"><span class="kui-visually-hidden">5 of 5 stars</span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#star"></use></svg></label>
</fieldset>

Classes and attributes

fieldset.kui-rating
The rating to choose. Its legend is hidden from view.
label > input type="radio" + .kui-visually-hidden + star
One star: the hidden radio, its spoken name and the icon.
.kui-stars
A rating shown: star icons, with .kui-icon--empty for the empty ones.
role="img" aria-label
On .kui-stars: the rating said in words.

Keyboard

Tab
Moves into the group, onto the chosen star.
Left or Right or Up or Down
Chooses the previous or next star.

Accessibility

  • It is a radio group, so a screen reader says “4 of 5 stars, radio button, 4 of 5”.
  • Every star is at least 44 by 44 pixels on a phone.
  • Filled and empty stars differ by fill, not only by colour.
  • A shown rating is one image with its name; the single stars are hidden.

Do and do not

Do

  • Name the two ends when they mean something, such as “very hard” and “very easy”.
  • Show the average with one decimal and the number of reviews.
  • Allow a rating to be sent without a written review.

Do not

  • Do not use stars for a yes or no question.
  • Do not show an average without the number of reviews.
  • Do not round 4.3 to five filled stars.