Code

Inline code in text, and a block with a title, a copy button and optional tabs.

Edit page

Inline

A code element in text gets a soft frame and the mono font.

Block

Terminal
yarn build
Card.jsx
<a className='card' href='/docs'>…</a>
Example.jsx
import { Code } from './components/Code'

<Code code='yarn build' />
<Code code={source} label='Card.jsx' icon='file' />

The block follows the mode: light on a light page, dark on a dark one. Copy puts the text on the clipboard and says so for two seconds.

With tabs

Terminal
yarn add react-icons
Example.jsx
<Code variants={[
  { label: 'yarn', code: 'yarn add react-icons' },
  { label: 'npm', code: 'npm install react-icons' },
  { label: 'pnpm', code: 'pnpm add react-icons' },
]} />

Variables

VariableDefaultWhat it sets
$code-backgroundvar(--surface)background of the block
$code-barvar(--page)background of the title bar
$code-textvar(--text)text colour
$code-mutedvar(--muted)title and buttons
$code-linevar(--line)border and active tab
$code-radius12pxcorner radius