Skip to content

    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.

    Open
    Customize

    tsx
    ts
    js
    css
    json
    bash
    python

    Installation

    npx shadcn@latest add @glint-ui/code-block

    First time using @glint-ui? Add the registry to components.json once, or install by URL: npx shadcn@latest add https://glintui.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

    PropTypeDefaultDescription
    filenamestring"counter.tsx"Tab label in the header.
    language"tsx" | "ts" | "js" | "css" | "json" | "bash" | "python""tsx"Token rules and header badge.
    highlightLinesstring"5-6"1-based lines to highlight: "3", "2,5-7" or number[].
    showLineNumbersbooleantrueGutter with line numbers.
    copyablebooleantrueCopy-to-clipboard button.
    codeReactNode—The source text to display.
    classNamestring—Extra classes for the root element.