Snippets Box

Bootstrap 5 Like, Comment and Share Post Card

A social post card with like, comment and share actions, a thread of replies, and a comment box that posts new comments.

Bootstrap 5 No jQuery May 2020 3.6K views

<section class="wdw-stage">
  <div class="container" style="max-width:640px">
    <article class="wdw-card overflow-hidden" id="post">
      <div class="p-4 pb-3">
        <div class="d-flex align-items-center gap-3">
          <img class="rounded-circle" src="https://i.pravatar.cc/96?img=47" width="48" height="48" alt="Marry Andrews">
          <div class="flex-grow-1">
            <h2 class="h6 fw-bold mb-0 text-body-emphasis">Marry Andrews</h2>
            <small class="text-body-secondary">Shared publicly · Jan 2020</small>
          </div>
          <span class="badge rounded-pill bg-primary-subtle text-primary-emphasis">Design</span>
        </div>
        <p class="mt-3 mb-0">Spent the weekend rebuilding our onboarding flow from scratch. Fewer steps, clearer copy, and a first-run checklist that actually gets finished. Early numbers look promising — curious how other teams handle this.</p>
      </div>
      <div class="d-flex justify-content-between align-items-center px-4 py-2 small text-body-secondary border-top">
        <span><span id="likeCount">24</span> <span id="likeWord">likes</span></span>
        <span aria-live="polite"><span id="commentCount">2</span> <span id="commentWord">comments</span></span>
      </div>
      <div class="d-flex gap-1 px-3 py-2 border-top">
        <button type="button" class="btn btn-link text-body-secondary text-decoration-none rounded-pill flex-fill" id="likeBtn" aria-pressed="false">
          <svg 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="M7 11v9H4v-9zM7 11l4-8a2 2 0 0 1 2 2v4h6a2 2 0 0 1 2 2l-1.4 7a2 2 0 0 1-2 1.6H7"/></svg>
          Like
        </button>
        <button type="button" class="btn btn-link text-body-secondary text-decoration-none rounded-pill flex-fill" id="commentBtn">
          <svg 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="M21 12a8 8 0 0 1-11.6 7.1L3 21l1.9-5.4A8 8 0 1 1 21 12z"/></svg>
          Comment
        </button>
        <button type="button" class="btn btn-link text-body-secondary text-decoration-none rounded-pill flex-fill" id="shareBtn">
          <svg 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="M4 12v7a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-7M16 6l-4-4-4 4M12 2v13"/></svg>
          <span id="shareLabel">Share</span>
        </button>
      </div>
      <ul class="list-unstyled m-0 px-4 py-3 border-top d-flex flex-column gap-3" id="comments">
        <li class="d-flex gap-3">
          <img class="rounded-circle" src="https://i.pravatar.cc/80?img=12" width="36" height="36" alt="Daniel Reyes">
          <div class="bg-body-tertiary rounded-4 px-3 py-2"><strong class="small d-block">Daniel Reyes</strong><span class="small">The checklist idea is great. Did completion rates move?</span></div>
        </li>
        <li class="d-flex gap-3">
          <img class="rounded-circle" src="https://i.pravatar.cc/80?img=32" width="36" height="36" alt="Priya Nair">
          <div class="bg-body-tertiary rounded-4 px-3 py-2"><strong class="small d-block">Priya Nair</strong><span class="small">Up 31% for us after a similar change.</span></div>
        </li>
      </ul>
      <form class="bg-body-tertiary p-3 p-sm-4 border-top" id="commentForm">
        <div class="d-flex gap-3 align-items-start">
          <img class="rounded-circle" src="https://i.pravatar.cc/96?img=47" width="40" height="40" alt="">
          <div class="flex-grow-1">
            <label for="commentText" class="visually-hidden">Write a comment</label>
            <textarea class="form-control" id="commentText" rows="2" placeholder="Write a comment…" required></textarea>
            <div class="d-flex justify-content-end gap-2 mt-3">
              <button type="reset" class="btn btn-link text-body-secondary text-decoration-none rounded-pill px-3">Cancel</button>
              <button type="submit" class="btn btn-primary rounded-pill px-3">Post comment</button>
            </div>
          </div>
        </div>
      </form>
    </article>
  </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.