Snippets Chat

Bootstrap 5 Collapsible Chat Widget

A support chat widget with an agent header, scrolling message history, quick replies, typing indicator and message input, which can be minimized, closed and reopened.

Bootstrap 5 No jQuery Sep 2019 2.3K views

<section class="wdw-stage chat-stage">
  <div class="container" style="max-width:1040px">
    <div class="row align-items-center gx-4 gy-5 mx-0">
      <div class="col-lg-5 text-center text-lg-start">
        <span class="wdw-eyebrow">Live support</span>
        <h1 class="wdw-heading display-6 mt-2 mb-3">Talk to a real person, right from the page</h1>
        <p class="text-body-secondary mb-4">A collapsible chat widget with message history, typing indicator and quick replies. Minimize it, close it, or bring it back from the launcher.</p>
        <button type="button" class="btn btn-primary rounded-pill" id="chatReopen">Open chat</button>
      </div>
      <div class="col-lg-7 d-flex flex-column align-items-center align-items-lg-end chat-slot">
        <div class="chat-widget wdw-card" id="chatWidget" role="region" aria-label="Chat with support">
          <header class="chat-head wdw-aurora d-flex align-items-center gap-3 p-3">
            <div class="position-relative"><img src="https://i.pravatar.cc/80?img=47" alt="" width="40" height="40" class="rounded-circle"><span class="chat-dot border border-2 border-dark-subtle"></span></div>
            <div class="flex-grow-1 lh-sm"><div class="fw-bold">Sofia from Support</div><div class="small opacity-75">Online · replies in minutes</div></div>
            <button type="button" class="btn btn-sm rounded-circle p-0 chat-ico" id="chatMin" aria-label="Minimize chat" aria-expanded="true" aria-controls="chatBody"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" aria-hidden="true"><path d="M5 12h14"/></svg></button>
            <button type="button" class="btn btn-sm rounded-circle p-0 chat-ico" id="chatClose" aria-label="Close chat"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18"/></svg></button>
          </header>
          <div id="chatBody">
            <div class="chat-msgs p-3 d-flex flex-column gap-3" id="chatMsgs" role="log" aria-live="polite">
              <div class="chat-day text-center small text-body-secondary">Today</div>
              <div class="chat-row"><img src="https://i.pravatar.cc/60?img=47" alt="" width="28" height="28" class="rounded-circle"><div><div class="bubble in">Hi there! How can we help you today?</div><div class="meta">Sofia · 10:02</div></div></div>
              <div class="chat-row out"><div><div class="bubble out">I'd like to change my plan before the next billing date.</div><div class="meta text-end">You · 10:03</div></div></div>
              <div class="chat-row"><img src="https://i.pravatar.cc/60?img=47" alt="" width="28" height="28" class="rounded-circle"><div><div class="bubble in">Sure thing. You can switch any time from Settings, or I can do it for you right now.</div><div class="meta">Sofia · 10:03</div></div></div>
            </div>
            <div class="px-3 pb-2 d-flex gap-2 flex-wrap" id="chatQuick">
              <button type="button" class="btn btn-sm btn-outline-primary rounded-pill">Switch for me</button>
              <button type="button" class="btn btn-sm btn-outline-primary rounded-pill">Show pricing</button>
            </div>
            <form class="chat-form d-flex gap-2 p-3 pt-2" id="chatForm" autocomplete="off">
              <input type="text" class="form-control rounded-pill" id="chatInput" placeholder="Write a message…" aria-label="Message">
              <button type="submit" class="btn btn-primary rounded-circle p-0 chat-send" 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>
          </div>
        </div>
        <button type="button" class="btn btn-primary rounded-circle p-0 chat-fab position-relative d-none" id="chatFab" aria-label="Open chat, 1 unread message"><svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z"/></svg><span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger border border-2 border-body" aria-hidden="true">1</span></button>
      </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.