Put a header and the content in the root.
example-code.tsx
CodeBlock
<figure>| Prop | Type | Default | Description |
|---|---|---|---|
| palette | "color""ink""theme" | — | |
| variant | "framed""plain" | — | |
| wrap | boolean | — | Wrap long lines (controlled). The Wrap toggle sets it. |
| default | boolean | false | Wrap long lines at first (uncontrolled). Default false: code scrolls sideways. |
| on | — | ||
| streaming | boolean | false | The code still arrives: an AI answer or a tool writes it now. The content shows plain text with fresh ink on the newest characters, Copy waits, and CodeBlockStatus says "Writing" with the line count. When it turns false, the syntax colors fade in once and the status says "Wrote N lines". Default false. |
| interrupted | "cut-off""stopped" | — | The stream ended before the code was whole: stopped (a person stopped it) or cut-off (the reply ended inside the block, a destructive edge). A note under the code says so. |
| ...props | <figure> attributes | — | Every other attribute goes to the <figure>, with a ref. |
CodeBlockHeader
<div>| Prop | Type | Default | Description |
|---|---|---|---|
| ...props | <div> attributes | — | Every other attribute goes to the <div>, with a ref. |
CodeBlockTitle
<div>| Prop | Type | Default | Description |
|---|---|---|---|
| ...props | <div> attributes | — | Every other attribute goes to the <div>, with a ref. |
CodeBlockLanguage
<span>| Prop | Type | Default | Description |
|---|---|---|---|
| lang | string | — | The language: its short label comes from languageLabel (tsx → "TSX"). |
| ...props | <span> attributes | — | Every other attribute goes to the <span>, with a ref. |
CodeBlockCopyButton
<button>| Prop | Type | Default | Description | ||||
|---|---|---|---|---|---|---|---|
| aria-label | string | — | Defines a string value that labels the current element. The name of the button. An icon-only button defaults to "Copy"; one with text uses its text. | ||||
| class | string | — | |||||
| busy | boolean | — | The button waits for the app (busy words): a spinner, aria-busy, and no clicks. Focus stays on the button. The style hook stays data-loading. | ||||
| spinner | "center""start" | — | center (default): the spinner covers the label. start: it takes the leading icon slot. The icon sizes always use center, because their one icon is the label. | ||||
| timeout | number | — | How long the result (check or X) shows, in ms. Default 2000. | ||||
| on | — | Runs after the clipboard has the text, with the text. | |||||
| on | — | Runs when the copy fails: no Clipboard API, the browser refused, or getValue failed. | |||||
| glass | "clear""dark""light" | — | |||||
| rounded | "default""full" | — | |||||
| size | "default""icon""icon-lg""icon-sm""icon-xs""lg""sm""xl""xs" | — | |||||
| variant | "dashed""default""destructive""destructive-outline""ghost""link""media""outline""secondary" | — | |||||
From Base UIButtonBase UI docs | |||||||
| focusable | boolean | false | Whether the button should be focusable when disabled. | ||||
| render | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render. | |||||
| style | — | Style applied to the element, or a function that returns a style object based on the component's state. | |||||
| |||||||
| ...props | <button> attributes | — | Every other attribute goes to the <button>, with a ref. | ||||
CodeBlockWrapToggle
<button>| Prop | Type | Default | Description | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| class | string | — | ||||||||||||
From Base UIToggleBase UI docs | ||||||||||||||
| disabled | boolean | false | Whether the component should ignore user interaction. | |||||||||||
| value | string | — | A unique string that identifies the toggle when used inside a toggle group. | |||||||||||
| render | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render. | ||||||||||||
| ||||||||||||||
| ...props | <button> attributes | — | Every other attribute goes to the <button>, with a ref. | |||||||||||
CodeBlockActions
<div>| Prop | Type | Default | Description |
|---|---|---|---|
| ...props | <div> attributes | — | Every other attribute goes to the <div>, with a ref. |
CodeBlockFooter
<div>| Prop | Type | Default | Description |
|---|---|---|---|
| ...props | <div> attributes | — | Every other attribute goes to the <div>, with a ref. |
CodeBlockContent
<pre>| Prop | Type | Default | Description |
|---|---|---|---|
| aria-label | string | — | Defines a string value that labels the current element. The name of the code region for screen readers. Default: "<Language> code". |
| lang | string | — | The language: a name or alias that highlighter knows (ts, bash, md). Default: plain text. |
| code | string | — | The source code. Copy copies it as is. While the block streams, the code so far. |
| line | boolean | true | Show line numbers. Default true. |
| start | number | 1 | The number of the first line, for a part of a file. Default 1. |
| numbers | — | Own line numbers, one entry per line, in place of startLine: one column, or two for a diff ([old, new]; undefined leaves a cell empty: an added line has no old number). Shown even with lineNumbers={false}. | |
| marks | — | A mark for a line, by its shown number: { 4: "highlight", 7: "inserted" }. | |
| focus | readonly number[] | — | Lines in focus, by their shown number: a tint band and a 2px edge at the start. The other lines keep full contrast. |
| words | readonly string[] | — | Word marks: each match of each string. |
| ranges | — | Word marks by character range in code: [start, end], end not included. | |
| prompt | string | — | A prompt before each line ($), not selectable and not copied. |
| max | number | — | Fold code longer than this many lines in a Spoiler: the first lines under a fade, and "Show all N lines" centered under the code. |
| expanded | boolean | — | Shows every line when maxLines applies (controlled). |
| default | boolean | false | Start expanded when maxLines applies (uncontrolled). |
| on | — | Runs when the fold trigger shows or hides the lines past maxLines. | |
| labels | CodeBlockContentLabels | — | The words of the fold trigger (expand, collapse) and of the stream notes. |
| reveal | "off""paragraph""word" | "word" | The pace of streamed code (#/lib/stream-pace): word (default) shows bursts at an even rate on the frame clock, off shows the code as it comes. A part that paces its text already (Streaming Markdown) passes off. |
| class | string | — | Classes of the scroll box around the <pre>: set a height here (max-h-96). |
| ...props | <pre> attributes | — | Every other attribute goes to the <pre>, with a ref. |
CodeBlockLine
<span>| Prop | Type | Default | Description |
|---|---|---|---|
| mark | "deleted""error""highlight""inserted""warning" | — | The mark of the line: its tint, and for inserted and deleted an <ins> or <del> element, so a screen reader can say the change. |
| number | number | — | The shown line number (data-line). |
| focused | boolean | false | A line in focus: the default tint band and a 2px edge at the start. |
| last | boolean | false | The last line of a stream (data-last). |
| ...props | <span> attributes | — | Every other attribute goes to the <span>. |
CodeBlockStatus
<span>| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | A mark before "Writing" while the code arrives: the Agent Presence orb with the writing verb in the AI items (<AiAgentPresence verb="writing" size={14} aria-hidden />). |
| labels | CodeBlockStatusLabels | — | |
| ...props | <span> attributes | — | Every other attribute goes to the <span>, with a ref. |
CodeBlockTabs
<div>| Prop | Type | Default | Description | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| class | string | — | ||||||||||||||||||||||
| sync | string | — | Share the open tab with every block that has the same key, and keep it for the next visit: "package-manager", "framework". Works with string tab values. A block that has no tab for the shared choice keeps its own tab. | |||||||||||||||||||||
From Base UITabs.RootBase UI docs | ||||||||||||||||||||||||
| value | any | — | The value of the currently active Tab. Use when the component is controlled. When the value is null, no Tab will be active. | |||||||||||||||||||||
| default | any | 0 | The default value. Use when the component is not controlled. When the value is null, no Tab will be active. | |||||||||||||||||||||
| orientation | "horizontal""vertical" | 'horizontal' | The component orientation (layout flow direction). | |||||||||||||||||||||
| ||||||||||||||||||||||||
| ...props | <div> attributes | — | Every other attribute goes to the <div>, with a ref. | |||||||||||||||||||||
CodeBlockTabsList
<div>| Prop | Type | Default | Description | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| class | string | — | ||||||||
| rounded | "default""full" | — | ||||||||
| size | "default""lg""sm" | — | ||||||||
From Base UITabs.ListBase UI docs | ||||||||||
| activate | boolean | false | Whether to automatically change the active tab on arrow key focus. Otherwise, tabs will be activated using <kbd>Enter</kbd> or <kbd>Space</kbd> key press. | |||||||
| loop | boolean | true | Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys. | |||||||
| render | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render. | ||||||||
| ||||||||||
| ...props | <div> attributes | — | Every other attribute goes to the <div>, with a ref. | |||||||
CodeBlockTab
<button>| Prop | Type | Default | Description | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| class | string | — | ||||||||||||
From Base UITabs.TabBase UI docs | ||||||||||||||
| value | any | — | The value of the Tab. | |||||||||||
| disabled | boolean | — | Whether the Tab is disabled. If a first Tab on a <Tabs.List> is disabled, it won't initially be selected. Instead, the next enabled Tab will be selected. However, it does not work like this during server-side rendering, as it is not known during pre-rendering which Tabs are disabled. To work around it, ensure that defaultValue or value on <Tabs.Root> is set to an enabled Tab's value. | |||||||||||
| render | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render. | ||||||||||||
| ||||||||||||||
| ...props | <button> attributes | — | Every other attribute goes to the <button>, with a ref. | |||||||||||
CodeBlockTabsPanel
<div>| Prop | Type | Default | Description | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| class | string | — | ||||||||
| gap | "default""none" | — | The space between the list and the panel: default (12px) or none, for a panel that sits flush under a list in a head with its own edge (the JSX Preview stage). | |||||||
From Base UITabs.PanelBase UI docs | ||||||||||
| value | any | — | The value of the TabPanel. It will be shown when the Tab with the corresponding value is active. | |||||||
| keep | boolean | false | Whether to keep the HTML element in the DOM while the panel is hidden. | |||||||
| render | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render. | ||||||||
| ||||||||||
| ...props | <div> attributes | — | Every other attribute goes to the <div>, with a ref. | |||||||
CodeBlockInstall
<div>| Prop | Type | Default | Description |
|---|---|---|---|
| wrap | boolean | — | Wrap long lines (controlled). The Wrap toggle sets it. |
| default | boolean | — | Wrap long lines at first (uncontrolled). Default false: code scrolls sideways. |
| on | — | ||
| streaming | boolean | — | The code still arrives: an AI answer or a tool writes it now. The content shows plain text with fresh ink on the newest characters, Copy waits, and CodeBlockStatus says "Writing" with the line count. When it turns false, the syntax colors fade in once and the status says "Wrote N lines". Default false. |
| interrupted | "cut-off""stopped" | — | The stream ended before the code was whole: stopped (a person stopped it) or cut-off (the reply ended inside the block, a destructive edge). A note under the code says so. |
| palette | "color""ink""theme" | — | |
| variant | "framed""plain" | — | |
| command | string | — | One npm command: npm install @tanstack/highlight, npx shadcn add @gelatin-ui/code-block. |
| managers | PACKAGE_MANAGERS | The tabs, in order. Default npm, pnpm, yarn, bun. | |
| sync | string | "package-manager" | The shared choice (see CodeBlockTabs). Default "package-manager". |
| prompt | string | "$" | The prompt before the command. Default $. |
| label | string | "Package manager" | The name of the tab list. Default "Package manager". |
| marks | — | A mark before the name of each tab, in place of the built-in one (the npm, pnpm, Yarn, or Bun logo at 14px). The name always shows with it. | |
| mark | "color""mono" | "color" | The built-in marks: color (default, the brand colors) or mono (the tab text color). |
| labels | Partial<{ copy: string; }> | — | The words (CODE_BLOCK_INSTALL_LABELS). Keep the object stable. |
| on | — | Called after Copy wrote the command to the clipboard, with the text it copied: the command of the open tab (pnpm dlx shadcn add …). A failed copy does not call it. The root's own onCopy stays the DOM clipboard event. | |
| ...props | <div> attributes | — | Every other attribute goes to the <div>, with a ref. |
| Tab | Moves focus to the code region when it scrolls, then to Copy and Wrap. |
|---|---|
| Left ArroworRight Arrow | Scrolls the focused code sideways. |
Built with
Installs with Code Block
- Components
- Code,Copy Button,Direction,Rolling Number,Scroll Area,Spoiler,Tabs,Toggle



