CodeBlock

Fiddle
Files and multi-line code as Fern Docs shows them: a title bar, highlighting, line numbers, copy.
fern/docs.yml
instances:  - url: acme.docs.buildwithfern.com

Usage

The import, then a use to start from. Both copy as they are.

Import
import { CodeBlock } from "@/components/ui/CodeBlock";
Example
<CodeBlock title="fern/generators.yml" language="yaml" code={generatorsYml} /> <CodeBlock title="Agent brief" code={brief} maxLines={3} wordWrap copySuccessMessage="Copied the brief" />

When to use

Use it for

  • A file or multi-line code: a config, a script, a SKILL.md, a brief to paste. The header names it, with Copy on the right.
  • language highlights it in Fern Docs' Shiki themes, so code reads the same here as in the docs. text (the default) stays uncolored.
  • Long code shows 20 lines (maxLines), then opens in place with “Show all”. A brief people mostly copy needs three.
  • wordWrap for prose such as briefs and Markdown; code scrolls sideways instead, so its shape holds.
  • actions puts more header buttons before Copy, such as a download.

Avoid

  • A one-line command inside a form or a dialog: use CodeSnippet.
  • A single value someone copies, such as a key or an ID: use CopyableText.
  • A hand-made <pre>: it misses the highlighting, the line numbers and Copy.

Accessibility

Checks

  • The scrolling area takes focus, so the keyboard can scroll it, and it's named after the block's title.
  • Copy is named after the file it copies, and confirms in a toast.

API

Read from each component's stories, the same source as COMPONENTS.md, and kept in step by check:design-system.

CodeBlock

Its stories don't declare argTypes, so no props are listed. The variants show its states.
VariantsDefaultUntitledPlainTextLongFileOneLineWithActions

Keep going

Typography
Beautiful display and mono fonts that scale for all sizes.