Syntax-highlighted code blocks with language labels and copy actions for AI markdown.
Use CodeBlock for fenced code output, tool snippets, and AI-generated examples.
CodeBlock is a subpath-only import (@heroui-pro/react/code-block) because it depends on the optional shiki peer. It is not exported from the package root, so SSR apps that don't use it never need shiki installed.
import {CodeBlock} from "@heroui-pro/react/code-block";
<CodeBlock>
<CodeBlock.Header> {/* Optional */}
<span>typescript</span>
<CodeBlock.CopyButton code={code} /> {/* Optional */}
</CodeBlock.Header>
<CodeBlock.Code code={code} language="typescript" />
</CodeBlock>;HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
The Code Block component uses these CSS classes:
.code-block: Root code block surface.code-block__header: Header row.code-block__code: Code scroll region.code-block__copy-button: Copy/check icon buttonRoot container. Also supports native div props.
Header slot for language labels and actions. Also supports native div props.
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | - | Code to render |
language | string | 'plaintext' | Shiki language id |
theme | string | 'github-light' | Shiki theme |
Also supports native div props.
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | - | Code copied to clipboard |
aria-label | string | 'Copy code' | Accessible label |
className | string | - | Additional class |
Resources