Skip to main content
CodivDocs

CodeBlock

Standalone code block wrapper as an alternative to markdown fences.

Usage

In most cases you should write code with plain markdown fences — they're shorter and the platform's code block features (syntax highlighting, copy button, language badge) work automatically.

```typescript
const x = 1;
```

Use <CodeBlock> only when you need an explicit JSX element with a title prop instead of relying on metastring parsing — for example, in computed/dynamic content or when wrapping inside another component that doesn't preserve fence metadata.

<CodeBlock title="server.ts" language="typescript">
{`const app = createServer();
app.listen(3000);`}
</CodeBlock>
const app = createServer();
app.listen(3000);

When to prefer fences

Markdown fences<CodeBlock>
SyntaxShort — ```tsVerbose — <CodeBlock language="ts">
Title```ts title="x.ts"title="x.ts" prop
MultilineNativeRequires template literal
Inside CodeGroupWorks as a fence childWorks the same way
Recommended for95% of casesEdge cases only

If you're writing prose-and-code documentation, use fences. If you're computing code dynamically (e.g. inside a custom React component) or composing inside something that needs explicit elements, use <CodeBlock>.

Props

PropTypeDescription
languagestringSyntax highlighter language identifier
titlestringOptional title shown in the language badge slot
childrenReactNodeCode content (typically a string template literal)

Last updated April 12, 2026