Skip to content
TrademarkTrademark
Docs
Modules

CodeBlock

Updated: July 27, 2026
View on GitHub

The CodeBlock component provides a way to display code snippets with syntax highlighting, interactive tabs for multiple code examples, and optional live previews. It supports various customization options including copy buttons, fullscreen mode, and line numbers.

Preview

Multiple code

The CodeBlock can display multiple code examples with tabs for easy navigation.

Compact mode

Use the compact prop for a more condensed display.

Line numbers

Use the lineNumbers prop to display line numbers for better code readability and reference.

Highlight

Use the highlight prop to highlight specific lines of code. The value should be a string with line numbers or ranges (e.g., "1,3-5").

Code Diff

Display Git-style diffs by setting the language to "diff". Numbering can be used from coordinates, also specified manually by setting the startLineNumber parameter. Numbering prioritizes as follows: coordinates > startLineNumber > 0 (fallback)

You can enable syntax highlighting by specifying a similar array as the language parameter: [ “diff”, “typescript” ]

Extras

The CodeBlock component supports additional features like fullscreen mode and style customization.

Collapsible

Use maxLines to limit code height and show a "View code" overlay for expandable code blocks. isCollapsible must be enabled for the overlay to appear.

Custom background

Use the background prop to change the CodeBlock's outer background. Combine with alpha tokens for transparency effects.

Custom colors

Pass any color via style.backgroundColor — the button wrappers automatically pick it up.

API reference

Type
Default
codeHeight
number—
fillHeight
boolean—
previewPadding
SpacingTokenl
codes
CodeInstance[][]
preview
ReactNode—
copyButton
booleantrue
styleButton
booleanfalse
reloadButton
booleanfalse
fullscreenButton
booleanfalse
compact
booleanfalse
className
string—
style
React.CSSProperties—
background
React.ComponentProps<typeof Flex>["background"]surface
onInstanceChange
(index: number) => void—
lineNumbers
booleanfalse
highlight
string—
maxLines
number5
isCollapsible
booleanfalse
hideCode
Render only the preview, without the code panel.
booleanfalse
…and every FlexProps propinherited—
Type
Default
code
string{ content: string; error: string | null }
—
language
Language[ "diff" , Language ]
—
label
string—
highlight
string—
prefixIcon
string—
startLineNumber
number0
Edit this page on GitHub