100 Free AI UI Components

Split View: Chat and Document

Chat on one side and a live document on the other, the layout used by AI writing tools. On phones it switches to two tabs.

One HTML file with the CSS and JavaScript inside. No library needed. MIT license.

Live preview

How to use it

  1. Click Copy the code, or download the file.
  2. Paste the CSS into your stylesheet, the HTML where you want the component, and the script before the closing body tag.
  3. Change --accent at the top of the CSS to your brand color, then connect the events to your AI service.

What you get

  • Works in light and dark mode automatically
  • Keyboard friendly, with labels for screen readers
  • Fits phones, tablets and desktops
  • Respects the reduced motion setting
  • No framework, so it works with any stack

The code

<!DOCTYPE html>
<!--
  Split View: Chat and Document: a free AI UI component
  From 100 Free AI UI Components by MM Rahman Bappi, MIT license
  https://mmrahmanbappi.github.io/100-free-ai-ui-components/

  How to use: copy the CSS, HTML and JavaScript below into your page.
  Colors are CSS variables at the top. Change --accent to match your brand.
  Light and dark themes follow the visitor's system setting, or set
  data-theme="dark" or data-theme="light" on the html element.
-->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Split View: Chat and Document | Free AI UI Component</title>
<meta name="description" content="Chat on one side and a live document on the other, the layout used by AI writing tools. On phones it switches to two tabs.">
<meta name="robots" content="noindex, follow">
<style>
:root{
  --accent:#5b5bd6; --accent-ink:#fff; --accent-soft:#ececfc;
  --bg:#f7f7f8; --surface:#fff; --surface-2:#f1f1f4; --ink:#17171c; --text:#3a3a44; --muted:#6c6c78;
  --line:#e3e3e8; --good:#15803d; --warn:#b45309; --bad:#c62828;
  --radius:14px; --shadow:0 1px 2px rgba(20,20,30,.06),0 8px 24px -12px rgba(20,20,30,.18);
  --font:system-ui,-apple-system,"Segoe UI",Roboto,Ubuntu,sans-serif; --mono:ui-monospace,"Cascadia Code",Menlo,Consolas,monospace;
}
@media (prefers-color-scheme:dark){:root:not([data-theme=light]){
  --accent:#8b8bff; --accent-ink:#0f0f16; --accent-soft:#25254a;
  --bg:#0f0f13; --surface:#18181f; --surface-2:#212129; --ink:#f3f3f6; --text:#d4d4dc; --muted:#9a9aa8;
  --line:#2c2c36; --good:#4ade80; --warn:#fbbf24; --bad:#f87171; --shadow:0 1px 2px rgba(0,0,0,.4),0 10px 30px -12px rgba(0,0,0,.6);
}}
:root[data-theme=dark]{
  --accent:#8b8bff; --accent-ink:#0f0f16; --accent-soft:#25254a;
  --bg:#0f0f13; --surface:#18181f; --surface-2:#212129; --ink:#f3f3f6; --text:#d4d4dc; --muted:#9a9aa8;
  --line:#2c2c36; --good:#4ade80; --warn:#fbbf24; --bad:#f87171; --shadow:0 1px 2px rgba(0,0,0,.4),0 10px 30px -12px rgba(0,0,0,.6);
}
*{box-sizing:border-box}
html,body{margin:0}
body{min-height:100vh;display:grid;grid-template-columns:minmax(0,1fr);place-items:center;padding:24px;background:var(--bg);color:var(--text);font:15px/1.5 var(--font);-webkit-font-smoothing:antialiased}
button,input,textarea,select{font:inherit;color:inherit}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
[hidden]{display:none!important}
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
@media (prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition:none!important}}
/* ---- component ---- */
.msgs{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:12px;scroll-behavior:smooth}
.m{max-width:80%;padding:9px 13px;border-radius:14px;line-height:1.55;font-size:14px;overflow-wrap:anywhere;animation:pop .2s ease}
.m.u{align-self:flex-end;background:var(--accent);color:var(--accent-ink);border-bottom-right-radius:4px}
.m.a{align-self:flex-start;background:var(--surface-2);color:var(--text);border-bottom-left-radius:4px}
@keyframes pop{from{opacity:0;transform:translateY(5px)}}
.pb{display:flex;gap:8px;align-items:flex-end;padding:10px;border-top:1px solid var(--line);background:var(--surface)}
.pb textarea{flex:1;border:1px solid var(--line);border-radius:12px;padding:9px 12px;resize:none;background:var(--surface);color:var(--ink);max-height:120px;line-height:1.45;min-width:0}
.pb textarea:focus{outline:0;border-color:var(--accent)}
.send{width:38px;height:38px;border-radius:11px;border:0;background:var(--accent);color:var(--accent-ink);display:grid;place-items:center;cursor:pointer;flex:none}
.send:disabled{opacity:.35;cursor:not-allowed}
.ib{width:34px;height:34px;display:grid;place-items:center;border:0;background:none;color:var(--muted);border-radius:9px;cursor:pointer;flex:none}
.ib:hover{background:var(--surface-2);color:var(--ink)}
body{padding:0;place-items:stretch}
.app{display:grid;grid-template-columns:minmax(300px,2fr) 3fr;height:100vh;width:100%}
.chatp{display:flex;flex-direction:column;border-right:1px solid var(--line);background:var(--surface);min-width:0;min-height:0}
.doc{overflow-y:auto;background:var(--surface-2);padding:28px;min-width:0}
.paper{max-width:620px;margin:0 auto;background:var(--surface);border:1px solid var(--line);border-radius:12px;padding:28px 32px;box-shadow:var(--shadow)}
.paper h1{font-size:22px;color:var(--ink);margin:0 0 12px}.paper p{line-height:1.7;margin:0 0 12px}
.paper mark{background:color-mix(in srgb,var(--accent) 22%,transparent);color:inherit;border-radius:3px;padding:0 2px;animation:hl 1.5s ease}
@keyframes hl{from{background:color-mix(in srgb,var(--accent) 55%,transparent)}}
.tabs{display:none}
@media(max-width:700px){.app{grid-template-columns:1fr;grid-template-rows:auto 1fr}.tabs{display:flex;border-bottom:1px solid var(--line);background:var(--surface)}
  .tabs button{flex:1;border:0;background:none;padding:12px;font-weight:600;color:var(--muted);cursor:pointer;border-bottom:2px solid transparent}
  .tabs button[aria-selected=true]{color:var(--ink);border-color:var(--accent)}
  .chatp,.doc{grid-row:2;grid-column:1}.app[data-tab=doc] .chatp,.app[data-tab=chat] .doc{display:none}.doc{padding:14px}.paper{padding:20px}}
