CodeSnippet

Displays code (inline, single-line, or multi-line) with an optional copy button, lightweight built-in syntax highlighting for bash/css/js/ts, and an optional terminal-window look

Category: display · WCAG 2.2-AA · display, code, snippet, copy, pre, syntax-highlighting, terminal, bash, css, js, ts

Variants

States

Props

PropTypeDefaultDescription
codestringThe code to display (and copy).
variant'inline' | 'single' | 'multi'singleinline = a <code> span; single = one-line <pre>; multi = multi-line <pre>.
language'bash' | 'css' | 'js' | 'ts'Enables built-in syntax highlighting for the block variants; inline is never highlighted.
terminalbooleanfalseRenders terminal-window chrome (title bar with dots). Block variants only.
titlestringOptional label shown in the terminal title bar.
showLineNumbersbooleanShow line numbers (multi only; ignored when language is set).
showCopyButtonbooleanShow the copy-to-clipboard button. Defaults true for single/multi, false for inline.
labels{ copy?: string; copied?: string }Overrides for the component’s user-visible strings (i18n).
classNamestringAdditional CSS class names merged onto the root element.

Design tokens

When to use

When not to use

How to build an accessible CodeSnippet in React →

Examples

Install command

<CodeSnippet code="npx cascivo add button" language="bash" />

Inline

<p>Run <CodeSnippet variant="inline" code="pnpm build" /> first.</p>

Terminal block

Multi-line shell transcript with terminal-window chrome.

<CodeSnippet
  variant="multi"
  language="bash"
  terminal
  title="deploy.sh"
  code={'pnpm build\npnpm deploy'}
/>

Related components

← Back to docs