Code block
Shows code and commands exactly, ready to copy.
Examples
Set retries on agt_triage01.
Styles
quartz.yamlYAML blockdefault
command
Sizes
sm
defaultdefault
Inline
Set
retriesto 2.defaultdefault
Model
mdl_fast2025plain
Open
run_8f2a00kind
States
rest
focus-visible
secret hidden
secret shown
copied
copy failed
highlighted
TypeScript wrapped
Usage
When to use it
- Use
- A command a person will paste into a terminal.
- Use
- A file, config or excerpt they read and copy from.
- Use
- An identifier, path or value inside a sentence, with Code.
- Not for
- A secret on its own in a form. Use Input.
Rules
10 rules
- Never
- Put a CodeBlock in a Panel or beside Panels; it is a working surface, white with one grey edge and a rule under its header. Because a surface that scrolls, streams or is read closely needs the white frame's edge to show where it ends, and a white frame in a grey Panel is a box in a box.
- Must
- Show a command and its output in one variant="command" block with the prompt on commands only. Because a plain block copies the $ and the printed output, so a pasted command fails in the terminal.
- Never
- Type $ into a plain block; pass the command as command. Because a plain block copies every character, so the $ lands in the clipboard and the shell answers "command not found".
- Must
- Pass a key or token in a command as secret; copy still takes the real value. A masked key keeps its length: one dot per hidden character. Because without it the key shows in full to anyone looking at the screen or a screenshot of it.
- Should
- Mark the 1 to 3 lines the text talks about with highlight and set startLine for an excerpt. Because without startLine an excerpt numbers from 1, so the numbers no longer match the file.
- Should
- Name a file the person creates or edits with filename.
- Should
- Write example IDs with real prefixes: run_, agt_, key_, dpl_, mdl_. Because the tokenizer underlines those prefixes in their kind, and a bare "123" looks like no ID the API returns.
- Must
- Pass filename or language on a file block; the scroll body is named from them. Because with neither, the focusable region is named "Text", so a screen reader cannot tell one block from the next.
- Never
- Add syntax colors to code. Because hue in a block marks a resource ID by its kind, so a purple keyword reads as an agent reference.
- Should
- Set maxHeight to 480 or link the file for a block longer than 24 lines. Because the block grows to its content, so a long file pushes the rest of the page out of reach.
Accessibility
6 checks
- The block is a figure; the body is a focusable region named by filename, language or "Command".
- Arrows and Page Up or Down scroll the focused body.
- Copy confirms in place and announces "copied"; a refused clipboard announces how to copy by hand.
- Wrap and reveal are toggle buttons with aria-pressed.
- The prompt, line numbers and secret dots are aria-hidden and never selected or copied.
- The code always reads left to right (dir="ltr").
Edge cases
11 edge cases
- Long line
- Scrolls sideways with the gutter held; wrap breaks anywhere.
- One-character command
- Keeps the 32px box with copy at the end.
- Empty code
- Renders one empty line; do not render an empty block.
- 120px container
- The command scrolls in its body; copy stays visible.
- Right to left
- The chrome mirrors; the code stays left to right.
- Zoom 200%
- The line height grows with the font; nothing clips.
- Heredoc in a command block
- The body reads as output; pass command for those.
- Ten copies in a second
- Each restarts the 1.6s confirm; no flicker.
- Secret wider than the line
- The dots keep the key's length and the line scrolls; the dots never shrink in a command.
- Forced colors
- The frame edge draws in CanvasText, Code takes a border, highlights an outline.
- Reduced motion
- Nothing moves; the copy confirm is a cut.
API
15 props
codestringdefault''variant'block' | 'command'default'block'commandstring | string[]promptstringdefault'$'secret, defaultRevealedstring, booleandefault, falselanguage'ts' | 'tsx' | 'js' | 'json' | 'bash' | 'python' | 'yaml' | 'text'default'text'filename, headerstring, booleandefault, truelineNumbers, startLine, highlightboolean, number, number[] | stringdefaulttrue, 1defaultWrap, maxHeightboolean, numberdefaultfalserefs, detectRefs{text, kind, href?}[], booleandefault[], truesize'sm' | 'default'default'default'copyLabel, onCopystring, (text) => voiddefault'Copy code'Code kind, href, variantKind, string, 'default' | 'plain'kindKindMaskedKey prefix, tail, lengthstring, string, numberdefaultrequired
Tokens
18 tokens
--line-frame- oklch(var(--ink-c) / var(--line-frame-alpha))
--line-row- oklch(var(--ink-c) / 0.08)
--surface-card- oklch(var(--grey-c))
--code-text- var(--ink)
--type-code- 400 13px/20px var(--font-mono)
--code-string- oklch(var(--ink-c) / var(--code-string-alpha))
--code-comment- oklch(var(--ink-c) / var(--code-comment-alpha))
--weight-strong- 500
--code-prompt- oklch(var(--ink-c) / 0.40)
--accent-wash- var(--surface-selected)
--accent-line- var(--ink)
--accent-mark- var(--ink)
--type-label-sm- 400 12px/16px var(--font-sans)
--type-tag- var(--type-code-sm)
--text-3- oklch(var(--ink-c) / 0.66)
--radius-inner- 4px
--radius-frame- 10px
--features-id- "ss04"