2.0 alpha
These docs describe 2.0. Install it with @once-ui-system/core@alpha.
On 1.8.x? Read the 1.x docs
TrademarkTrademarkDocs
Ctrl k
Search 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. The CodeBlock can display multiple code examples with tabs for easy navigation. Use the compact prop for a more condensed display. Use the lineNumbers prop to display line numbers for better code readability and reference. 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"). 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” ] The CodeBlock component supports additional features like fullscreen mode and style customization. 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. Use the background prop to change the CodeBlock's outer background. Combine with alpha tokens for transparency effects. Pass any color via style.backgroundColor — the button wrappers automatically pick it up.
Prop
Type
Default
codes
CodeInstance[][]
preview
ReactNode
copyButton
booleantrue
styleButton
booleanfalse
reloadButton
booleanfalse
fullscreenButton
booleanfalse
compact
booleanfalse
isCollapsible
booleanfalse
lineNumbers
booleanfalse
codeHeight
number
maxLines
number
fillHeight
booleanfalse
previewPadding
SpacingToken'l'
background
Colors | 'surface' | 'overlay' | 'page' | 'transparent''surface'
onInstanceChange
(index: number) => void
hideCode
Render only the preview, without the code panel.
booleanfalse
…and every FlexProps propinherited
Prop
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
TrademarkTrademark
Built with curiosity by Lorant One and the Design Engineers Club