Code Block
Highlighted code with line numbers, marked lines, a copy button and a filename bar — always dark.
Loading documentation…
CodeBlock is always dark, in both colour modes. A code block is a
quotation from a terminal, and a terminal is dark — a light one reads as
another piece of UI rather than as output, and it doubles the number of token
palettes anyone has to keep tuned.
The highlighting is monochrome: one grey ramp, italics for comments, a
heavier weight for keywords. Syntax colour is decoration that competes with the
parts of an interface where colour means something. The tokens are --code-*
custom properties, so a coloured palette is a handful of variables rather than
a fork.
children is a string. Indentation common to every line is stripped, so a
template literal inside your component tree does not arrive with the component
tree's indentation.
ts, tsx, js, jsx, json, sh, css, html, yaml and sql are
understood; anything else renders plain. Setting language also labels the
block.
The highlighter is one regular expression per language — no grammars. It
covers the snippets that actually appear in an interface for about a kilobyte.
If you already ship Shiki or Prism, pass their markup as children and the
block renders it untouched.
highlight takes 1-based line numbers — the ones the surrounding prose is
about. Pair it with lineNumbers so the reader can follow a reference in the
text.
maxHeight caps the block and scrolls past it; wrap wraps long lines instead
of scrolling sideways, which is usually right for log output and never right
for code.
The source. Indentation common to every line is stripped.
Turns highlighting on and labels the block. ts, tsx, js, jsx,
json, sh, css, html, yaml and sql are understood; anything else
renders plain.
A filename or command, shown in the bar above.
A glyph in that bar.
It defaults to false.
1-based lines to mark.
The copy control in the bar. It defaults to true.
Caps the height and scrolls past it, for example "20rem".
Wraps long lines instead of scrolling sideways. It defaults to false.
Hides the language tag on the right of the bar.
Merged into the root.