Code Block
Code Block
Display code and terminal output with an optional header, line numbers, and copy button.
import { streamText } from "ai"
export async function POST(request: Request) {
const { messages } = await request.json()
const result = streamText({
model: "anthropic/claude-sonnet-4.5",
system: "You are a helpful assistant. Answer in one short paragraph.",
messages,
})
return result.toUIMessageStreamResponse()
}
<div class="code-block">
<header>
<span><svg aria-hidden="true" class="lucide lucide-file-code" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" /> <path d="M14 2v5a1 1 0 0 0 1 1h5" /> <path d="M10 12.5 8 15l2 2.5" /> <path d="m14 12.5 2 2.5-2 2.5" /> </svg>app/api/chat/route.ts</span>
<div>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" aria-label="Wrap lines" title="Wrap lines" aria-pressed="false" onclick="const pre = this.closest('.code-block').querySelector('pre'); this.setAttribute('aria-pressed', pre.toggleAttribute('data-wrap'))">
<svg aria-hidden="true" class="lucide lucide-wrap-text" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="m16 16-3 3 3 3" /> <path d="M3 12h14.5a1 1 0 0 1 0 7H13" /> <path d="M3 19h6" /> <path d="M3 5h18" /> </svg>
</button>
<a class="btn" data-variant="ghost" data-size="icon-xs" aria-label="Download" title="Download" download="route.ts" href="data:text/plain;charset=utf-8,import%20%7B%20streamText%20%7D%20from%20%22ai%22%0A%0Aexport%20async%20function%20POST(request%3A%20Request)%20%7B%0A%20%20const%20%7B%20messages%20%7D%20%3D%20await%20request.json()%0A%0A%20%20const%20result%20%3D%20streamText(%7B%0A%20%20%20%20model%3A%20%22anthropic%2Fclaude-sonnet-4.5%22%2C%0A%20%20%20%20system%3A%20%22You%20are%20a%20helpful%20assistant.%20Answer%20in%20one%20short%20paragraph.%22%2C%0A%20%20%20%20messages%2C%0A%20%20%7D)%0A%0A%20%20return%20result.toUIMessageStreamResponse()%0A%7D">
<svg aria-hidden="true" class="lucide lucide-download" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M12 15V3" /> <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /> <path d="m7 10 5 5 5-5" /> </svg>
</a>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" data-copy aria-label="Copy code" title="Copy code">
<svg aria-hidden="true" class="lucide lucide-copy" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /> </svg>
<svg aria-hidden="true" class="lucide lucide-check" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M20 6 9 17l-5-5" /> </svg>
</button>
</div>
</header>
<pre class="scrollbar" tabindex="0" aria-label="app/api/chat/route.ts" data-line-numbers><code><span><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583">import</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8"> { streamText } </span><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583">from</span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF"> "ai"</span></span>
<span></span>
<span><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583">export</span><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583"> async</span><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583"> function</span><span style="color:light-dark(#6F42C1, #B392F0);--shiki-light:#6F42C1;--shiki-dark:#B392F0"> POST</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="color:light-dark(#E36209, #FFAB70);--shiki-light:#E36209;--shiki-dark:#FFAB70">request</span><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583">:</span><span style="color:light-dark(#6F42C1, #B392F0);--shiki-light:#6F42C1;--shiki-dark:#B392F0"> Request</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">) {</span></span>
<span><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583"> const</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8"> { </span><span style="color:light-dark(#005CC5, #79B8FF);--shiki-light:#005CC5;--shiki-dark:#79B8FF">messages</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8"> } </span><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583"> await</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8"> request.</span><span style="color:light-dark(#6F42C1, #B392F0);--shiki-light:#6F42C1;--shiki-dark:#B392F0">json</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">()</span></span>
<span></span>
<span class="bg-foreground/5 forced-colors:outline"><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583"> const</span><span style="color:light-dark(#005CC5, #79B8FF);--shiki-light:#005CC5;--shiki-dark:#79B8FF"> result</span><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583"> =</span><span style="color:light-dark(#6F42C1, #B392F0);--shiki-light:#6F42C1;--shiki-dark:#B392F0"> streamText</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">({</span></span>
<span class="bg-foreground/5 forced-colors:outline"><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8"> model: </span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF">"anthropic/claude-sonnet-4.5"</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">,</span></span>
<span class="bg-foreground/5 forced-colors:outline"><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8"> system: </span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF">"You are a helpful assistant. Answer in one short paragraph."</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">,</span></span>
<span class="bg-foreground/5 forced-colors:outline"><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8"> messages,</span></span>
<span class="bg-foreground/5 forced-colors:outline"><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8"> })</span></span>
<span></span>
<span><span style="color:light-dark(#D73A49, #F97583);--shiki-light:#D73A49;--shiki-dark:#F97583"> return</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8"> result.</span><span style="color:light-dark(#6F42C1, #B392F0);--shiki-light:#6F42C1;--shiki-dark:#B392F0">toUIMessageStreamResponse</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">()</span></span>
<span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">}</span></span></code></pre>
</div>Usage
Load the styles
Load a full Basecoat style bundle, or import base/base.css, components/code-block.css, components/button.css, components/scrollbar.css, and one style pack after Tailwind.
Add the code block
Use .code-block around native <pre><code>. Add a semantic <header> or <footer> when needed. Use Button for actions and Scroll Area’s .scrollbar on the focusable <pre>.
<div class="code-block">
<header>
<span>Terminal</span>
<div>
<button type="button" class="btn" data-variant="ghost" data-size="xs" data-copy>Copy</button>
</div>
</header>
<pre class="scrollbar" tabindex="0" aria-label="Terminal output"><code>npm run build</code></pre>
</div>For syntax colors, see Syntax highlighting.
Enable copying (optional)
Add data-copy to the button that copies the block. Include the Basecoat runtime and code-block.js, or the full all.js bundle. Copy uses the Clipboard API, which requires HTTPS or localhost; failure is announced without pretending the copy succeeded. Without JavaScript, the code remains selectable.
HTML structure
Use a <span> for the header title and a <div> for actions. An actions <div> directly inside .code-block floats at the top end, appearing on hover, keyboard focus, or touch devices.
Scrollable code has a CSS edge fade in browsers with scroll-driven animations. Wrapping moves the fade to the vertical axis.
Line numbers are off by default. To opt in, add data-line-numbers to <pre> and wrap each line in a direct <span> inside <code>. Preserve real newline characters between lines, including empty lines. CSS counters supply the visual numbers, which are excluded from both native selection and the Copy button. Plain text needs no line wrappers; use them only for numbering, highlighting, or line-specific utilities.
Examples
Basic
$ pnpm build
> next build
✓ Compiled successfully in 4.2s
✓ Generating static pages (12/12)
Route (app) Size First Load JS
┌ ○ / 1.9 kB 112 kB
├ ○ /_not-found 993 B 103 kB
└ ƒ /api/chat 141 B 102 kB
<div class="code-block">
<pre class="scrollbar" tabindex="0" aria-label="Code"><code>$ pnpm build
> next build
✓ Compiled successfully in 4.2s
✓ Generating static pages (12/12)
Route (app) Size First Load JS
┌ ○ / 1.9 kB 112 kB
├ ○ /_not-found 993 B 103 kB
└ ƒ /api/chat 141 B 102 kB</code></pre>
</div>Header
Use a header for a filename or a label. The Copy button here copies the displayed terminal output.
$ pnpm add ai @ai-sdk/react zod
Packages: +14
Progress: resolved 412, reused 398, downloaded 14, added 14, done
Done in 2.8s using pnpm v10.18.0
<div class="code-block">
<header>
<span><svg aria-hidden="true" class="lucide lucide-terminal" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M12 19h8" /> <path d="m4 17 6-6-6-6" /> </svg>Terminal</span>
<div>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" data-copy aria-label="Copy code" title="Copy code">
<svg aria-hidden="true" class="lucide lucide-copy" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /> </svg>
<svg aria-hidden="true" class="lucide lucide-check" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M20 6 9 17l-5-5" /> </svg>
</button>
</div>
</header>
<pre class="scrollbar" tabindex="0" aria-label="Terminal"><code>$ pnpm add ai @ai-sdk/react zod
Packages: +14
Progress: resolved 412, reused 398, downloaded 14, added 14, done
Done in 2.8s using pnpm v10.18.0</code></pre>
</div>Actions
The header can hold any buttons or links your app needs. Try Wrap lines to switch the lint output between wrapped lines and horizontal scrolling. Download saves the output as lint.log using a native download link. Copy copies the same text to the clipboard. Basecoat handles Copy. Your app supplies the behavior for custom actions.
$ pnpm lint
apps/web/components/message-list.tsx
18:22 error 'messages' is possibly 'undefined'. Add a guard before calling map @typescript-eslint/no-unsafe-call
42:7 warning React Hook React.useEffect has a missing dependency: 'scrollToBottom' react-hooks/exhaustive-deps
✖ 2 problems (1 error, 1 warning)
<div class="code-block">
<header>
<span><svg aria-hidden="true" class="lucide lucide-terminal" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M12 19h8" /> <path d="m4 17 6-6-6-6" /> </svg>Terminal</span>
<div>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" aria-label="Wrap lines" title="Wrap lines" aria-pressed="true" onclick="const pre = this.closest('.code-block').querySelector('pre'); this.setAttribute('aria-pressed', pre.toggleAttribute('data-wrap'))">
<svg aria-hidden="true" class="lucide lucide-wrap-text" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="m16 16-3 3 3 3" /> <path d="M3 12h14.5a1 1 0 0 1 0 7H13" /> <path d="M3 19h6" /> <path d="M3 5h18" /> </svg>
</button>
<a class="btn" data-variant="ghost" data-size="icon-xs" aria-label="Download" title="Download" download="lint.log" href="data:text/plain;charset=utf-8,%24%20pnpm%20lint%0Aapps%2Fweb%2Fcomponents%2Fmessage-list.tsx%0A%20%2018%3A22%20%20error%20%20'messages'%20is%20possibly%20'undefined'.%20Add%20a%20guard%20before%20calling%20map%20%20%40typescript-eslint%2Fno-unsafe-call%0A%20%2042%3A7%20%20%20warning%20%20React%20Hook%20React.useEffect%20has%20a%20missing%20dependency%3A%20'scrollToBottom'%20%20react-hooks%2Fexhaustive-deps%0A%0A%E2%9C%96%202%20problems%20(1%20error%2C%201%20warning)">
<svg aria-hidden="true" class="lucide lucide-download" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M12 15V3" /> <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /> <path d="m7 10 5 5 5-5" /> </svg>
</a>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" data-copy aria-label="Copy code" title="Copy code">
<svg aria-hidden="true" class="lucide lucide-copy" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /> </svg>
<svg aria-hidden="true" class="lucide lucide-check" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M20 6 9 17l-5-5" /> </svg>
</button>
</div>
</header>
<pre class="scrollbar" tabindex="0" aria-label="Terminal" data-wrap><code>$ pnpm lint
apps/web/components/message-list.tsx
18:22 error 'messages' is possibly 'undefined'. Add a guard before calling map @typescript-eslint/no-unsafe-call
42:7 warning React Hook React.useEffect has a missing dependency: 'scrollToBottom' react-hooks/exhaustive-deps
✖ 2 problems (1 error, 1 warning)</code></pre>
</div>Floating actions
$ pnpm add ai @ai-sdk/react zod
Progress: resolved 412, reused 398, downloaded 14, added 14, done
dependencies:
+ @ai-sdk/react 3.0.12
+ ai 6.0.12
+ zod 4.1.12
Done in 2.8s using pnpm v10.18.0
<div class="code-block">
<div>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" data-copy aria-label="Copy code" title="Copy code">
<svg aria-hidden="true" class="lucide lucide-copy" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /> </svg>
<svg aria-hidden="true" class="lucide lucide-check" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M20 6 9 17l-5-5" /> </svg>
</button>
</div>
<pre class="scrollbar" tabindex="0" aria-label="Code"><code>$ pnpm add ai @ai-sdk/react zod
Progress: resolved 412, reused 398, downloaded 14, added 14, done
dependencies:
+ @ai-sdk/react 3.0.12
+ ai 6.0.12
+ zod 4.1.12
Done in 2.8s using pnpm v10.18.0</code></pre>
</div>Line numbers
Add data-line-numbers to opt in. Like upstream, unnumbered code is the default.
{
"name": "chat",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build"
}
}
<div class="code-block">
<pre class="scrollbar" tabindex="0" aria-label="Code" data-line-numbers><code><span>{</span>
<span> "name": "chat",</span>
<span> "private": true,</span>
<span> "scripts": {</span>
<span> "dev": "next dev",</span>
<span> "build": "next build"</span>
<span> }</span>
<span>}</span></code></pre>
</div>Wrapping
The first block scrolls horizontally. Adding data-wrap to the second block lets the same error message fit its width.
Error: The model "anthropic/claude-sonnet-4.5" returned an error: Request too large. The prompt is 212,431 tokens and the context window is 200,000 tokens. Remove some messages or summarize the conversation and try again.
Error: The model "anthropic/claude-sonnet-4.5" returned an error: Request too large. The prompt is 212,431 tokens and the context window is 200,000 tokens. Remove some messages or summarize the conversation and try again.
<div class="code-block">
<pre class="scrollbar" tabindex="0" aria-label="Scrollable error message"><code>Error: The model "anthropic/claude-sonnet-4.5" returned an error: Request too large. The prompt is 212,431 tokens and the context window is 200,000 tokens. Remove some messages or summarize the conversation and try again.</code></pre>
</div>
<div class="code-block">
<pre class="scrollbar" tabindex="0" aria-label="Wrapped error message" data-wrap><code>Error: The model "anthropic/claude-sonnet-4.5" returned an error: Request too large. The prompt is 212,431 tokens and the context window is 200,000 tokens. Remove some messages or summarize the conversation and try again.</code></pre>
</div>Highlighted lines
Apply ordinary utilities to the lines you want to emphasize. This recipe uses bg-foreground/5 and an outline in forced-colors mode. Unlike upstream’s line variants, these are example classes, not a Code Block API.
export default {
experimental: {
reactCompiler: true,
viewTransition: true,
},
images: {
remotePatterns: [{ hostname: "avatars.githubusercontent.com" }],
},
}
<div class="code-block">
<pre class="scrollbar" tabindex="0" aria-label="Code" data-line-numbers><code><span>export default {</span>
<span> experimental: {</span>
<span class="bg-foreground/5 forced-colors:outline"> reactCompiler: true,</span>
<span class="bg-foreground/5 forced-colors:outline"> viewTransition: true,</span>
<span> },</span>
<span> images: {</span>
<span> remotePatterns: [{ hostname: "avatars.githubusercontent.com" }],</span>
<span> },</span>
<span>}</span></code></pre>
</div>Diff
Render the patch as text, including its + and - prefixes, and use utilities for line backgrounds. The prefixes keep changes distinguishable without color. Native selection and the Copy button both copy the displayed patch, including its prefixes. No diff parser or dedicated variants are included.
export function Greeting({ name }: { name: string }) {
- return <p>Hello, {name}</p>
+ return <p className="text-sm text-muted-foreground">
+ Hello, {name}!
+ </p>
}
<div class="code-block">
<header>
<span>components/greeting.tsx</span>
<div>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" data-copy aria-label="Copy code" title="Copy code">
<svg aria-hidden="true" class="lucide lucide-copy" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /> </svg>
<svg aria-hidden="true" class="lucide lucide-check" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M20 6 9 17l-5-5" /> </svg>
</button>
</div>
</header>
<pre class="scrollbar" tabindex="0" aria-label="components/greeting.tsx"><code><span> export function Greeting({ name }: { name: string }) {</span>
<span class="bg-destructive/10">- return <p>Hello, {name}</p></span>
<span class="bg-foreground/5">+ return <p className="text-sm text-muted-foreground"></span>
<span class="bg-foreground/5">+ Hello, {name}!</span>
<span class="bg-foreground/5">+ </p></span>
<span> }</span></code></pre>
</div>Height
Use ordinary height utilities to constrain a block. The native scroll area remains keyboard-accessible.
[01] GET /api/chat 200 in 12ms
[02] GET /api/chat 200 in 19ms
[03] GET /api/chat 200 in 26ms
[04] GET /api/chat 200 in 33ms
[05] GET /api/chat 200 in 40ms
[06] GET /api/chat 200 in 47ms
[07] GET /api/chat 200 in 14ms
[08] GET /api/chat 200 in 21ms
[09] GET /api/chat 200 in 28ms
[10] GET /api/chat 200 in 35ms
[11] GET /api/chat 200 in 42ms
[12] GET /api/chat 200 in 49ms
[13] GET /api/chat 200 in 16ms
[14] GET /api/chat 200 in 23ms
[15] GET /api/chat 200 in 30ms
[16] GET /api/chat 200 in 37ms
[17] GET /api/chat 200 in 44ms
[18] GET /api/chat 200 in 51ms
[19] GET /api/chat 200 in 18ms
[20] GET /api/chat 200 in 25ms
[21] GET /api/chat 200 in 32ms
[22] GET /api/chat 200 in 39ms
[23] GET /api/chat 200 in 46ms
[24] GET /api/chat 200 in 13ms
[25] GET /api/chat 200 in 20ms
[26] GET /api/chat 200 in 27ms
[27] GET /api/chat 200 in 34ms
[28] GET /api/chat 200 in 41ms
[29] GET /api/chat 200 in 48ms
[30] GET /api/chat 200 in 15ms
[31] GET /api/chat 200 in 22ms
[32] GET /api/chat 200 in 29ms
[33] GET /api/chat 200 in 36ms
[34] GET /api/chat 200 in 43ms
[35] GET /api/chat 200 in 50ms
[36] GET /api/chat 200 in 17ms
[37] GET /api/chat 200 in 24ms
[38] GET /api/chat 200 in 31ms
[39] GET /api/chat 200 in 38ms
[40] GET /api/chat 200 in 45ms
<div class="code-block">
<header>
<span>Logs</span>
<div>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" data-copy aria-label="Copy code" title="Copy code">
<svg aria-hidden="true" class="lucide lucide-copy" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /> </svg>
<svg aria-hidden="true" class="lucide lucide-check" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M20 6 9 17l-5-5" /> </svg>
</button>
</div>
</header>
<pre class="scrollbar max-h-48" tabindex="0" aria-label="Logs"><code>[01] GET /api/chat 200 in 12ms
[02] GET /api/chat 200 in 19ms
[03] GET /api/chat 200 in 26ms
[04] GET /api/chat 200 in 33ms
[05] GET /api/chat 200 in 40ms
[06] GET /api/chat 200 in 47ms
[07] GET /api/chat 200 in 14ms
[08] GET /api/chat 200 in 21ms
[09] GET /api/chat 200 in 28ms
[10] GET /api/chat 200 in 35ms
[11] GET /api/chat 200 in 42ms
[12] GET /api/chat 200 in 49ms
[13] GET /api/chat 200 in 16ms
[14] GET /api/chat 200 in 23ms
[15] GET /api/chat 200 in 30ms
[16] GET /api/chat 200 in 37ms
[17] GET /api/chat 200 in 44ms
[18] GET /api/chat 200 in 51ms
[19] GET /api/chat 200 in 18ms
[20] GET /api/chat 200 in 25ms
[21] GET /api/chat 200 in 32ms
[22] GET /api/chat 200 in 39ms
[23] GET /api/chat 200 in 46ms
[24] GET /api/chat 200 in 13ms
[25] GET /api/chat 200 in 20ms
[26] GET /api/chat 200 in 27ms
[27] GET /api/chat 200 in 34ms
[28] GET /api/chat 200 in 41ms
[29] GET /api/chat 200 in 48ms
[30] GET /api/chat 200 in 15ms
[31] GET /api/chat 200 in 22ms
[32] GET /api/chat 200 in 29ms
[33] GET /api/chat 200 in 36ms
[34] GET /api/chat 200 in 43ms
[35] GET /api/chat 200 in 50ms
[36] GET /api/chat 200 in 17ms
[37] GET /api/chat 200 in 24ms
[38] GET /api/chat 200 in 31ms
[39] GET /api/chat 200 in 38ms
[40] GET /api/chat 200 in 45ms</code></pre>
</div>Size
$ pnpm add ai @ai-sdk/react zod
Progress: resolved 412, reused 398, downloaded 14, added 14, done
Done in 2.8s using pnpm v10.18.0
$ pnpm add ai @ai-sdk/react zod
Progress: resolved 412, reused 398, downloaded 14, added 14, done
Done in 2.8s using pnpm v10.18.0
<div class="code-block">
<header>
<span><svg aria-hidden="true" class="lucide lucide-terminal" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M12 19h8" /> <path d="m4 17 6-6-6-6" /> </svg>Terminal</span>
<div>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" data-copy aria-label="Copy code" title="Copy code">
<svg aria-hidden="true" class="lucide lucide-copy" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /> </svg>
<svg aria-hidden="true" class="lucide lucide-check" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M20 6 9 17l-5-5" /> </svg>
</button>
</div>
</header>
<pre class="scrollbar" tabindex="0" aria-label="Terminal" data-wrap><code>$ pnpm add ai @ai-sdk/react zod
Progress: resolved 412, reused 398, downloaded 14, added 14, done
Done in 2.8s using pnpm v10.18.0</code></pre>
</div>
<div class="code-block" data-size="sm">
<header>
<span><svg aria-hidden="true" class="lucide lucide-terminal" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M12 19h8" /> <path d="m4 17 6-6-6-6" /> </svg>Terminal</span>
<div>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" data-copy aria-label="Copy code" title="Copy code">
<svg aria-hidden="true" class="lucide lucide-copy" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /> </svg>
<svg aria-hidden="true" class="lucide lucide-check" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M20 6 9 17l-5-5" /> </svg>
</button>
</div>
</header>
<pre class="scrollbar" tabindex="0" aria-label="Terminal" data-wrap><code>$ pnpm add ai @ai-sdk/react zod
Progress: resolved 412, reused 398, downloaded 14, added 14, done
Done in 2.8s using pnpm v10.18.0</code></pre>
</div>Destructive
TypeError: Cannot read properties of undefined (reading 'map')
at MessageList (components/message-list.tsx:18:22)
at renderWithHooks (react-dom.development.js:16305:18)
<div class="code-block" data-variant="destructive">
<header>
<span>Error</span>
<div>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" data-copy aria-label="Copy code" title="Copy code">
<svg aria-hidden="true" class="lucide lucide-copy" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /> </svg>
<svg aria-hidden="true" class="lucide lucide-check" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M20 6 9 17l-5-5" /> </svg>
</button>
</div>
</header>
<pre class="scrollbar" tabindex="0" aria-label="Error" data-wrap><code>TypeError: Cannot read properties of undefined (reading 'map')
at MessageList (components/message-list.tsx:18:22)
at renderWithHooks (react-dom.development.js:16305:18)</code></pre>
</div>Syntax highlighting
Code Block displays plain text by default. To color the keys, strings, and numbers in this JSON example, the docs run Shiki at build time and place its colored spans inside <pre><code>. The browser receives ordinary HTML. Basecoat styles the block, and the Shiki theme supplies the token colors.
{
"location": "San Francisco",
"temperature": 18,
"unit": "celsius",
"conditions": ["fog", "wind"]
}
<div class="code-block">
<header>
<span>getWeather output</span>
</header>
<pre class="scrollbar" tabindex="0" aria-label="getWeather output"><code><span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">{</span></span>
<span><span style="color:light-dark(#005CC5, #79B8FF);--shiki-light:#005CC5;--shiki-dark:#79B8FF"> "location"</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">: </span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF">"San Francisco"</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">,</span></span>
<span><span style="color:light-dark(#005CC5, #79B8FF);--shiki-light:#005CC5;--shiki-dark:#79B8FF"> "temperature"</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">: </span><span style="color:light-dark(#005CC5, #79B8FF);--shiki-light:#005CC5;--shiki-dark:#79B8FF">18</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">,</span></span>
<span><span style="color:light-dark(#005CC5, #79B8FF);--shiki-light:#005CC5;--shiki-dark:#79B8FF"> "unit"</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">: </span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF">"celsius"</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">,</span></span>
<span><span style="color:light-dark(#005CC5, #79B8FF);--shiki-light:#005CC5;--shiki-dark:#79B8FF"> "conditions"</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">: [</span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF">"fog"</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF">"wind"</span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">]</span></span>
<span><span style="color:light-dark(#24292E, #E1E4E8);--shiki-light:#24292E;--shiki-dark:#E1E4E8">}</span></span></code></pre>
</div>RTL
The header follows the page direction. Code always reads left to right.
ثبّت الحزم، ثم شغّل خادم التطوير.
pnpm add ai @ai-sdk/react zod
pnpm dev
<div dir="rtl" class="grid gap-3 text-sm">
<p>ثبّت الحزم، ثم شغّل خادم التطوير.</p>
<div class="code-block">
<header>
<span><svg aria-hidden="true" class="lucide lucide-terminal" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M12 19h8" /> <path d="m4 17 6-6-6-6" /> </svg>الطرفية</span>
<div>
<button type="button" class="btn" data-variant="ghost" data-size="icon-xs" data-copy aria-label="Copy code" title="Copy code">
<svg aria-hidden="true" class="lucide lucide-copy" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /> </svg>
<svg aria-hidden="true" class="lucide lucide-check" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <path d="M20 6 9 17l-5-5" /> </svg>
</button>
</div>
</header>
<pre class="scrollbar" tabindex="0" aria-label="الطرفية" data-line-numbers><code><span><span style="color:light-dark(#6F42C1, #B392F0);--shiki-light:#6F42C1;--shiki-dark:#B392F0">pnpm</span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF"> add</span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF"> ai</span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF"> @ai-sdk/react</span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF"> zod</span></span>
<span><span style="color:light-dark(#6F42C1, #B392F0);--shiki-light:#6F42C1;--shiki-dark:#B392F0">pnpm</span><span style="color:light-dark(#032F62, #9ECBFF);--shiki-light:#032F62;--shiki-dark:#9ECBFF"> dev</span></span></code></pre>
</div>
</div>