Use fenced code blocks by enclosing code in three backticks. Code blocks are copyable, and if you have the assistant enabled, users can ask AI to explain the code.
Specify the programming language for syntax highlighting and to enable meta options. Add any meta options, like a title or icon, after the language.
class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); }}
Enable syntax highlighting by specifying the programming language after the opening backticks of a code block.
We use Shiki for syntax highlighting and support all available languages. See the full list of languages in Shiki's documentation.
Customize code block themes globally using styling.codeblocks in your config.json file. Set simple themes like system or dark, or configure custom Shiki themes for light and dark modes. See Settings for configuration options.
class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); }}
In JavaScript and TypeScript code blocks, use twoslash to enable interactive type information. Users can hover over variables, functions, and parameters to see types and errors like in an IDE.
type Pet = "cat" | "dog" | "hamster";function adoptPet(name: string, type: Pet) { return `${name} the ${type} is now adopted!`;}// Hover to see the inferred typesconst message = adoptPet("Luna", "cat");
```ts twoslash Twoslash exampletype Pet = "cat" | "dog" | "hamster";function adoptPet(name: string, type: Pet) { return `${name} the ${type} is now adopted!`;}// Hover to see the inferred typesconst message = adoptPet("Luna", "cat");```
Enable text wrapping for long lines using the <CodeBlock> component with the wrap prop. This prevents horizontal scrolling and makes long lines easier to read.
const greeting = "Hello, World! I am a very long line of text that will wrap to the next line instead of requiring horizontal scrolling.";function sayHello() {console.log(greeting);}sayHello();
<CodeBlock language="javascript" filename="wrap.js" wrap>{`const greeting = "Hello, World! I am a very long line...";`}</CodeBlock>
Use the <CodeBlock> component in custom React components to programmatically render code blocks with the same styling and features as markdown code blocks.