Components / Text

CodeBlock nativelite

Source code in a mono block with built-in syntax colouring, optional line numbers and a copy button.

Children
none
Loading the renderer…
CodeBlock rendered by the React renderer on Web
Web React
CodeBlock rendered by the SwiftUI renderer on iOS
iOS SwiftUI
CodeBlock rendered by the Compose renderer on Android
Android Compose
CodeBlock rendered by the gpui renderer on Desktop
Desktop gpui

View exponential-ui-code-block, painted by each native renderer.

wrap
PropTypeDefaultDescription
coderequiredbindstring–The source text.
languageplain | json | js | ts | tsx | rust | swift | kotlin | python | bash | html | css | sql | yaml | markdown"plain"The syntax colouring.
titlestring–A header line (a file name).
lineNumbersbooleanfalseShows a line-number gutter.
wrapbooleanfalseWraps long lines instead of scrolling sideways.
copyablebooleantrueShows the copy-to-clipboard button.
highlight[number]–1-based line numbers to emphasise.
maxLinesnumber–Lines shown before the block scrolls.

No events, no slots. Children: none.

Role
region
Semantics
region (code), copy = button
KeysAction
Tab reaches the copy button; EnterSpacecopy and announce copied
Recipe parts
CodeBlock/rootCodeBlock/headerCodeBlock/titleCodeBlock/copyCodeBlock/gutterCodeBlock/lineCodeBlock/lineNumberCodeBlock/tokenCodeBlock/bodyCodeBlock/code
Keyed by
lineNumberswrapkind:hover:pressed:focus:disabled:checked:open:selected:invalid:dragover

Themes · Write a theme