Skip to content

Code

Inline or block code formatting for identifiers, expressions, and short snippets — semantic <code> with <pre> wrapping when needed.

  • stable
  • since v0.1.0
  • 3.7 kB
  • typography
  • code

Renders a native <code> (inline) or <pre><code> (block); assistive tech announces the content as code without extra ARIA wiring.

Preview
Open
tsx

Two variants: inline (default) renders a bare <code> and slots into prose; block wraps <code> inside <pre> so multi-line snippets retain whitespace.

Preview
Open
tsx

Pick sm for dense inline usage or md (default) for body-aligned snippets.

Preview
Open
tsx

colorScheme tints the surface and border — neutral (default), accent, success, and danger cover the common roles (e.g. red for deprecated identifiers, green for new APIs).

Preview
Open
tsx

Code slots cleanly inside a Text paragraph for identifiers and short expressions.

Preview
Open
tsx
PropTypeDefaultDescription
size
"sm"|"md"
"md"
Font-size step for the monospace glyphs.
variant
"inline"|"block"
"inline"
`"inline"` renders a bare `<code>`; `"block"` wraps in `<pre><code>` so multi-line snippets preserve whitespace and line breaks.
colorScheme
"neutral"|"accent"|"success"|"danger"
"neutral"
Background / foreground palette token for the chip.
className
string
—
Additional class names appended after Cynosure's base classes.
style
CSSProperties
—
Inline style overrides merged last.
children
ReactNode
—
Code text content.
padding
—
Padding on all four sides. Token from the spacing scale.
paddingX
—
Horizontal padding (left + right). Overrides `padding` on the X axis.
paddingY
—
Vertical padding (top + bottom). Overrides `padding` on the Y axis.
paddingTop
—
Padding on the top edge. Beats `padding` / `paddingY`.
paddingRight
—
Padding on the right (inline-end in RTL) edge.
paddingBottom
—
Padding on the bottom edge.
paddingLeft
—
Padding on the left (inline-start in RTL) edge.
margin
—
Margin on all four sides. Accepts the spacing scale or `"auto"`.
marginX
—
Horizontal margin (left + right). Use `"auto"` to centre.
marginY
—
Vertical margin (top + bottom).
marginTop
—
Margin on the top edge.
marginRight
—
Margin on the right edge.
marginBottom
—
Margin on the bottom edge.
marginLeft
—
Margin on the left edge.
width
—
Element width. Accepts a `SpaceToken`, `LengthValue`, or named alias.
height
—
Element height. Accepts a `SpaceToken`, `LengthValue`, or named alias.
minWidth
—
Minimum width — useful for preventing flex children from collapsing.
maxWidth
—
Maximum width — `"prose"` caps to a comfortable reading measure.
minHeight
—
Minimum height.
maxHeight
—
Maximum height.
background
—
Background colour. Use a `ColorToken` like `"bg.surface"` for theme awareness.
color
—
Text colour. Inherits unless set.
borderColor
—
Border colour. Pair with `borderWidth` to make the border visible.
borderWidth
—
Border thickness in scale steps.
borderStyle
—
Border line style.
borderRadius
—
Corner rounding token.
boxShadow
—
Drop-shadow token from the elevation scale.
opacity
Responsive<number | `${number}`>
—
Opacity 0–1. Use sparingly — prefer surface tokens over translucency.
overflow
—
How content that exceeds the box is handled.
overflowX
—
Horizontal-axis overflow control. Overrides `overflow` for the X axis.
overflowY
—
Vertical-axis overflow control.
display
—
CSS `display` value. `"contents"` removes the element's box from layout.
position
—
CSS `position`. Pair with `top`/`right`/`bottom`/`left` for placement.
top
—
Top inset (when positioned). Accepts a `SpaceToken`, `"auto"`, `"0"`, or `LengthValue`.
right
—
Right inset (when positioned).
bottom
—
Bottom inset (when positioned).
left
—
Left inset (when positioned).
zIndex
—
Stacking-context layer token (`"modal"`, `"tooltip"`, …).
gridColumn
Responsive<string>
—
Grid-column shorthand (e.g. `"1 / 3"`, `"span 2"`).
gridRow
Responsive<string>
—
Grid-row shorthand.
gridArea
Responsive<string>
—
Named grid area.
flex
Responsive<"1" | "none" | "auto" | "initial" | (string & {})>
—
Shorthand: `1 | auto | none | initial | <css>`. Resolves to `flex` on the child.
flexGrow
Responsive<number | `${number}`>
—
Grow factor inside a flex container.
flexShrink
Responsive<number | `${number}`>
—
Shrink factor inside a flex container.
flexBasis
Responsive<"content" | SizeValue>
—
Initial main-axis size before grow/shrink.
alignSelf
—
Override `align-items` for a single child.
justifySelf
—
Override `justify-items` for a single child (grid).
order
Responsive<number | `${number}`>
—
Flex/grid child reorder index.
asChild
boolean
—
When `true`, renders the primitive's single React child via `Slot`, forwarding className/style/ref/event handlers onto it.
  • Renders the native <code> element so screen readers identify the content as code.
  • variant="block" wraps <code> in <pre> so newlines and indentation are preserved for both visual and assistive consumers.
  • Avoid color-only signals — pair colorScheme="danger" with descriptive surrounding copy.
  • For multi-line code with syntax highlighting reach for the dedicated CodeBlock component once available; Code variant="block" is intentionally style-only.
  • Inline Code reads best wrapped inside a Text or paragraph element.
  • Keep inline snippets short — break longer code into a variant="block" snippet or a full code block.
  • Combine with Kbd to differentiate keyboard input from code output in tutorials.
  • Use colorScheme="success" or "danger" sparingly to flag newly added or deprecated APIs in changelogs.