---
title: "Code block"
subtitle: "<CodeBlock> controls a code block's title, highlighting, focus, line numbers and collapsing with props."
---

Most of the time a plain fenced code block is all you need; for meta syntax (titles, line highlighting, focus, max lines…) see [Code blocks](../writing/code-blocks.mdx).

Uses props instead of fence meta — handy when there are many options or you need `links`:

````mdx
<CodeBlock title="client.ts" highlight="2" maxLines={0} links={{ "createClient": "/api-reference", "/get\\w+/": "/api-reference" }}>
```ts
import { createClient } from "@acme/sdk";
const client = createClient({ apiKey: process.env.ACME_KEY });
const me = await client.getMe();
```
</CodeBlock>
````

<CodeBlock title="client.ts" highlight="2" maxLines={0} links={{ "createClient": "/api-reference", "/get\\w+/": "/api-reference" }}>
```ts
import { createClient } from "@acme/sdk";
const client = createClient({ apiKey: process.env.ACME_KEY });
const me = await client.getMe();
```
</CodeBlock>

<ParamField path="title" type="string">Title (`filename` also works).</ParamField>
<ParamField path="language" type="string">Language (`lang` also works); defaults to the fence's language.</ParamField>
<ParamField path="highlight" type="string">Lines to highlight, e.g. `"2-4, 6"`.</ParamField>
<ParamField path="focus" type="string">Lines to focus; the rest are dimmed.</ParamField>
<ParamField path="startLine" type="number">Starting line number.</ParamField>
<ParamField path="maxLines" type="number" default="20">Maximum visible lines; `0` means no limit.</ParamField>
<ParamField path="wordWrap" type="boolean">Wrap long lines.</ParamField>
<ParamField path="showLineNumbers" type="boolean">Show / hide line numbers (`lineNumbers` also works).</ParamField>
<ParamField path="for" type="string">Custom sync group.</ParamField>
<ParamField path="links" type="object">Map text in the code (or a `/regex/`) to links.</ParamField>
<ParamField path="collapsible" type="boolean">When the block exceeds the max lines, collapse it behind "Show more" instead of scrolling.</ParamField>
