CodeBlock
Molecule
Syntax-highlighted code display with clipboard copy, horizontal scrolling, line emphasis, diff rendering, collapsible folding, and tabbed alternatives.
Playground
Every control sets a real prop of CodeBlockProps. The JSX below updates as you go.
Web
iOS
Android
JSX · CodeBlockProps
Variants
13 examples from src/molecules/code-block/code-block.md, each rendered live from its own JSX.
Anatomy
1
Frame
2
Filename
3
Code
4
Copy button
5
Line numbers
Dimmed parts appear only in some states or variants.
Props
31 props on CodeBlockProps, grouped as they are declared in source. Required props are marked *.
Accessibility and keyboard
Keyboard
Not focusable. It has no interaction of its own and takes the semantics of what it wraps.
Semantics
Roles
button
tab
tablist
States
expanded
selected
ARIA on web
aria-expanded
aria-selected
From the docs
When a line is wider than the block, Tab reaches the scrollable code and the platform's arrow keys scroll it; while it has keyboard focus, the block's card draws the theme's focus ring. Short content, wrap, and inline do not add a scrolling tab stop. Native scrolling continues to use the native ScrollView.
Platform skins
The playground's props on each platform: same tree, native shapes, type and touch sizes.
Usage
The variant axis picks the surface (terminal > numbered > inline > plain, first match wins); the density axis is compact (the tightened ramp), playground (the hand-off component page's JSX card: the block at the card corner, its header a 40 px bar on the card fill, 16 in and 8 out, its Copy a 28 px hairline button, and the code 16 above and below and 18 in at the default ramp), snippet (the page's own snippet, the Usage section's block: the code-card corner with the code 16 above and below and 18 in at the default ramp) or guide (a card's snippet, the block in a guidance card: a 10 px corner with the code 12 above and below and 14 in at 12 / 1.65), in that order of precedence; copy, wrap, diff, collapsible, attached, headerless, and unbadged stack orthogonally. language drives the in-kit highlighter (ts/tsx/js/jsx, json, bash, css, html, python; anything else renders monochrome) and, with no filename, labels a header bar above the code; with a filename it is a trailing badge beside the copy chip instead, which unbadged drops for a filename that already names the language (the hand-off's playground bar, "JSX · ButtonProps" and a Copy button only). headerless keeps the highlighting and drops the whole bar (a tabs strip and the terminal chrome stay), so copy floats over the code's corner. Long lines scroll horizontally instead of truncating, and every run of code, highlighted tokens included, is set in the theme's mono face.
The block is the v4 hand-off's code card on every platform: the sunken well on a hairline at a 14 px corner, a 36 px header of 12 px mono labels, 13 / 1.7 code, line numbers in the subtle ink, and the hand-off's code inks (each light-scheme ink held to 4.5:1 on the well). A ts or js snippet takes the hand-off's CodeBlock renderer: keywords, strings, numbers and tag names in the accent, mint, amber and cyan. A tsx or jsx snippet takes the hand-off's component-page highlighter, which paints four things and nothing else: a Capitalised tag name in the accent (the brackets and slash neutral), an attribute name before its = in cyan, a string literal in mint and a comment in the subtle ink; a bare boolean attribute, a keyword, a number and the children text stay in the code ink, so <Button>Save changes</Button> reads as one label after one accent name. The terminal is a fixed dark window in every scheme.
Tokens
Read from the playground render. Values follow the scheme and the ion hue.
--bg2
--cyan
--fd
--fm
--ft
--ion-tx
--ln
--ln2
--sf
--tx2
--tx3