Code block

You can add code blocks with line numbers and a title using Markdown syntax like this:

Markdown syntax
1
2
3
```js showLineNumbers title="Code block title"
const x = "Hello world"
```

You can also use the React component if you prefer:

MDX syntax
1
2
3
<CodeBlock language="js" title="Code block title" showLineNumbers>
    {`const x = "Hello world"`}
</CodeBlock>

Here's how a code block without a title looks like:

1
const x = "Code block without a title"

Code highlighting

Prose UI code blocks are highlighted server-side using Shiki. Check out the list of languages supported by Shiki.

Since code highlighting happens server-side (the CodeBlock is a server component), all languages supported by Shiki are built-in. You don't need to configure them separately.

Customizing highlighter theme colors

To customize the highlighter theme colors we recommend that you override the following css variables:

CSS Variable
--p-color-syntax-syntax1
--p-color-syntax-syntax2
--p-color-syntax-syntax3
--p-color-syntax-syntax4

Fine-tuning code highlighting

If you'd like more granular control, you can modify syntax token colors for the code block component. Below are all the available CSS variables and their default values:

VariableDefault value
--p-code-block-color-texthsl(var(--p-color-text))
--p-code-block-color-constanthsl(var(--p-color-syntax-syntax1))
--p-code-block-color-stringhsl(var(--p-color-syntax-syntax2))
--p-code-block-color-commenthsl(var(--p-color-text-low))
--p-code-block-color-keywordhsl(var(--p-color-syntax-syntax3))
--p-code-block-color-parameterhsl(var(--p-color-text))
--p-code-block-color-functionhsl(var(--p-color-syntax-syntax4))
--p-code-block-color-string-expressionhsl(var(--p-color-syntax-syntax2))
--p-code-block-color-punctuationhsl(var(--p-color-text))
--p-code-block-color-linkhsl(var(--p-color-syntax-syntax2))

To learn more about Prose UI design system and CSS variables check out the styling page.

Created by Valdemaras, designed by Domas. Source code available on GitHub.