Snippets Layout

Bootstrap 5 Star Rating Form

A review card with five clickable stars that fill on hover and selection, a live rating label, an optional comment box and a submit button.

Bootstrap 5 No jQuery Mar 2020 2.1K views

<section class="wdw-stage">
  <div class="container" style="max-width:520px">
    <div class="wdw-card p-4 p-md-5 text-center">
      <form id="ratingForm" novalidate>
        <div class="wdw-icon mx-auto mb-3" aria-hidden="true">
          <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2.8l2.78 5.64 6.22.9-4.5 4.39 1.06 6.2L12 17.0l-5.56 2.93 1.06-6.2L3 9.34l6.22-.9z"/></svg>
        </div>
        <h1 class="wdw-heading h3 mb-1">How was your experience?</h1>
        <p class="wdw-muted mb-4">Your rating helps us make things better.</p>

        <fieldset class="border-0 p-0 m-0">
          <legend class="visually-hidden">Rating</legend>
          <div class="sr-group d-flex flex-row-reverse justify-content-center gap-1"><input type="radio" class="sr-input" name="rating" id="star5" value="5" aria-describedby="srLabel"><label for="star5" class="sr-star" title="Excellent"><span class="visually-hidden">5 stars - Excellent</span><svg viewBox="0 0 24 24" width="52" height="52" aria-hidden="true"><path d="M12 2.8l2.78 5.64 6.22.9-4.5 4.39 1.06 6.2L12 17.0l-5.56 2.93 1.06-6.2L3 9.34l6.22-.9z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg></label><input type="radio" class="sr-input" name="rating" id="star4" value="4" aria-describedby="srLabel"><label for="star4" class="sr-star" title="Great"><span class="visually-hidden">4 stars - Great</span><svg viewBox="0 0 24 24" width="52" height="52" aria-hidden="true"><path d="M12 2.8l2.78 5.64 6.22.9-4.5 4.39 1.06 6.2L12 17.0l-5.56 2.93 1.06-6.2L3 9.34l6.22-.9z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg></label><input type="radio" class="sr-input" name="rating" id="star3" value="3" aria-describedby="srLabel"><label for="star3" class="sr-star" title="Good"><span class="visually-hidden">3 stars - Good</span><svg viewBox="0 0 24 24" width="52" height="52" aria-hidden="true"><path d="M12 2.8l2.78 5.64 6.22.9-4.5 4.39 1.06 6.2L12 17.0l-5.56 2.93 1.06-6.2L3 9.34l6.22-.9z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg></label><input type="radio" class="sr-input" name="rating" id="star2" value="2" aria-describedby="srLabel"><label for="star2" class="sr-star" title="Fair"><span class="visually-hidden">2 stars - Fair</span><svg viewBox="0 0 24 24" width="52" height="52" aria-hidden="true"><path d="M12 2.8l2.78 5.64 6.22.9-4.5 4.39 1.06 6.2L12 17.0l-5.56 2.93 1.06-6.2L3 9.34l6.22-.9z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg></label><input type="radio" class="sr-input" name="rating" id="star1" value="1" aria-describedby="srLabel"><label for="star1" class="sr-star" title="Poor"><span class="visually-hidden">1 star - Poor</span><svg viewBox="0 0 24 24" width="52" height="52" aria-hidden="true"><path d="M12 2.8l2.78 5.64 6.22.9-4.5 4.39 1.06 6.2L12 17.0l-5.56 2.93 1.06-6.2L3 9.34l6.22-.9z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg></label></div>
        </fieldset>
        <p class="fw-semibold mt-3 mb-4" id="srLabel" aria-live="polite">Select a rating</p>

        <div class="form-floating mb-3 text-start">
          <textarea class="form-control" id="srComment" placeholder="Tell us more (optional)"></textarea>
          <label for="srComment">Tell us more (optional)</label>
        </div>
        <button type="submit" class="btn btn-primary rounded-pill w-100" id="srSubmit">Submit rating</button>
      </form>

      <div id="srOk" class="d-none py-3" role="status" tabindex="-1">
        <div class="sr-sum d-flex justify-content-center gap-1 mb-3" id="srSum"><svg class="sr-sum-star" viewBox="0 0 24 24" width="36" height="36" aria-hidden="true"><path d="M12 2.8l2.78 5.64 6.22.9-4.5 4.39 1.06 6.2L12 17.0l-5.56 2.93 1.06-6.2L3 9.34l6.22-.9z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg><svg class="sr-sum-star" viewBox="0 0 24 24" width="36" height="36" aria-hidden="true"><path d="M12 2.8l2.78 5.64 6.22.9-4.5 4.39 1.06 6.2L12 17.0l-5.56 2.93 1.06-6.2L3 9.34l6.22-.9z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg><svg class="sr-sum-star" viewBox="0 0 24 24" width="36" height="36" aria-hidden="true"><path d="M12 2.8l2.78 5.64 6.22.9-4.5 4.39 1.06 6.2L12 17.0l-5.56 2.93 1.06-6.2L3 9.34l6.22-.9z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg><svg class="sr-sum-star" viewBox="0 0 24 24" width="36" height="36" aria-hidden="true"><path d="M12 2.8l2.78 5.64 6.22.9-4.5 4.39 1.06 6.2L12 17.0l-5.56 2.93 1.06-6.2L3 9.34l6.22-.9z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg><svg class="sr-sum-star" viewBox="0 0 24 24" width="36" height="36" aria-hidden="true"><path d="M12 2.8l2.78 5.64 6.22.9-4.5 4.39 1.06 6.2L12 17.0l-5.56 2.93 1.06-6.2L3 9.34l6.22-.9z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg></div>
        <h2 class="wdw-heading h3 mb-1">Thank you!</h2>
        <p class="wdw-muted mb-4" id="srSumText">Thanks for your feedback.</p>
        <button type="button" class="btn btn-outline-secondary rounded-pill" id="srAgain">Rate again</button>
      </div>
    </div>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.