Docs › Toolbar and look
Style menu
Apply your site's own classes from a menu (the styles option).
If your site has set looks such as a lead paragraph or a notice box, list them in styles. Writers pick a name instead of fiddling with colors and sizes, and the saved HTML carries your site's classes.
Try it
A paragraph with the Lead style.
Subheading
The notice box style. Put the caret in a paragraph and open the "Styles" menu in the toolbar.
Select a few words and pick Highlighter to wrap just those.
Code for this demo
createEditor('#editor', {
toolbar: 'styles | bold | bulletList',
styles: [
{ title: 'Lead', block: 'p', className: 'lead' },
{ title: 'Subheading', block: 'h3', className: 'sub' },
{ title: 'Notice box', block: 'p', className: 'box' },
{ title: 'Highlighter', inline: 'mark', className: 'hl' },
{ title: 'Muted', inline: 'span', style: 'color: #868e96' },
],
contentStyle: `
.lead { font-size: 1.15em; color: #495057; }
.sub { padding-left: 10px; border-left: 4px solid #2f6fed; }
.box { padding: 12px 16px; background: #f1f3f5; border-radius: 8px; }
.hl { background: #fff3bf; }
`,
});Entries
Each entry in styles takes these fields. Give it a className or a style so the menu can tell where it is applied.
titlethe name in the menublocka paragraph style: the paragraph becomes this tag and gets the class ('p','h2','h3'…).inlinea text style: the selected text is wrapped in this tag ('span','mark','small'…). Nothing happens without a selection.classNameone class: letters, digits,-and_, up to 40 characters.styleinline CSS instead of a class, written asproperty: valuepairs joined with;, e.g.'color: #868e96'.
Leave out both block and inline to just add the class to the current paragraph, list item, heading or quote.
On and off
Picking the same entry where it is already applied removes it. The menu button shows the style at the caret and the menu checks it. Entries with a style are previewed in that style.
Toolbar and presets
- The toolbar item is
styles. It is in the ⋯ menu of thefullpreset;boarddoesn't have it, so add it to your toolbar string. - With an empty
stylesoption the button never shows, even if listed.
Classes and the sanitizer
82editor normally strips every class that arrives through paste or setHTML. Classes named in styles are the exception, so pasted content using the same class names keeps them too.
The editor doesn't know what your classes look like. To see them while writing, add the same CSS to contentStyle, as the demo does.
Saved HTML
<p class="lead">A paragraph with the Lead style.</p>
<h3 class="sub">Subheading</h3>
<p>Select a few words and pick <mark class="hl">Highlighter</mark>…</p>
<p><span style="color: #868e96">Muted text</span></p>Options
| Name | Type | Default | Description |
|---|---|---|---|
styles | StyleFormat[] | - | Style menu entries; their classes pass the sanitizer |
title | string | - | Menu label (required) |
block | string | - | Tag the paragraph becomes |
inline | string | - | Tag wrapped around the selection |
className | string | - | Class to add |
style | string | - | Inline CSS to add |
styles | toolbar item | - | The style menu button |