---
title: "Add a code block node to your Editor"
description: "Integrate a node component displaying code content in your Tiptap Editor. More in our docs!"
---

> This page is for Tiptap 2.x. [See the latest version of this page.](https://tiptap.dev/docs/ui-components/node-components/code-block-node.md)

# Add a code block node to your Editor

Integrate a node component displaying code content in your Tiptap Editor. More in our docs!

> **Upgrade to v3**
>
> To use UI components or templates you need to upgrade to Editor version 3.x. See the [upgrade
> guide](https://tiptap.dev/docs/resources/whats-new) for more details.

A styled code block node for displaying formatted code snippets in the editor.

> **Interactive demo:** [code block node](https://template.tiptap.dev/preview/tiptap-node/code-block-node)

## Install

You can add the node component via Tiptap CLI (for Vite or Next.js)

```bash
npx @tiptap/cli add code-block-node
```

### Manual Integration

For frameworks other than Vite or Next.js, add the node component manually from the [open-source repository](https://github.com/ueberdosis/tiptap-ui-components/tree/main/apps/web/src/components/tiptap-node/code-block-node).

### Import styles

This component requires you to import our styles which were added to `styles/keyframe-animation.scss` and `styles/_variables.scss`.

## Usage

The CodeBlockNode is primarily a styling component that enhances the appearance of code blocks in the editor. To use it, simply include it in your project and ensure you're using the CodeBlock extension from Tiptap.

```tsx
import { useEditor, EditorContent } from '@tiptap/react'
import { StarterKit } from '@tiptap/starter-kit'

import '@/components/tiptap-node/code-block-node/code-block-node.scss'

export default function EditorWithCodeBlock() {
  const editor = useEditor({
    extensions: [StarterKit],
    content: `<h2>1. Inline <code>&lt;code&gt;</code></h2>
    <p>You can use <code>&lt;code&gt;</code> to style short snippets like <code>const x = 42;</code>.</p>

    <h2>2. Block <code>&lt;pre&gt;&lt;code&gt;</code></h2>
    <pre><code>// This is a JavaScript example
function greet(name) {
    return \`Hello, \${name}!\`;
}

console.log(greet("World"));</code></pre>
    `,
  })

  return <EditorContent editor={editor} />
}
```

## Features

- Syntax highlighting styles for code blocks
- Dark mode support
- Proper spacing and margins
- Enhanced readability with monospace font

## Requirements

Open source feature(s)

- [`@tiptap/extension-code-block`](https://tiptap.dev/docs/v2/editor/extensions/nodes/code-block.md)
- [`@tiptap/extension-code-block-lowlight`](https://tiptap.dev/docs/v2/editor/extensions/nodes/code-block-lowlight.md)