</style>
</head>
<body>
<div class="app" id="app" data-tab="chat">
  <div class="tabs" role="tablist"><button role="tab" aria-selected="true" data-t="chat" aria-controls="cp">Chat</button><button role="tab" aria-selected="false" data-t="doc" aria-controls="dp">Document</button></div>
  <section class="chatp" id="cp" role="tabpanel" aria-label="Chat"><div class="msgs" id="msgs" role="log" aria-live="polite" aria-label="Messages"></div>
<form class="pb" id="pf"><label class="sr" for="pq">Message</label><textarea id="pq" rows="1" placeholder="Message the assistant"></textarea><button class="send" id="ps" type="submit" aria-label="Send message" disabled><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 19V5M5 12l7-7 7 7"/></svg></button></form></section>
  <section class="doc" id="dp" role="tabpanel" aria-label="Document"><article class="paper"><h1>Welcome email</h1>
    <p id="p1">Hi Sam, welcome to the team! We are so glad you are here.</p>
    <p id="p2">Your first week will be about meeting people and getting set up. On Monday you will have lunch with the design team.</p>
    <p id="p3">If you have questions, just reply to this email.</p></article></section>
</div>
<script>
// Demo helper: add ?theme=dark or ?theme=light to the address to preview a theme.
(function(){var t=new URLSearchParams(location.search).get('theme');if(t)document.documentElement.dataset.theme=t;})();
var REPLIES=['Good question. Here is a short answer you can use right away.','Sure. I would start with the simplest option and adjust from there.','Here is a quick plan: first list what you need, then pick one small step for today.'];
function chat(root,seed){var msgs=root.querySelector('#msgs'),f=root.querySelector('#pf'),q=root.querySelector('#pq'),s=root.querySelector('#ps'),busy=false,n=0;
  function add(role,text){var d=document.createElement('div');d.className='m '+role;d.textContent=text;msgs.appendChild(d);msgs.scrollTop=msgs.scrollHeight;return d;}
  function grow(){q.style.height='auto';q.style.height=Math.min(q.scrollHeight,120)+'px';}
  (seed||[]).forEach(function(p){add(p[0],p[1]);});
  q.addEventListener('input',function(){grow();s.disabled=!q.value.trim()||busy;});
  q.addEventListener('keydown',function(e){if(e.key==='Enter'&&!e.shiftKey&&!e.isComposing){e.preventDefault();f.requestSubmit();}});
  f.addEventListener('submit',function(e){e.preventDefault();var t=q.value.trim();if(!t||busy)return;add('u',t);q.value='';grow();s.disabled=true;busy=true;
    var d=add('a',''),words=REPLIES[n++%REPLIES.length].split(' '),i=0;
    (function tick(){if(i<words.length){d.textContent+=(i?' ':'')+words[i++];msgs.scrollTop=msgs.scrollHeight;setTimeout(tick,60);}else{busy=false;s.disabled=!q.value.trim();}})();});
  return {add:add};}
var app=document.getElementById('app'),tabs=[].slice.call(document.querySelectorAll('.tabs button'));
var c=chat(document.getElementById('cp'),[['u','Write a short welcome email for a new designer named Sam.'],['a','Done. I wrote it in the document on the right. Want it warmer or shorter?']]);
tabs.forEach(function(t){t.addEventListener('click',function(){app.dataset.tab=t.dataset.t;tabs.forEach(function(x){x.setAttribute('aria-selected',x===t);});});});
// When a new message is sent, pretend the AI edits the document
document.getElementById('pf').addEventListener('submit',function(){setTimeout(function(){var p=document.getElementById('p2');
  p.innerHTML='Your first week will be about meeting people and getting set up. <mark>We have planned a relaxed lunch on Monday so you can meet the design team.</mark>';},800);});
</script>
</body>
</html>

More chat layouts components

  • Full Chat Window

    A complete chat screen with a header, scrolling messages and a prompt box at the bottom. Replies stream in, and the view follows along.

  • Chat Sidebar

    A sidebar with past chats grouped by date, a New chat button and the current chat highlighted. On phones it slides in from a menu button.

  • Empty Chat Welcome Screen

    The first screen of a new chat: a greeting, example prompts, what the assistant can do and its limits, with the prompt box ready below.

  • Floating Chat Widget

    A round chat button in the corner that opens a small chat panel, with an unread badge. Escape or the close button hides it again.

  • Mobile Chat Screen

    A phone-sized chat with a back button, assistant name and status, messages, and a prompt bar with an attach button, sized for thumbs.

  • Conversation Search

    Search through past chats as you type. Matching words are highlighted, and a friendly message appears when nothing is found.