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.
<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>
/* Web Designer Wall library style — shared base for every Bootstrap 5 snippet.
Indigo accent, Plus Jakarta Sans, soft cards, pill buttons. Works in light and dark. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");
:root,
[data-bs-theme="light"] {
--wdw-font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--bs-body-font-family: var(--wdw-font);
--bs-primary: #4f46e5;
--bs-primary-rgb: 79, 70, 229;
--bs-primary-text-emphasis: #3730a3;
--bs-primary-bg-subtle: #eef2ff;
--bs-primary-border-subtle: #c7d2fe;
--bs-link-color: #4f46e5;
--bs-link-color-rgb: 79, 70, 229;
--bs-link-hover-color: #4338ca;
--bs-link-hover-color-rgb: 67, 56, 202;
--bs-focus-ring-color: rgba(79, 70, 229, 0.25);
--bs-border-radius: 0.75rem;
--bs-border-radius-lg: 1rem;
--bs-border-radius-xl: 1.25rem;
--wdw-radius-card: 1.25rem;
--wdw-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 40px -16px rgba(16, 24, 40, 0.22);
--wdw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px -4px rgba(16, 24, 40, 0.12);
--wdw-stage: #f5f6fb;
}
[data-bs-theme="dark"] {
--bs-primary: #818cf8;
--bs-primary-rgb: 129, 140, 248;
--bs-primary-text-emphasis: #c7d2fe;
--bs-primary-bg-subtle: rgba(129, 140, 248, 0.14);
--bs-primary-border-subtle: rgba(129, 140, 248, 0.35);
--bs-link-color: #a5b4fc;
--bs-link-color-rgb: 165, 180, 252;
--bs-link-hover-color: #c7d2fe;
--bs-link-hover-color-rgb: 199, 210, 254;
--bs-focus-ring-color: rgba(129, 140, 248, 0.35);
--wdw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
--wdw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
--wdw-stage: #0f1117;
}
body { font-family: var(--wdw-font); -webkit-font-smoothing: antialiased; }
/* Bootstrap compiles its blue into these components; point them at the accent. */
.btn-primary {
--bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
--bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
--bs-btn-disabled-bg: var(--bs-primary); --bs-btn-disabled-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1117; --bs-btn-hover-bg: #a5b4fc; --bs-btn-hover-border-color: #a5b4fc; --bs-btn-hover-color: #0f1117; --bs-btn-active-color: #0f1117; }
.btn-outline-primary {
--bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary);
--bs-btn-active-bg: var(--bs-primary); --bs-btn-active-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn { --bs-btn-font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; border-radius: .75rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary); }
.nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-active-bg: var(--bs-primary); --bs-pagination-active-border-color: var(--bs-primary); --bs-pagination-color: var(--bs-body-color); --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); }
.list-group { --bs-list-group-active-bg: var(--bs-primary); --bs-list-group-active-border-color: var(--bs-primary); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--bs-primary); border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
.accordion { --bs-accordion-active-bg: var(--bs-primary-bg-subtle); --bs-accordion-active-color: var(--bs-primary-text-emphasis); --bs-accordion-btn-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.badge { font-weight: 600; }
/* Library building blocks — use these instead of re-inventing them per snippet. */
.wdw-stage { min-height: 100vh; display: flex; align-items: center; background: var(--wdw-stage); padding-block: 3rem; }
.wdw-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: var(--wdw-radius-card); box-shadow: var(--wdw-shadow); }
.wdw-card-sm { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); }
.wdw-aurora { position: relative; color: #fff; background: radial-gradient(60% 55% at 100% 0, #818cf8 0, transparent 70%), radial-gradient(65% 60% at 0 100%, #ec4899 0, transparent 65%), #1e1b4b; }
.wdw-eyebrow { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--bs-primary); }
.wdw-heading { font-weight: 800; letter-spacing: -.02em; color: var(--bs-emphasis-color); }
.wdw-muted { color: var(--bs-secondary-color); }
.wdw-icon { width: 2.75rem; height: 2.75rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: .875rem; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
/* Component */
#post textarea { resize: vertical; min-height: 76px; height: auto; }
#post .btn-link { --bs-btn-hover-color: var(--bs-emphasis-color); --bs-btn-active-color: var(--bs-emphasis-color); }
#post .btn-link:hover { background: var(--bs-tertiary-bg); }
#post .btn-link.is-on { color: var(--bs-primary); background: var(--bs-primary-bg-subtle); }
#post .btn-link.is-on svg { fill: currentColor; fill-opacity: .2; }
#comments li { animation: wdw-in .25s ease; }
@keyframes wdw-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { #comments li { animation: none; } }
(function () {
function plural(id, n, word) {
var el = document.getElementById(id);
if (el) el.textContent = word + (n === 1 ? '' : 's');
}
function initLike() {
var btn = document.getElementById('likeBtn'), count = document.getElementById('likeCount');
if (!btn || !count) return;
btn.addEventListener('click', function () {
var on = btn.classList.toggle('is-on');
btn.setAttribute('aria-pressed', on);
var n = parseInt(count.textContent, 10) + (on ? 1 : -1);
count.textContent = n;
plural('likeWord', n, 'like');
});
}
function initComments() {
var form = document.getElementById('commentForm'), list = document.getElementById('comments');
var text = document.getElementById('commentText'), count = document.getElementById('commentCount');
var btn = document.getElementById('commentBtn');
if (!form || !list || !text) return;
if (btn) btn.addEventListener('click', function () { text.focus(); });
form.addEventListener('submit', function (e) {
e.preventDefault();
var v = text.value.trim();
if (!v) return;
var li = document.createElement('li');
li.className = 'd-flex gap-3';
var img = document.createElement('img');
img.className = 'rounded-circle'; img.width = 36; img.height = 36; img.alt = 'You';
img.src = 'https://i.pravatar.cc/80?img=47';
var box = document.createElement('div');
box.className = 'bg-body-tertiary rounded-4 px-3 py-2';
var s = document.createElement('strong'); s.className = 'small d-block'; s.textContent = 'You';
var p = document.createElement('span'); p.className = 'small'; p.textContent = v;
box.append(s, p); li.append(img, box); list.append(li);
count.textContent = list.children.length;
plural('commentWord', list.children.length, 'comment');
form.reset();
});
}
function initShare() {
var btn = document.getElementById('shareBtn'), label = document.getElementById('shareLabel');
if (!btn || !label) return;
btn.addEventListener('click', function () {
var done = function (msg) {
label.textContent = msg;
setTimeout(function () { label.textContent = 'Share'; }, 1600);
};
try {
navigator.clipboard.writeText(location.href).then(function () { done('Link copied'); }, function () { done('Copy failed'); });
} catch (e) { done('Copy failed'); }
});
}
initLike(); initComments(); initShare();
})();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.