About this snippet

Add a support button to your site with this floating chat widget. It sits in the corner and expands into a message box when clicked, yet keeps the interface clean when not in use.

Size
2.9 KB
Uses
HTML, CSS, JavaScript
Loads
placehold.co
Views
664
<button class="chat-toggle" id="chatToggle" aria-label="Open Chat">
  <span class="icon-open">&#128172;</span>
  <span class="icon-close">&times;</span>
</button>

<div class="chat-widget" id="chatWidget">
  <div class="chat-header">
    <div class="agent">
      <img src="https://placehold.co/40x40/3b82f6/ffffff?text=A" alt="Agent">
      <div>
        <h4>Support Team</h4>
        <span>Online</span>
      </div>
    </div>
  </div>
  <div class="chat-body">
    <div class="msg income">Hi! How can we help you?</div>
  </div>
  <div class="chat-footer">
    <input type="text" placeholder="Type a message...">
    <button>&#10148;</button>
  </div>
</div>
.chat-toggle {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 60px;
  height: 60px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 50%;
  box-shadow: 0 5px 20px rgba(37, 99, 235, 0.4);
  cursor: pointer;
  z-index: 1000;
  font-size: 1.5rem;
  transition: transform 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-toggle:hover {
  transform: scale(1.1);
}
.icon-close { display: none; }
.chat-toggle.open .icon-open { display: none; }
.chat-toggle.open .icon-close { display: block; font-size: 2rem; }

.chat-widget {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 350px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  z-index: 999;
  overflow: hidden;
  transform: translateY(20px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}
.chat-widget.active {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}
.chat-header {
  background: #2563eb;
  padding: 20px;
  color: white;
}
.agent {
  display: flex;
  align-items: center;
  gap: 10px;
}
.agent img { border-radius: 50%; border: 2px solid white; }
.agent h4 { margin: 0; font-size: 1rem; }
.agent span { font-size: 0.8rem; opacity: 0.9; }
.chat-body {
  padding: 20px;
  height: 250px;
  background: #f9fafb;
  overflow-y: auto;
}
.msg {
  max-width: 80%;
  padding: 10px 15px;
  border-radius: 12px;
  margin-bottom: 10px;
  font-size: 0.9rem;
}
.income {
  background: #e5e7eb;
  color: #1f2937;
  border-bottom-left-radius: 2px;
}
.chat-footer {
  padding: 15px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 10px;
}
.chat-footer input {
  flex: 1;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  outline: none;
}
.chat-footer button {
  background: #2563eb;
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
}
const toggle = document.getElementById("chatToggle");
const widget = document.getElementById("chatWidget");

toggle.addEventListener("click", () => {
  toggle.classList.toggle("open");
  widget.classList.toggle("active");
});
Esc
↑↓ moveEnter select

Start from a template

Open an .html file, or HTML, CSS, JS, Markdown, Less or TypeScript files. You can also drop them here. Styles and scripts go into their panes.

Share

Source

Keyboard shortcuts

Save