2021-10-14 06:13:50 +08:00
---
description: Add an image (but a beautiful one), when words aren’ t enough.
2021-10-15 03:20:21 +08:00
icon: image-line
2021-10-14 06:13:50 +08:00
---
2020-10-27 22:32:55 +08:00
# Image
2021-01-25 17:35:52 +08:00
[![Version ](https://img.shields.io/npm/v/@tiptap/extension-image.svg?label=version )](https://www.npmjs.com/package/@tiptap/extension-image)
[![Downloads ](https://img.shields.io/npm/dm/@tiptap/extension-image.svg )](https://npmcharts.com/compare/@tiptap/extension-image?minimal=true)
2020-11-03 23:43:35 +08:00
Use this extension to render `<img>` HTML tags. By default, those images are blocks. If you want to render images in line with text set the `inline` option to `true` .
:::warning Restrictions
This extension does only the rendering of images. It doesn’ t upload images to your server, that’ s a whole different story.
:::
2020-10-27 22:32:55 +08:00
## Installation
```bash
npm install @tiptap/extension -image
```
2020-10-30 23:57:55 +08:00
## Settings
2021-10-02 07:20:09 +08:00
2022-02-09 19:21:03 +08:00
### inline
Renders the image node inline, for example in a paragraph tag: `<p><img src="spacer.gif"></p>` . By default images are on the same level as paragraphs.
It totally depends on what kind of editing experience you’ d like to have, but can be useful if you (for example) migrate from Quill to Tiptap.
Default: `false`
2021-10-02 07:20:09 +08:00
```js
Image.configure({
2022-02-09 19:21:03 +08:00
inline: true,
2021-10-02 07:20:09 +08:00
})
```
2022-02-09 19:21:03 +08:00
### allowBase64
Allow images to be parsed as base64 strings `<img src="data:image/jpg;base64...">` .
2021-10-02 07:20:09 +08:00
Default: `false`
```js
Image.configure({
2022-02-09 19:21:03 +08:00
allowBase64: true,
})
```
### HTMLAttributes
Custom HTML attributes that should be added to the rendered HTML tag.
```js
Image.configure({
HTMLAttributes: {
class: 'my-custom-class',
},
2021-10-02 07:20:09 +08:00
})
```
2020-10-30 23:57:55 +08:00
2021-10-02 06:14:44 +08:00
## Commands
### setImage()
Makes the current node an image.
```js
2021-11-10 14:30:41 +08:00
editor.commands.setImage({ src: 'https://example.com/foobar.png' })
2021-10-02 06:14:44 +08:00
editor.commands.setImage({ src: 'https://example.com/foobar.png', alt: 'A boring example image', title: 'An example' })
```
2020-10-27 22:32:55 +08:00
## Source code
2021-04-21 21:31:11 +08:00
[packages/extension-image/ ](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-image/ )
2020-10-27 22:32:55 +08:00
## Usage
2021-10-19 00:01:47 +08:00
https://embed.tiptap.dev/preview/Nodes/Image