AI Snippet

Copy. Paste. Ship.

Home › Code Snippets › AI › Chat Sidebar

Snippet

AI Chat Sidebar

Right-docked copilot panel with suggestion chips, message flow, and a composer.

Last updated: October 2026

What this snippet does: A right-docked AI copilot panel. Collapsible, with suggestion chips, chat messages, and an input composer. Works alongside your main content — no modal takeover. Pure HTML, CSS, vanilla JS.

🎬 Live Demo

Click a suggestion chip or type a message.

📄 Your Document

The AI sidebar sits alongside your content. Users can consult it without losing their place. Click the chevron to collapse it.

This pattern is used in Notion AI, Linear, Vercel, and modern IDEs.

📝

How It Works

The sidebar is absolutely positioned to the right of a relative container. It slides in/out via transform: translateX(). Suggestion chips dispatch messages; the composer accepts text. Hook up respond() to your AI API.

1

HTML Structure

<div class="ai-sidebar-wrap">
  <div class="ai-sidebar-main">Your content</div>
  <aside class="ai-sidebar">
    <div class="ai-sidebar-head">AI Assistant</div>
    <div class="ai-sidebar-body">Messages + chips</div>
    <div class="ai-sidebar-composer">
      <input placeholder="Ask anything...">
      <button>↑</button>
    </div>
  </aside>
</div>
2

Core CSS

.ai-sidebar-wrap { position: relative; height: 480px; }
.ai-sidebar {
  position: absolute; top: 0; right: 0; bottom: 0; width: 340px;
  transition: transform 0.3s ease;
  display: flex; flex-direction: column;
}
.ai-sidebar.collapsed { transform: translateX(300px); }
3

JavaScript — Hook to Real API

async function respond(q) {
  appendMsg(q, 'user');
  const res = await fetch('/api/chat', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ prompt: q })
  });
  const data = await res.json();
  appendMsg(data.reply, 'bot');
}

🎨 Customization

Property Effect Default
Sidebar widthPanel size340px
Animation durationSlide speed0.3s ease
Accent colorSend button, user bubbles#3b82f6

🎯 Use Cases

⚠️ Common Mistakes

🎯 What's Next?

← AI Hub