Snippets Bar

Bootstrap 5 Comment Form with Star Rating

A review form with an interactive five-star rating, a floating-label comment box with a character counter and an inline confirmation after posting.

Bootstrap 5 No jQuery May 2020 9.8K views

<section class="cr-section wdw-stage">
  <div class="container" style="max-width:980px">
    <div class="wdw-card overflow-hidden">
      <div class="row g-0">
        <aside class="col-md-5 p-4 p-lg-5 bg-body-tertiary" aria-label="Rating summary">
          <span class="wdw-eyebrow mb-2">Customer reviews</span>
          <div class="d-flex align-items-end gap-2 mb-1"><span class="display-3 wdw-heading lh-1">4.8</span><span class="text-body-secondary mb-2">out of 5</span></div>
          <div class="d-flex gap-1 text-warning mb-1" role="img" aria-label="4.8 out of 5 stars"><svg class="" width="22" height="22" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.9L12 17.8 5.8 21l1.2-6.9-5-4.9 6.9-1z"/></svg><svg class="" width="22" height="22" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.9L12 17.8 5.8 21l1.2-6.9-5-4.9 6.9-1z"/></svg><svg class="" width="22" height="22" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.9L12 17.8 5.8 21l1.2-6.9-5-4.9 6.9-1z"/></svg><svg class="" width="22" height="22" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.9L12 17.8 5.8 21l1.2-6.9-5-4.9 6.9-1z"/></svg><svg class="" width="22" height="22" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.9L12 17.8 5.8 21l1.2-6.9-5-4.9 6.9-1z"/></svg></div>
          <p class="small text-body-secondary mb-4">Based on 1,284 reviews</p>
          <ul class="list-unstyled d-grid gap-2 small mb-0">
            <li class="d-flex align-items-center gap-2"><span class="cr-bar-l">5</span><div class="progress flex-grow-1" style="height:6px" role="progressbar" aria-label="5 stars" aria-valuenow="82" aria-valuemin="0" aria-valuemax="100"><div class="progress-bar bg-warning" style="width:82%"></div></div><span class="cr-bar-r text-body-secondary">82%</span></li>
            <li class="d-flex align-items-center gap-2"><span class="cr-bar-l">4</span><div class="progress flex-grow-1" style="height:6px" role="progressbar" aria-label="4 stars" aria-valuenow="12" aria-valuemin="0" aria-valuemax="100"><div class="progress-bar bg-warning" style="width:12%"></div></div><span class="cr-bar-r text-body-secondary">12%</span></li>
            <li class="d-flex align-items-center gap-2"><span class="cr-bar-l">3</span><div class="progress flex-grow-1" style="height:6px" role="progressbar" aria-label="3 stars" aria-valuenow="4" aria-valuemin="0" aria-valuemax="100"><div class="progress-bar bg-warning" style="width:4%"></div></div><span class="cr-bar-r text-body-secondary">4%</span></li>
            <li class="d-flex align-items-center gap-2"><span class="cr-bar-l">2</span><div class="progress flex-grow-1" style="height:6px" role="progressbar" aria-label="2 stars" aria-valuenow="1" aria-valuemin="0" aria-valuemax="100"><div class="progress-bar bg-warning" style="width:1%"></div></div><span class="cr-bar-r text-body-secondary">1%</span></li>
            <li class="d-flex align-items-center gap-2"><span class="cr-bar-l">1</span><div class="progress flex-grow-1" style="height:6px" role="progressbar" aria-label="1 star" aria-valuenow="1" aria-valuemin="0" aria-valuemax="100"><div class="progress-bar bg-warning" style="width:1%"></div></div><span class="cr-bar-r text-body-secondary">1%</span></li>
            </ul>
        </aside>
        <div class="col-md-7 p-4 p-lg-5 bg-body">
          <div class="d-flex align-items-center gap-3 mb-4">
            <img src="https://i.pravatar.cc/96?img=47" width="48" height="48" alt="Your profile photo" class="rounded-circle">
            <div>
              <h2 class="h5 wdw-heading mb-0">Leave a review</h2>
              <p class="small text-body-secondary mb-0">Posting as Emma Larsen</p>
            </div>
          </div>
          <form id="crForm" novalidate>
            <fieldset class="mb-3">
              <legend class="form-label small fw-semibold mb-1">Your rating</legend>
              <div class="cr-rating d-flex gap-1">
                <input type="radio" class="btn-check" name="rating" value="1" id="cr1"><label for="cr1" class="cr-star-btn" title="1 star"><svg class="cr-star text-body-tertiary" width="32" height="32" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.9L12 17.8 5.8 21l1.2-6.9-5-4.9 6.9-1z"/></svg><span class="visually-hidden">1 star</span></label>
                <input type="radio" class="btn-check" name="rating" value="2" id="cr2"><label for="cr2" class="cr-star-btn" title="2 stars"><svg class="cr-star text-body-tertiary" width="32" height="32" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.9L12 17.8 5.8 21l1.2-6.9-5-4.9 6.9-1z"/></svg><span class="visually-hidden">2 stars</span></label>
                <input type="radio" class="btn-check" name="rating" value="3" id="cr3"><label for="cr3" class="cr-star-btn" title="3 stars"><svg class="cr-star text-body-tertiary" width="32" height="32" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.9L12 17.8 5.8 21l1.2-6.9-5-4.9 6.9-1z"/></svg><span class="visually-hidden">3 stars</span></label>
                <input type="radio" class="btn-check" name="rating" value="4" id="cr4"><label for="cr4" class="cr-star-btn" title="4 stars"><svg class="cr-star text-body-tertiary" width="32" height="32" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.9L12 17.8 5.8 21l1.2-6.9-5-4.9 6.9-1z"/></svg><span class="visually-hidden">4 stars</span></label>
                <input type="radio" class="btn-check" name="rating" value="5" id="cr5"><label for="cr5" class="cr-star-btn" title="5 stars"><svg class="cr-star text-body-tertiary" width="32" height="32" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.9L12 17.8 5.8 21l1.2-6.9-5-4.9 6.9-1z"/></svg><span class="visually-hidden">5 stars</span></label>
                </div>
              <span class="small fw-semibold text-body-secondary d-block mt-1" id="crRatingText" aria-live="polite">Rate it</span>
            </fieldset>
            <div class="mb-3">
              <label for="crTitle" class="form-label small fw-semibold">Review title</label>
              <input type="text" id="crTitle" class="form-control" placeholder="Sum it up in a few words" maxlength="80">
            </div>
            <div class="mb-3 position-relative">
              <label for="crText" class="form-label small fw-semibold">Your review</label>
              <textarea id="crText" class="form-control pb-4" rows="4" placeholder="What did you like or dislike?" maxlength="300" required></textarea>
              <span class="cr-count small text-body-secondary"><span id="crCount">0</span>/300</span>
            </div>
            <fieldset class="mb-3">
              <legend class="form-label small fw-semibold mb-1">Would you recommend it?</legend>
              <div class="d-flex gap-2">
                <input type="radio" class="btn-check" name="recommend" id="crRecYes" value="Yes" checked><label class="btn btn-outline-primary btn-sm rounded-pill px-3" for="crRecYes">Yes</label>
                <input type="radio" class="btn-check" name="recommend" id="crRecNo" value="No"><label class="btn btn-outline-primary btn-sm rounded-pill px-3" for="crRecNo">No</label>
              </div>
            </fieldset>
            <div class="small mb-2" style="min-height:1.25rem"><span id="crError" class="text-danger" role="alert"></span></div>
            <div class="d-flex justify-content-end align-items-center gap-2">
              <button type="reset" class="btn btn-link link-body-emphasis fw-semibold text-decoration-none px-3">Cancel</button>
              <button type="submit" class="btn btn-primary rounded-pill px-4">Post review</button>
            </div>
          </form>
          <div id="crPosted" class="d-none mt-4 p-3 rounded-3 bg-body-tertiary border" role="status">
            <div class="d-flex gap-1 text-warning mb-1" id="crPostedStars" aria-hidden="true"></div>
            <p class="fw-semibold small mb-0" id="crPostedTitle"></p>
            <p class="mb-0 small" id="crPostedText"></p>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

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