Code

Monospace code, either inline in a tray chip or as a multi-line block. Syntax highlighting is left to you.

StableSource

Import the stylesheet once with @merid/react/styles.css.

Import

tsx
import { Code } from "@merid/react";

Examples

Block

variant="block" renders <pre><code> for multi-line snippets. Whitespace is preserved and long lines scroll horizontally.

npm i @merid/react
import "@merid/react/styles.css";

API reference

Code forwards its ref to the <code> (inline) or <pre> (block) and passes other HTML attributes to that element.

PropTypeDefaultDescription
variant"inline" | "block""inline"inline renders <code> in a tray chip; block renders <pre><code>.

Styling

HookValues
.mrd-codeRoot: <code> or <pre>
data-variantinline · block

To add highlighting, pass pre-highlighted children or style the inner code element from your highlighter's output.

Accessibility

  • Code is read as plain text. A block that overflows horizontally should be reachable by keyboard; add tabIndex={0} and an aria-label to the block when snippets can be wide.

Guidelines

Do

Use inline Code for identifiers, file names and short commands inside a sentence.

Avoid

Wrap whole paragraphs or UI labels in Code for a “technical” look.

  • Kbd — keyboard shortcuts.
  • Text — the surrounding copy.