Code Block
Code Block presents structured multi-line source with native scrolling, explicit language metadata, and truthful Atom-backed copy behavior.
Built from the published package
Know when Code Block is the right part
Use it when
Use it for examples, configuration, commands, generated markup, and other preserved multi-line technical content that may overflow its container.
Choose another path when
Do not use it for inline literals, Markdown rendering, editable source, terminal output, executable sandboxes, or accidental layout overflow.
Installation and imports
The complete stylesheet above is the recommended default. For a measured route-aware build, replace it with the shared foundation and this component's stylesheet:
Add the modular stylesheet for every other Brick component the route renders.
Do not combine modular styles with styles.css or tokens.css.
CodeBlock and every direct part are also available from the package root.
Quick start
Visual recipes and states
subtle supplies a quiet filled surface, bordered a transparent bordered
surface, and plain removes surrounding paint. Size changes only component
rhythm and technical typography. Atom supplies idle, copying, copied,
and error copy states; the trigger is disabled when the clipboard contract
is disabled. Scroll and wrap differ only in long-line handling.
Examples
Copy feedback
Wrapped content
API
Start with the public parts and root options below. Components with multiple parts separate each area into its own named subsection.
| Part or prop | Values | Default |
|---|---|---|
Root.value | copied plain-text source | required |
variant | subtle, bordered, plain | subtle |
size | sm, md | md |
Root.language | explicit string | none |
wrap | scroll, wrap | scroll |
focusable | boolean | true |
| Clipboard behavior | disabled, timeout, writeValue, onStatusChange | Atom defaults |
Public parts are Root, Header, Title, Language, Actions, Content,
CopyTrigger, CopyIndicator, and CopyStatus. Direct exports are
CodeBlockRoot, CodeBlockHeader, CodeBlockTitle, CodeBlockLanguage,
CodeBlockActions, CodeBlockContent, CodeBlockCopyTrigger,
CodeBlockCopyIndicator, and CodeBlockCopyStatus. Their prop types are
CodeBlockRootProps, CodeBlockHeaderProps, CodeBlockTitleProps,
CodeBlockLanguageProps, CodeBlockActionsProps, CodeBlockContentProps,
CodeBlockCopyTriggerProps, CodeBlockCopyIndicatorProps, and
CodeBlockCopyStatusProps. Type exports also include CodeBlockVariant,
CodeBlockSize, and CodeBlockWrap.
Accessibility
Give focusable Content a specific aria-label or aria-labelledby; it is the
only scroll-region keyboard stop. CopyTrigger retains focus. Author concise
CopyStatus text for copying, success, and failure so Atom can announce truthful
results. Do not add role="application".
Responsive behavior
The root fills available inline space but owns no external dimensions or
breakpoints. scroll preserves long lines in the horizontal viewport; wrap
reflows them. Code defaults to LTR inside an RTL page while Header follows page
direction.
Styling and tokens
Customization
Language highlighting is consumer-owned. Pass trusted highlighted React nodes
to Content while keeping Root value as the matching plain text. Unsafe HTML
is not accepted and Brick does not bundle a tokenizer.
Tokens and CSS hooks
Hooks include .brick-code-block and its part classes, Atom data-state, plus
data-slot, data-language, data-size, data-variant, and data-wrap.
Public variables are --brick-code-block-background,
--brick-code-block-foreground, --brick-code-block-border-color,
--brick-code-block-border-width, --brick-code-block-radius,
--brick-code-block-header-padding, --brick-code-block-content-padding,
--brick-code-block-gap, --brick-code-block-font-family,
--brick-code-block-font-size, --brick-code-block-font-weight,
--brick-code-block-line-height, --brick-code-block-letter-spacing,
--brick-code-block-selection-background, and
--brick-code-block-selection-foreground.
Advanced reference
Open these details only when you need to inspect DOM ownership, native forwarding, or lower-level composition.