Bootstrap 5 Chat Box Template with Contact List
A two-pane messaging layout with a searchable contact list, presence dots and a conversation view with bubbles and a composer. On small screens it switches to a list-then-thread flow.
<section class="wdw-stage">
<div class="container" style="max-width: 980px">
<div class="wdw-card chat show-list overflow-hidden">
<aside class="chat-list" aria-label="Conversations">
<div class="p-3 pb-2">
<h1 class="h5 wdw-heading mb-3">Messages</h1>
<label class="visually-hidden" for="chatSearch">Search conversations</label>
<input type="search" id="chatSearch" class="form-control rounded-pill bg-body-tertiary border-0" placeholder="Search people">
</div>
<ul class="list-group list-group-flush list-unstyled m-0 px-2 pb-2 overflow-auto" id="contacts">
<li><button type="button" class="list-group-item list-group-item-action contact d-flex align-items-center gap-3 border-0 rounded-3 py-2 active-contact" data-name="Maryam Naz" data-img="47" data-status="Online" aria-current="true">
<span class="position-relative flex-none"><img src="https://i.pravatar.cc/80?img=47" alt="" width="44" height="44" class="rounded-circle"><span class="position-absolute bottom-0 end-0 p-1 rounded-circle border border-2 border-body bg-success"></span></span>
<span class="flex-grow-1 text-start text-truncate"><strong class="d-block">Maryam Naz</strong><small class="text-body-secondary">Looking for your next template</small></span>
<span class="d-flex flex-column align-items-end gap-1"><small class="text-body-secondary">9:05</small><span class="badge rounded-pill text-bg-primary">2</span></span></button></li>
<li><button type="button" class="list-group-item list-group-item-action contact d-flex align-items-center gap-3 border-0 rounded-3 py-2" data-name="Sahar Darya" data-img="32" data-status="Away">
<span class="position-relative flex-none"><img src="https://i.pravatar.cc/80?img=32" alt="" width="44" height="44" class="rounded-circle"><span class="position-absolute bottom-0 end-0 p-1 rounded-circle border border-2 border-body bg-secondary"></span></span>
<span class="flex-grow-1 text-start text-truncate"><strong class="d-block">Sahar Darya</strong><small class="text-body-secondary">Sounds good, see you then</small></span>
<span class="d-flex flex-column align-items-end gap-1"><small class="text-body-secondary">8:12</small></span></button></li>
<li><button type="button" class="list-group-item list-group-item-action contact d-flex align-items-center gap-3 border-0 rounded-3 py-2" data-name="Yolduz Rafi" data-img="45" data-status="Online">
<span class="position-relative flex-none"><img src="https://i.pravatar.cc/80?img=45" alt="" width="44" height="44" class="rounded-circle"><span class="position-absolute bottom-0 end-0 p-1 rounded-circle border border-2 border-body bg-success"></span></span>
<span class="flex-grow-1 text-start text-truncate"><strong class="d-block">Yolduz Rafi</strong><small class="text-body-secondary">Sent the design files</small></span>
<span class="d-flex flex-column align-items-end gap-1"><small class="text-body-secondary">Mon</small><span class="badge rounded-pill text-bg-primary">1</span></span></button></li>
<li><button type="button" class="list-group-item list-group-item-action contact d-flex align-items-center gap-3 border-0 rounded-3 py-2" data-name="Nargis Hawa" data-img="44" data-status="Away">
<span class="position-relative flex-none"><img src="https://i.pravatar.cc/80?img=44" alt="" width="44" height="44" class="rounded-circle"><span class="position-absolute bottom-0 end-0 p-1 rounded-circle border border-2 border-body bg-secondary"></span></span>
<span class="flex-grow-1 text-start text-truncate"><strong class="d-block">Nargis Hawa</strong><small class="text-body-secondary">Thanks for the update!</small></span>
<span class="d-flex flex-column align-items-end gap-1"><small class="text-body-secondary">Sun</small></span></button></li>
<li><button type="button" class="list-group-item list-group-item-action contact d-flex align-items-center gap-3 border-0 rounded-3 py-2" data-name="Omid Karim" data-img="15" data-status="Online">
<span class="position-relative flex-none"><img src="https://i.pravatar.cc/80?img=15" alt="" width="44" height="44" class="rounded-circle"><span class="position-absolute bottom-0 end-0 p-1 rounded-circle border border-2 border-body bg-success"></span></span>
<span class="flex-grow-1 text-start text-truncate"><strong class="d-block">Omid Karim</strong><small class="text-body-secondary">Can we move the call to 3?</small></span>
<span class="d-flex flex-column align-items-end gap-1"><small class="text-body-secondary">Sat</small></span></button></li>
<li><button type="button" class="list-group-item list-group-item-action contact d-flex align-items-center gap-3 border-0 rounded-3 py-2" data-name="Laila Noor" data-img="25" data-status="Away">
<span class="position-relative flex-none"><img src="https://i.pravatar.cc/80?img=25" alt="" width="44" height="44" class="rounded-circle"><span class="position-absolute bottom-0 end-0 p-1 rounded-circle border border-2 border-body bg-secondary"></span></span>
<span class="flex-grow-1 text-start text-truncate"><strong class="d-block">Laila Noor</strong><small class="text-body-secondary">Invoice paid, thank you</small></span>
<span class="d-flex flex-column align-items-end gap-1"><small class="text-body-secondary">Fri</small></span></button></li>
</ul>
</aside>
<section class="chat-main d-flex flex-column" aria-label="Conversation">
<header class="d-flex align-items-center gap-3 px-3 py-3 border-bottom">
<button type="button" class="btn btn-icon btn-outline-secondary border-0 bg-body-tertiary text-body rounded-circle d-md-none back" aria-label="Back to conversations"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg></button>
<span class="position-relative flex-none"><img id="peerImg" src="https://i.pravatar.cc/80?img=47" alt="" width="44" height="44" class="rounded-circle"><span id="peerDot" class="position-absolute bottom-0 end-0 p-1 rounded-circle border border-2 border-body bg-success"></span></span>
<div class="flex-grow-1 lh-sm"><strong id="peerName" class="d-block">Maryam Naz</strong><small id="peerStatus" class="text-success-emphasis">Online</small></div>
<button type="button" class="btn btn-icon btn-outline-secondary border-0 bg-body-tertiary text-body rounded-circle" aria-label="Call"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M22 16.9v3a2 2 0 0 1-2.2 2 19.8 19.8 0 0 1-8.6-3.1 19.500 19.500 0 0 1-6-6A19.800 19.800 0 0 1 2.100 4.200 2 2 0 0 1 4.100 2h3a2 2 0 0 1 2 1.700c.1 1 .4 1.900.7 2.800a2 2 0 0 1-.5 2.100L8.100 9.900a16 16 0 0 0 6 6l1.300-1.300a2 2 0 0 1 2.100-.4c.9.300 1.800.6 2.800.7a2 2 0 0 1 1.700 2z"/></svg></button>
</header>
<div class="msgs flex-grow-1 overflow-auto p-3 d-flex flex-column gap-2 bg-body-tertiary" id="msgs" tabindex="0" aria-live="polite">
<div class="text-center"><span class="badge rounded-pill bg-body text-body-secondary border fw-medium">Today</span></div>
<div class="msg in"><p>Hi, how are you Samim?</p><small>8:40 AM</small></div>
<div class="msg out"><p>Hi Maryam, I am good thanks. How about you?</p><small>8:55 AM</small></div>
<div class="msg in"><p>I am good too, thank you for your chat template.</p><small>9:00 AM</small></div>
<div class="msg out"><p>You are welcome!</p><small>9:05 AM</small></div>
<div class="msg in"><p>I am looking for your next templates too.</p><small>9:06 AM</small></div>
<div class="msg in typing" id="typing"><p aria-label="Maryam is typing"><i></i><i></i><i></i></p></div>
</div>
<form class="d-flex align-items-center gap-2 p-3 border-top" id="chatForm">
<label class="visually-hidden" for="chatInput">Message</label>
<input id="chatInput" class="form-control rounded-pill" placeholder="Type your message" autocomplete="off">
<button class="btn btn-primary btn-icon rounded-circle flex-none" type="submit" aria-label="Send"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M22 2 11 13M22 2l-7 20-4-9-9-4z"/></svg></button>
</form>
</section>
</div>
</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 */
.chat { display: grid; grid-template-columns: 300px 1fr; height: 590px; }
.chat-list { display: flex; flex-direction: column; border-right: 1px solid var(--bs-border-color); min-height: 0; }
.chat-main { min-height: 0; }
.chat-list ul { gap: 2px; }
.contact { color: var(--bs-body-color); font-size: .9rem; background: transparent; }
.contact small { font-size: .75rem; }
.contact.active-contact { background: var(--bs-primary-bg-subtle); }
.btn-icon { width: 44px; height: 44px; padding: 0; flex: none; }
.flex-none { flex: none; }
.msg { max-width: 78%; width: fit-content; }
.msg p { margin: 0; padding: .5rem .9rem; border-radius: 1.1rem; font-size: .925rem; }
.msg small { display: block; margin-top: .15rem; font-size: .7rem; color: var(--bs-secondary-color); }
.msg.in p { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-bottom-left-radius: .35rem; }
.msg.out { align-self: flex-end; text-align: right; }
.msg.out p { color: #fff; border-bottom-right-radius: .35rem; text-align: left; background: radial-gradient(90% 140% at 100% 0, #818cf8 0, transparent 70%), #4338ca; }
.typing p { display: flex; gap: 4px; padding: .8rem 1rem; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--bs-secondary-color); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; } }
@media (max-width: 767.98px) {
.chat { grid-template-columns: 1fr; height: 600px; }
.chat-list { display: none; border-right: 0; }
.chat.show-list .chat-list { display: flex; }
.chat.show-list .chat-main { display: none !important; }
}
function initChat() {
const root = document.querySelector('.chat');
const form = document.getElementById('chatForm');
const input = document.getElementById('chatInput');
const msgs = document.getElementById('msgs');
if (!root || !form || !input || !msgs) return;
function time() {
return new Date().toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });
}
function add(text, dir) {
const box = document.createElement('div');
box.className = 'msg ' + dir;
const p = document.createElement('p');
p.textContent = text;
const t = document.createElement('small');
t.textContent = time();
box.append(p, t);
msgs.insertBefore(box, document.getElementById('typing'));
msgs.scrollTop = msgs.scrollHeight;
}
form.addEventListener('submit', function (e) {
e.preventDefault();
const v = input.value.trim();
if (!v) return;
add(v, 'out');
input.value = '';
setTimeout(function () { add('Got it, thanks!', 'in'); }, 900);
});
const contacts = document.querySelectorAll('.contact');
contacts.forEach(function (c) {
c.addEventListener('click', function () {
contacts.forEach(function (o) { o.classList.remove('active-contact'); o.removeAttribute('aria-current'); });
c.classList.add('active-contact');
c.setAttribute('aria-current', 'true');
const b = c.querySelector('.badge');
if (b) b.remove();
document.getElementById('peerDot').className = 'position-absolute bottom-0 end-0 p-1 rounded-circle border border-2 border-body ' + (c.dataset.status === 'Online' ? 'bg-success' : 'bg-secondary');
document.getElementById('peerName').textContent = c.dataset.name;
document.getElementById('peerImg').src = 'https://i.pravatar.cc/80?img=' + c.dataset.img;
const st = document.getElementById('peerStatus');
st.textContent = c.dataset.status;
st.className = c.dataset.status === 'Online' ? 'text-success-emphasis' : 'text-body-secondary';
root.classList.remove('show-list');
});
});
msgs.scrollTop = msgs.scrollHeight;
const back = root.querySelector('.back');
if (back) back.addEventListener('click', function () { root.classList.add('show-list'); });
const search = document.getElementById('chatSearch');
if (search) search.addEventListener('input', function () {
const q = search.value.toLowerCase();
contacts.forEach(function (c) { c.parentElement.hidden = c.dataset.name.toLowerCase().indexOf(q) === -1; });
});
}
initChat();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.