2020-09-16 23:01:47 +08:00
# Custom styling
2020-09-27 16:29:01 +08:00
## Table of Contents
2020-10-01 18:26:20 +08:00
## Introduction
Tiptap is renderless, that doesn’ t mean there is no styling provided. You can decided how your editor should look like.
2020-09-22 22:03:31 +08:00
## Option 1: Style the plain HTML
The whole editor is rendered inside of a container with the class `.ProseMirror` . You can use that to scope your styling to the editor content:
2020-09-16 23:01:47 +08:00
```css
2020-09-22 22:03:31 +08:00
/* Scoped to the editor */
2020-09-27 17:01:25 +08:00
.ProseMirror p {
2020-09-22 22:03:31 +08:00
margin: 1em 0;
}
```
If you’ re rendering the stored content somewhere, there won’ t be a `.ProseMirror` container, so you can just globally add styling to the used HTML tags:
```css
/* Global styling */
2020-09-27 17:01:25 +08:00
p {
2020-09-16 23:01:47 +08:00
margin: 1em 0;
}
```
2020-09-22 22:03:31 +08:00
## Option 2: Add custom classes
Most extensions have a `class` option, which you can use to add a custom CSS class to the HTML tag.
2020-09-16 23:01:47 +08:00
```js
2020-09-22 22:03:31 +08:00
/* Add custom classes */
2020-09-16 23:01:47 +08:00
new Editor({
extensions: [
Document(),
Paragraph({
class: 'my-custom-paragraph',
}),
Heading({
class: 'my-custom-heading',
}),
Text(),
]
})
```
2020-09-22 22:03:31 +08:00
The rendered HTML will look like that:
2020-09-16 23:01:47 +08:00
```html
< h1 class = "my-custom-heading" > Example Text< / p >
< p class = "my-custom-paragraph" > Wow, that’ s really custom.< / p >
```
2020-09-22 22:03:31 +08:00
## Option 3: Customize the HTML
2020-09-16 23:01:47 +08:00
You can even customize the markup for every extension. This will make a custom bold extension that doesn’ t render a `<strong>` tag, but a `<b>` tag:
```js
2020-09-22 22:03:31 +08:00
/* Customizing the markup */
2020-09-16 23:01:47 +08:00
import Bold from '@tiptap/extension-bold'
const CustomBold = Bold
.schema(() => ({
toDOM: () => ['b', 0],
}))
.create()
new Editor({
extensions: [
// …
CustomBold(),
]
})
```
You should put your custom extensions in separate files though, but I think you’ ve got the idea.