Snippets Comments

Bootstrap 5 Blog Comments Section

A blog comment section with a composer, avatar cards, an author badge, a nested reply thread, like buttons with a visible liked state, and inline reply boxes.

Bootstrap 5 No jQuery May 2019 3.5K views

<section class="wdw-stage cm-stage align-items-start align-items-lg-center">
  <div class="container" style="max-width: 720px;">
    <div class="mb-3"><span class="wdw-eyebrow">Discussion</span><h1 class="wdw-heading h3 mb-0 mt-1" id="cm-count" aria-live="polite">3 comments</h1></div>

    <form class="wdw-card p-3 mb-3 cm-composer" id="cm-form" data-author="You" novalidate>
      <div class="d-flex gap-3 align-items-start">
        <img class="cm-avatar" src="https://i.pravatar.cc/96?img=47" width="48" height="48" alt="Your profile picture">
        <div class="flex-grow-1 d-flex flex-column flex-sm-row gap-2 align-items-sm-start">
          <label for="cm-text" class="visually-hidden">Leave a comment</label>
          <textarea class="form-control cm-textarea" id="cm-text" rows="1" placeholder="Share your thoughts..." required style="height:auto;min-height:44px;"></textarea>
          <button type="submit" class="btn btn-primary rounded-pill px-4 text-nowrap">Post comment</button>
        </div>
      </div>
    </form>

    <div class="d-grid gap-3" id="cm-list">
      <article class="wdw-card-sm p-3 cm-item" data-comment data-author="John Doe">
        <div class="d-flex gap-3">
          <img class="cm-avatar" src="https://i.pravatar.cc/96?img=12" width="48" height="48" alt="John Doe">
          <div class="flex-grow-1 min-w-0">
            <div class="d-flex flex-wrap align-items-baseline gap-2"><h2 class="h6 fw-bold mb-0">John Doe</h2><span class="small wdw-muted">2 days ago</span></div>
            <p class="mt-1 mb-2">Really clear walkthrough, thank you. The dark mode part finally made the colour tokens click for me.</p>
            <div class="cm-actions d-flex gap-2 small">
              <button type="button" class="cm-act" data-like aria-pressed="false"><svg class="cm-ico" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 21s-7.500-4.600-9.300-9.200C1.500 8.600 3.400 5 7 5c2 0 3.400 1 5 3 1.600-2 3-3 5-3 3.600 0 5.500 3.600 4.300 6.800C19.500 16.400 12 21 12 21Z"/></svg><span>Like</span> <span data-n>4</span></button>
              <button type="button" class="cm-act" data-reply><svg class="cm-ico" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 14-5-5 5-5"/><path d="M4 9h10a6 6 0 0 1 6 6v3"/></svg><span>Reply</span></button>
            </div>
            <div class="cm-thread d-grid gap-3 mt-3">
              <article class="cm-reply" data-comment data-author="Albert Arja">
                <div class="d-flex gap-3">
                  <img class="cm-avatar cm-avatar-sm" src="https://i.pravatar.cc/96?img=32" width="36" height="36" alt="Albert Arja">
                  <div class="flex-grow-1 min-w-0">
                    <div class="d-flex flex-wrap align-items-baseline gap-2"><h3 class="h6 fw-bold mb-0">Albert Arja</h3><span class="badge bg-primary-subtle text-primary-emphasis rounded-pill">Author</span><span class="small wdw-muted">1 day ago</span></div>
                    <p class="mt-1 mb-2">Glad it helped! I will add a dark mode variant next week.</p>
                    <div class="cm-actions d-flex gap-2 small">
                      <button type="button" class="cm-act" data-like aria-pressed="false"><svg class="cm-ico" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 21s-7.500-4.600-9.300-9.200C1.500 8.600 3.400 5 7 5c2 0 3.400 1 5 3 1.600-2 3-3 5-3 3.600 0 5.500 3.600 4.300 6.800C19.500 16.400 12 21 12 21Z"/></svg><span>Like</span> <span data-n>11</span></button>
                      <button type="button" class="cm-act" data-reply><svg class="cm-ico" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 14-5-5 5-5"/><path d="M4 9h10a6 6 0 0 1 6 6v3"/></svg><span>Reply</span></button>
                    </div>
                  </div>
                </div>
              </article>
            </div>
          </div>
        </div>
      </article>
      <article class="wdw-card-sm p-3 cm-item" data-comment data-author="Robert Hale">
        <div class="d-flex gap-3">
          <img class="cm-avatar" src="https://i.pravatar.cc/96?img=15" width="48" height="48" alt="Robert Hale">
          <div class="flex-grow-1 min-w-0">
            <div class="d-flex flex-wrap align-items-baseline gap-2"><h2 class="h6 fw-bold mb-0">Robert Hale</h2><span class="small wdw-muted">2 months ago</span></div>
            <p class="mt-1 mb-2">Works great on mobile too. Dropped it straight into our blog template.</p>
            <div class="cm-actions d-flex gap-2 small">
              <button type="button" class="cm-act" data-like aria-pressed="false"><svg class="cm-ico" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 21s-7.500-4.600-9.300-9.200C1.500 8.600 3.400 5 7 5c2 0 3.400 1 5 3 1.600-2 3-3 5-3 3.600 0 5.500 3.600 4.300 6.800C19.500 16.400 12 21 12 21Z"/></svg><span>Like</span> <span data-n>2</span></button>
              <button type="button" class="cm-act" data-reply><svg class="cm-ico" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 14-5-5 5-5"/><path d="M4 9h10a6 6 0 0 1 6 6v3"/></svg><span>Reply</span></button>
            </div>
            <div class="cm-thread d-grid gap-3 mt-3 d-none"></div>
          </div>
        </div>
      </article>
    </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.