Code Block Style
Visual style configuration for SyntaxHighlightedCode.
Use Default for a standard code block with rounded corners and comfortable padding. Use Compact for tighter padding in space-constrained layouts.
Default values for all properties are available via SyntaxHighlightedCodeDefaults.
Using presets
SyntaxHighlightedCode(code = snippet, language = "json", style = CodeBlockStyle.Default)
SyntaxHighlightedCode(code = snippet, language = "json", style = CodeBlockStyle.Compact)Custom style
val myStyle = CodeBlockStyle(
shape = RoundedCornerShape(4.dp),
padding = PaddingValues(8.dp),
headerPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp),
lineNumberWidth = 40.dp,
copyButtonSize = 24.dp,
)
SyntaxHighlightedCode(code = snippet, language = "bash", style = myStyle)Custom typography
Override textStyle to change the font, size, or line height of the code text:
SyntaxHighlightedCode(
code = snippet,
language = "kotlin",
style = CodeBlockStyle(
textStyle = SyntaxHighlightedCodeDefaults.codeTextStyle.copy(fontSize = 15.sp),
),
)The lineNumberColor defaults to Color.Unspecified, which derives the color from the active theme at 40% opacity. Override it to use a fixed color.
For custom styles constructed inline in a composable, wrap them in remember to avoid unnecessary recompositions:
val myStyle = remember { CodeBlockStyle(padding = PaddingValues(8.dp)) }Constructors
Properties
Size (width and height) of the copy-to-clipboard button icon.
Background color used when the active theme's CSS has no .hljs { background: ... } rule.
Text color used when the active theme's CSS has no .hljs { color: ... } rule.
Padding for the header row (language label + copy button).
Color of the line number gutter text.
Width reserved for the line number gutter.
Inner padding between the container edge and the code content area.