Snippets Checkbox

Bootstrap 5 Pop-Up Chat Box with Message Bubbles

A pop-up chat window with an agent header, message bubbles, a typing form and an options menu, opened and closed from a launcher button.

Bootstrap 5 No jQuery Sep 2019 7K views

<section class="wdw-stage pc-stage">
  <div class="container" style="max-width:460px">
      <div class="pc-wrap d-flex flex-column align-items-end gap-3">
        <div class="pc-box wdw-card overflow-hidden mx-auto" id="pc-box" role="region" aria-label="Chat with Maya">
          <div class="d-flex align-items-center gap-3 p-3 border-bottom">
            <div class="position-relative"><img src="https://i.pravatar.cc/80?img=47" class="rounded-circle" width="44" height="44" alt="Maya, support agent"><span class="pc-online" aria-hidden="true"></span></div>
            <div class="flex-grow-1"><div class="fw-bold lh-sm">Maya Collins</div><div class="small text-success-emphasis">Online now</div></div>
            <div class="dropdown">
              <button class="btn btn-sm pc-icon px-2" type="button" data-bs-toggle="dropdown" aria-expanded="false" aria-label="Chat options"><svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><circle cx="5" cy="12" r="1.8"/><circle cx="12" cy="12" r="1.8"/><circle cx="19" cy="12" r="1.8"/></svg></button>
              <ul class="dropdown-menu dropdown-menu-end"><li><button class="dropdown-item" type="button" id="pc-clear">Clear conversation</button></li><li><a class="dropdown-item" href="#">Email transcript</a></li></ul>
            </div>
            <button type="button" class="btn btn-sm pc-icon px-2" id="pc-close" aria-label="Close chat"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg></button>
          </div>
          <div class="pc-log p-3 d-flex flex-column gap-3" id="pc-log" role="log" aria-live="polite" aria-label="Conversation" tabindex="0">
            <div class="text-center small wdw-muted">Today</div>
            <div class="pc-msg"><div class="pc-bubble">Hi there! How can I help you today?</div><span class="pc-time">10:02</span></div>
            <div class="pc-msg pc-me"><div class="pc-bubble">I need to change the shipping address on my order.</div><span class="pc-time">10:03</span></div>
            <div class="pc-msg"><div class="pc-bubble">Of course. Could you share your order number?</div><span class="pc-time">10:03</span></div>
            <div class="pc-typing" aria-hidden="true"><span></span><span></span><span></span></div>
          </div>
          <div class="pc-chips d-flex flex-wrap gap-2 px-3 pb-3 bg-body-tertiary" role="group" aria-label="Quick replies">
            <button type="button" class="btn btn-sm btn-outline-primary rounded-pill" data-reply="My order number is #48213.">Order #48213</button>
            <button type="button" class="btn btn-sm btn-outline-primary rounded-pill" data-reply="I don't have it with me.">I don't have it</button>
            <button type="button" class="btn btn-sm btn-outline-primary rounded-pill" data-reply="Can I talk to a person?">Talk to a person</button>
          </div>
          <form class="d-flex gap-2 p-3 border-top" id="pc-form" autocomplete="off">
            <label class="visually-hidden" for="pc-input">Message</label>
            <input type="text" class="form-control rounded-pill" id="pc-input" placeholder="Write a message…">
            <button type="submit" class="btn btn-primary rounded-circle p-0 pc-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"><path d="M22 2L11 13M22 2l-7 20-4-9-9-4z"/></svg></button>
          </form>
        </div>
        <button type="button" class="btn btn-primary rounded-circle p-0 pc-fab" id="pc-open" aria-controls="pc-box" aria-expanded="true" aria-label="Close chat">
          <svg class="pc-ic-chat" 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 01-11.6 7.1L4 20l1-4.6A8 8 0 1121 12z"/></svg>
          <svg class="pc-ic-x" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>
        </button>
      </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.