Codecomponent

Code({ children, plain, ...props }: CodeProps): ReactElement
ParamType
propsCodeProps
Props for Code — colour and typography variants, optional children, plus a plain toggle. required
    .plainboolean
Return
ReactElement
Rendered <code> element.

Inline code span — renders a <code> element.

  • Pass plain to drop the default background and padding.

An inline code span — renders a <code> element with monospace type and a subtle tinted background. Code.tsx exports four siblings that share the same monospace styling but carry different HTML semantics:

ComponentHTML elementUse for
Code<code>Inline code fragments
Keyboard<kbd>Keyboard input, e.g. Ctrl+S
Sample<samp>Program output
Variable<var>Variable names in documentation

Things to know:

  • Pick the sibling whose semantics match — they all look the same but mean different things to assistive tech and search.
  • Pass plain to drop the default background and inline padding (useful when the code already sits inside a tinted container).
  • Painted from the tint ladder: the background is --tint-90 and the text --tint-00, so it re-tints with its surrounding scope.
  • Inside <Prose> raw <code> / <kbd> / <samp> / <var> pick up the same styling, and code inside a <pre> drops the inline box automatically.

Usage

Inline code and keyboard input

tsx
import { Code, Keyboard, Sample } from "shelving/ui";

<p>Run <Code>npm install</Code>, then press <Keyboard>Enter</Keyboard>.</p>
<p>It prints <Sample>Done.</Sample></p>

Plain (no background)

tsx
import { Code } from "shelving/ui";

<Code plain>const x = 1;</Code>

Styling

Code paints from the tint ladder; the box (background / color) reads ladder steps directly, while type, padding, and radius have per-property hooks.

VariableStylesDefault
--code-fontFont familyvar(--font-code)
--code-weightFont weightvar(--weight-code)
--code-sizeFont sizevar(--size-smaller)
--code-leadingLine heightvar(--leading)
--code-paddingInline padding (non-plain)var(--space-xxsmall)
--code-radiusCorner radius (non-plain)var(--radius-xxsmall)

Global tokens it reads: --font-code, --weight-code, --size-smaller, --leading, --space-xxsmall, --radius-xxsmall, and the tint-ladder steps --tint-00 / --tint-90 for the box fill and text.

Examples

<Code>npm install</Code>