---
title: "Code extension"
description: "Use the Code extension in your Tiptap Editor to add inline code to your texts. Learn more in our docs!"
---

> This page is for Tiptap 2.x. [See the latest version of this page.](https://tiptap.dev/docs/editor/extensions/marks/code.md)

# Code extension

Use the Code extension in your Tiptap Editor to add inline code to your texts. Learn more in our docs!

The Code extensions enables you to use the `<code>` HTML tag in the editor. If you paste in text with `<code>` tags it will rendered accordingly.

Type something with <code>\`back-ticks around\`</code> and it will magically transform to `inline code` while you type.

> **Interactive demo:** [Code](https://v2--tiptap-embed.netlify.app/preview/Marks/Code)

## Install

```bash
npm install @tiptap/extension-code
```

## Settings

### HTMLAttributes

Custom HTML attributes that should be added to the rendered HTML tag.

```js
Code.configure({
  HTMLAttributes: {
    class: 'my-custom-class',
  },
})
```

## Commands

### setCode()

Mark text as inline code.

```js
editor.commands.setCode()
```

### toggleCode()

Toggle inline code mark.

```js
editor.commands.toggleCode()
```

### unsetCode()

Remove inline code mark.

```js
editor.commands.unsetCode()
```

## Keyboard shortcuts

| Command      | Windows/Linux                     | macOS                         |
| ------------ | --------------------------------- | ----------------------------- |
| toggleCode() | <kbd>Control</kbd> + <kbd>E</kbd> | <kbd>Cmd</kbd> + <kbd>E</kbd> |

## Source code

[packages/extension-code/](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-code/)
