Code
Inline and block code display with monospace styling.
Import
import { Code } from '@matix/components/code';Usage
Install the package with bun add @matix/components
Use the variant prop to change the style.
Sizes
Code and Code.Block accept a size prop with three values: sm, md (default), and lg. Inline sizes are relative (em) so they scale with surrounding text; block sizes use the type scale.
<p>
Small: <Code size="sm">npm install</Code>
</p>
<p>
Medium: <Code size="md">npm install</Code>
</p>
<p>
Large: <Code size="lg">npm install</Code>
</p>Code Block
Use Code.Block for multi-line code. It wraps the content in a <pre> element and accepts the same size prop.
<Code.Block size="sm">
{`function greet(name: string) {
return \`Hello, \${name}!\`;
}`}
</Code.Block>Custom Styles
import * as stylex from '@stylexjs/stylex';
import { colors } from '@matix/tokens';
const custom = stylex.create({
inline: { backgroundColor: colors.primary, color: '#fff', padding: '2px 6px' },
block: { borderRadius: '8px' },
});
<p>
The <Code sx={custom.inline}>status</Code> field is required.
</p>
<Code.Block sx={custom.block}>
{`const config = {
strict: true,
target: "es2022",
};`}
</Code.Block>;API Reference
Code
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Inline code content |
size | 'sm' | 'md' | 'lg' | 'md' | Font size — relative to surrounding text |
sx | StyleXStyles | — | StyleX style override |
Code.Block
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Block code content (rendered inside <pre><code>) |
size | 'sm' | 'md' | 'lg' | 'md' | Font size from the type scale |
sx | StyleXStyles | — | StyleX style override for the <pre> wrapper |
Accessibility
Coderenders an inline<code>element. Screen readers announce it as code when they encounter it in prose.Code.Blockrenders a<pre>wrapping a<code>element, preserving whitespace and formatting.- Neither component adds ARIA roles — the semantic HTML elements provide sufficient meaning.
- Both set
dir="ltr", so code reads left to right on an RTL page. Passdirto change it.
This is an RSC-safe component — it ships no JavaScript to the browser.