Components
Code Block
Code with a copy affordance and an optional header. Used in these docs for install commands and source examples; it is not a syntax highlighter.
Usage
Short source or command snippets where the exact string matters.
Do and don't
- Do. Set a language label and keep lines short enough to read on a phone.
- Don't. Use it for prose or paste long transcripts into it.
Composition
CodeBlock takes the plain code string as its source of truth. Pass children only when a highlighter supplies its own markup; the copy button still copies the plain string.
Props
code; required plain text, also what the copy button writes.language,title; header label.hideHeaderfloats the copy button over the block instead.lineNumbers,wrap,maxHeight,size,onCopy.
Behavior and states
The copy button reports success in place, then settles back to its idle label. Long lines scroll sideways unless wrap is set; a maxHeight makes taller blocks scroll inside the body. Line numbers apply to plain code only.
Accessibility
The copy control has an accessible name. Keep the language or file label visible when the code is not self-evident, and do not rely on color alone to show copy success. This component renders preformatted text; it does not announce or describe the code to a screen reader.
Responsive
The block scrolls horizontally on narrow screens. Prefer short lines in examples so a phone does not require sideways scrolling to read the snippet.
Related
Tooltip provides the copy hint in other controls, Scroll Area documents the overflow pattern, and Motion & Transitions covers the short state change.