Browse components
Code Block
Code display with a filename tab, line numbers, highlighted lines that sweep in, lightweight built-in token coloring and a copy button that springs into a check.
Installation
npx shadcn@latest add @glint-ui/code-blockFirst time using @glint-ui? Add the registry to components.json once, or install by URL: npx shadcn@latest add https://glint-ui-seven.vercel.app/r/code-block.json
Usage
import { CodeBlock } from "@/components/ui/code-block";
<CodeBlock
filename="counter.tsx"
language="tsx"
highlightLines="5-6"
code={source}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| filename | string | "counter.tsx" | Tab label in the header. |
| language | "tsx" | "ts" | "js" | "css" | "json" | "bash" | "python" | "tsx" | Token rules and header badge. |
| highlightLines | string | "5-6" | 1-based lines to highlight: "3", "2,5-7" or number[]. |
| showLineNumbers | boolean | true | Gutter with line numbers. |
| copyable | boolean | true | Copy-to-clipboard button. |
| code | ReactNode | — | The source text to display. |
| className | string | — | Extra classes for the root element. |