Skip to content

Code Block Message

A copy-paste ai / chat ui component in pure HTML & CSS. Zero dependencies, framework-agnostic, MIT-licensed.

AI / Chat UIHTMLCSSany framework
TypeScript
const sum = (a, b) => a + b;

Copy into your project

HTML
<!-- Code Block Message — language chip + copy button + streaming caret -->
<div class="nuda-ac2-codemsg">
  <div class="nuda-ac2-codemsg__bar">
    <span class="nuda-ac2-codemsg__lang">TypeScript</span>
    <button class="nuda-ac2-codemsg__copy" aria-label="Copy code" type="button">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
           stroke-linecap="round" stroke-linejoin="round">
        <rect x="8" y="8" width="13" height="13" rx="2" />
        <path d="M16 8 L16 5 A 2 2 0 0 0 14 3 L5 3 A 2 2 0 0 0 3 5 L3 14 A 2 2 0 0 0 5 16 L8 16" />
      </svg>
      <span>Copy</span>
    </button>
  </div>
  <pre class="nuda-ac2-codemsg__pre"><code class="nuda-ac2-codemsg__code">const sum = (a, b) => a + b;</code></pre>
</div>
CSS
.nuda-ac2-codemsg {
  width: 300px;
  background: #0e0e0e;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  overflow: hidden;
  box-sizing: border-box;
  font: 12px ui-sans-serif,system-ui,sans-serif;
}

.nuda-ac2-codemsg__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #161616;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.nuda-ac2-codemsg__lang {
  color: #777;
  font-size: 11px;
  letter-spacing: .02em;
}

.nuda-ac2-codemsg__copy {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 2px 8px;
  background: transparent;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px;
  color: #a1a1aa;
  font-size: 11px;
  cursor: pointer;
  transition: color .2s,border-color .2s,background .2s;
}

.nuda-ac2-codemsg__copy svg {
  width: 11px;
  height: 11px;
}

.nuda-ac2-codemsg__copy:hover {
  color: #e4ff54;
  border-color: rgba(228,255,84,.4);
  background: rgba(228,255,84,.08);
}

.nuda-ac2-codemsg__pre {
  margin: 0;
  padding: 10px;
  overflow-x: auto;
}

.nuda-ac2-codemsg__code {
  color: #cfcfcf;
  font-family: ui-monospace,Menlo,monospace;
  font-size: 11.5px;
  white-space: pre;
}

.nuda-ac2-codemsg__code::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 12px;
  margin-left: 2px;
  background: #e4ff54;
  vertical-align: -2px;
  animation: _nuda-ac2codemsg 1s step-end infinite;
}

@keyframes _nuda-ac2codemsg {
  50% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nuda-ac2-codemsg__code::after {
    animation: none !important;
    opacity: 1;
  }
}

How to use Code Block Message

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More ai / chat ui components

← Browse all NudaUI components