Snippets Chat

Bootstrap 5 Chat Window with Conversation List

A two-pane chat layout with a searchable conversation list and a message thread with avatars and timestamps. Switching conversations, filtering and sending messages all work.

Bootstrap 5 No jQuery Sep 2019 2.2K views

<section class="wdw-stage">
  <div class="container" style="max-width: 1000px">
    <div class="wdw-card overflow-hidden chat" id="chat">
      <div class="row g-0">
        <aside class="col-md-4 border-end chat-side">
          <div class="p-3 pb-2">
            <div class="d-flex align-items-center justify-content-between mb-3">
              <h2 class="h5 fw-bold mb-0 text-body-emphasis">Messages</h2>
              <span class="badge rounded-pill bg-primary-subtle text-primary-emphasis" id="chat-new">3 new</span>
            </div>
            <label for="chat-search" class="visually-hidden">Search conversations</label>
            <input type="search" class="form-control bg-body-tertiary border-0" id="chat-search" placeholder="Search conversations">
          </div>
          <ul class="list-unstyled mb-0 px-2 pb-2 chat-people" id="chat-people">
          <li>
            <button type="button" class="chat-person is-active w-100 d-flex align-items-center gap-3 text-start" aria-current="true" data-chat="0" data-name="Maya Lindqvist" data-img="47">
              <img src="https://i.pravatar.cc/80?img=47" width="44" height="44" class="rounded-circle flex-shrink-0" alt="">
              <span class="flex-grow-1 min-w-0">
                <span class="d-flex justify-content-between gap-2"><span class="fw-semibold text-body-emphasis text-truncate">Maya Lindqvist</span><span class="small wdw-muted flex-shrink-0">Dec 25</span></span>
                <span class="d-flex justify-content-between gap-2 align-items-center"><span class="small wdw-muted text-truncate">Sounds good, I will send the files tonight.</span><span class="badge rounded-pill bg-primary chat-unread" data-n="2">2</span></span>
              </span>
            </button>
          </li>
          <li>
            <button type="button" class="chat-person w-100 d-flex align-items-center gap-3 text-start" data-chat="1" data-name="Daniel Okafor" data-img="12">
              <img src="https://i.pravatar.cc/80?img=12" width="44" height="44" class="rounded-circle flex-shrink-0" alt="">
              <span class="flex-grow-1 min-w-0">
                <span class="d-flex justify-content-between gap-2"><span class="fw-semibold text-body-emphasis text-truncate">Daniel Okafor</span><span class="small wdw-muted flex-shrink-0">Dec 24</span></span>
                <span class="d-flex justify-content-between gap-2 align-items-center"><span class="small wdw-muted text-truncate">Can we move the review to Thursday?</span></span>
              </span>
            </button>
          </li>
          <li>
            <button type="button" class="chat-person w-100 d-flex align-items-center gap-3 text-start" data-chat="2" data-name="Sofia Marin" data-img="32">
              <img src="https://i.pravatar.cc/80?img=32" width="44" height="44" class="rounded-circle flex-shrink-0" alt="">
              <span class="flex-grow-1 min-w-0">
                <span class="d-flex justify-content-between gap-2"><span class="fw-semibold text-body-emphasis text-truncate">Sofia Marin</span><span class="small wdw-muted flex-shrink-0">Dec 22</span></span>
                <span class="d-flex justify-content-between gap-2 align-items-center"><span class="small wdw-muted text-truncate">The new mockups look great!</span></span>
              </span>
            </button>
          </li>
          <li>
            <button type="button" class="chat-person w-100 d-flex align-items-center gap-3 text-start" data-chat="3" data-name="Tomas Vidal" data-img="15">
              <img src="https://i.pravatar.cc/80?img=15" width="44" height="44" class="rounded-circle flex-shrink-0" alt="">
              <span class="flex-grow-1 min-w-0">
                <span class="d-flex justify-content-between gap-2"><span class="fw-semibold text-body-emphasis text-truncate">Tomas Vidal</span><span class="small wdw-muted flex-shrink-0">Dec 20</span></span>
                <span class="d-flex justify-content-between gap-2 align-items-center"><span class="small wdw-muted text-truncate">Thanks, that fixed the build.</span></span>
              </span>
            </button>
          </li>
          <li>
            <button type="button" class="chat-person w-100 d-flex align-items-center gap-3 text-start" data-chat="4" data-name="Priya Nair" data-img="45">
              <img src="https://i.pravatar.cc/80?img=45" width="44" height="44" class="rounded-circle flex-shrink-0" alt="">
              <span class="flex-grow-1 min-w-0">
                <span class="d-flex justify-content-between gap-2"><span class="fw-semibold text-body-emphasis text-truncate">Priya Nair</span><span class="small wdw-muted flex-shrink-0">Dec 18</span></span>
                <span class="d-flex justify-content-between gap-2 align-items-center"><span class="small wdw-muted text-truncate">Let me know when you are free to chat.</span><span class="badge rounded-pill bg-primary chat-unread" data-n="1">1</span></span>
              </span>
            </button>
          </li>
          <li>
            <button type="button" class="chat-person w-100 d-flex align-items-center gap-3 text-start" data-chat="5" data-name="Brian Hale" data-img="53">
              <img src="https://i.pravatar.cc/80?img=53" width="44" height="44" class="rounded-circle flex-shrink-0" alt="">
              <span class="flex-grow-1 min-w-0">
                <span class="d-flex justify-content-between gap-2"><span class="fw-semibold text-body-emphasis text-truncate">Brian Hale</span><span class="small wdw-muted flex-shrink-0">Dec 15</span></span>
                <span class="d-flex justify-content-between gap-2 align-items-center"><span class="small wdw-muted text-truncate">Invoice attached for December.</span></span>
              </span>
            </button>
          </li>
          </ul>
        </aside>
        <section class="col-md-8 d-flex flex-column chat-main" aria-label="Conversation">
          <header class="d-flex align-items-center gap-3 px-4 py-3 border-bottom">
            <img src="https://i.pravatar.cc/80?img=47" width="40" height="40" class="rounded-circle" alt="" id="chat-avatar">
            <div><div class="fw-semibold text-body-emphasis" id="chat-title">Maya Lindqvist</div><div class="small text-success-emphasis d-flex align-items-center gap-1"><span class="chat-dot" aria-hidden="true"></span>Online</div></div>
          </header>
          <div class="chat-thread flex-grow-1 p-4 d-flex flex-column gap-3" id="chat-thread" aria-live="polite">
            <div class="chat-msg in"><img src="https://i.pravatar.cc/80?img=47" width="36" height="36" class="rounded-circle" alt=""><div><div class="chat-bubble">Hi! Did you get a chance to look at the proposal?</div><div class="chat-time">11:01 AM | June 9</div></div></div>
            <div class="chat-msg out"><div><div class="chat-bubble">Yes, it looks solid. A few small notes on the timeline.</div><div class="chat-time">11:04 AM | June 9</div></div></div>
            <div class="chat-msg in"><img src="https://i.pravatar.cc/80?img=47" width="36" height="36" class="rounded-circle" alt=""><div><div class="chat-bubble">Great, we work directly with our designers and suppliers, so we can adjust quickly.</div><div class="chat-time">11:06 AM | Yesterday</div></div></div>
            <div class="chat-msg out"><div><div class="chat-bubble">Perfect. Send me the updated version when ready.</div><div class="chat-time">11:09 AM | Today</div></div></div>
            <div class="chat-msg in"><img src="https://i.pravatar.cc/80?img=47" width="36" height="36" class="rounded-circle" alt=""><div><div class="chat-bubble">Sounds good, I will send the files tonight.</div><div class="chat-time">11:12 AM | Today</div></div></div>
          </div>
          <form class="d-flex gap-2 p-3 border-top" id="chat-form">
            <label for="chat-input" class="visually-hidden">Type a message</label>
            <input type="text" class="form-control rounded-pill bg-body-tertiary border-0 px-4" id="chat-input" placeholder="Type a message" autocomplete="off">
            <button type="submit" class="btn btn-primary rounded-circle p-0 flex-shrink-0" style="width:44px" aria-label="Send message"><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>
  </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.