A rich text editor component powered by TipTap, providing customizable formatting tools, form integration, and accessible content editing.
The Rich Text Editor is suited for content management systems, comment sections, documentation editors, and any application requiring formatted HTML input. Common use cases include:
Under the hood, this component uses TipTap.
While we have tried our best to secure our component, having a rich text editor is inherently risky. Because it operates on the frontend, input can always be bypassed or tampered with by users. Always sanitize and validate HTML input on the server side.
Once everything is configured, you may use the <z-rte> markup in your HTML code:
RTE is headless by default. This means there is no built-in typography styling inside the content area, and developers are expected to style prose elements (headings, lists, blockquotes, paragraphs) according to their design system.
You can use the following snippet as a starting point:
.z-rte-body .ProseMirror strong {
font-weight: 700;
}
.z-rte-body .ProseMirror u {
--z-u-font-weight: 500;
--z-u-underline-offset: 4px;
font-weight: var(--z-u-font-weight);
text-decoration-line: underline;
text-underline-offset: var(--z-u-underline-offset);
}
.z-rte-body .ProseMirror ol {
list-style-type: decimal;
}
.z-rte-body .ProseMirror ul {
list-style-type: disc;
}
.z-rte-body .ProseMirror ol,
.z-rte-body .ProseMirror ul {
--z-list-indent: 32px;
padding-inline-start: var(--z-list-indent);
}
.z-rte .ProseMirror h1 {
font-size: calc(var(--z-global-font-size) * 3.052);
font-weight: 800;
letter-spacing: -0.025em;
line-height: 1.1;
}
.z-rte .ProseMirror h2 {
font-size: calc(var(--z-global-font-size) * 2.441);
font-weight: 700;
letter-spacing: -0.025em;
line-height: 1.15;
}
.z-rte .ProseMirror h3 {
font-size: calc(var(--z-global-font-size) * 1.953);
font-weight: 700;
letter-spacing: -0.025em;
line-height: 1.2;
}
.z-rte .ProseMirror h4 {
font-size: calc(var(--z-global-font-size) * 1.563);
font-weight: 600;
letter-spacing: -0.025em;
line-height: 1.25;
}
.z-rte .ProseMirror h5 {
font-size: calc(var(--z-global-font-size) * 1.25);
font-weight: 600;
letter-spacing: -0.025em;
line-height: 1.3;
}
.z-rte .ProseMirror h6 {
font-size: var(--z-global-font-size);
font-weight: 600;
letter-spacing: -0.025em;
line-height: 1.4;
}
.z-rte .ProseMirror blockquote {
margin-block-start: calc(var(--z-global-line-height) * 1);
border-inline-start-width: 2px;
border-color: color-mix(in srgb, var(--z-border) 10%, transparent);
padding-inline-start: calc(var(--z-global-line-height) * 1);
font-style: italic;
}If you run multiple instances of the RTE component on a single page, you can customize the selectors as well as the cls target. Note that .z-rte targets the wrapping div of the editor, while .ProseMirror targets the actual editor area. You can customize these selectors however you want via the cls tag. Learn more about available cls targets.
Set initial HTML content strictly using a <template data-fn="value"> element inside the component:
This is some initial content with formatting.
The template content supports full HTML and is parsed into the editor with formatting preserved. Setting initial content via a value attribute is intentionally unsupported to avoid escaping raw HTML in attributes.
By default, the editor displays all available tools organized into five groups:
bold, italic, underline, strikethroughlist, list-orderedh1, h2, h3, h4align-left, align-right, align-center, align-justifyblockquoteYou can customize which tools appear and how they are grouped using the toolbar attribute or a configuration script.
To render the editor without a toolbar, set toolbar to "none", "false", or "[]":
| Item | Aliases | Icon Key | Description |
|---|---|---|---|
bold | — | bold | Toggles bold text |
italic | — | italic | Toggles italic text |
underline | — | underline | Toggles underlined text |
strikethrough | strike | strikethrough | Toggles strikethrough text |
list | bullet-list, bulletList | list | Toggles a bulleted list |
list-ordered | ordered-list, orderedList | list-ordered | Toggles a numbered list |
h1 | heading-1 | heading-1 | Toggles Heading 1 |
h2 | heading-2 | heading-2 | Toggles Heading 2 |
h3 | heading-3 | heading-3 | Toggles Heading 3 |
h4 | heading-4 | heading-4 | Toggles Heading 4 |
align-left | — | align-left | Aligns text to the left |
align-center | — | align-center | Centers text |
align-right | — | align-right | Aligns text to the right |
align-justify | — | align-justify | Justifies text |
blockquote | quote, text-quote | text-quote | Toggles blockquote formatting |
When a name attribute is provided, the component automatically renders and syncs a hidden <input type="hidden"> element for form submission:
<form method="POST" action="/save">
<z-rte name="blog_content" placeholder="Write your blog post..."></z-rte>
<button type="submit">Publish</button>
</form>The form will receive the serialized HTML string under the blog_content field name.
A live word counter is displayed in the footer of the editor, updating automatically as users type and using localized singular or plural labels based on the current word count.
This component allows you to customize toolbar icons through the <template data-fn="icons"> system using the icon keys listed in the Available toolbar items table:
The Rich Text Editor component supports internationalization through multiple methods with the following priority order (highest to lowest):
i18n attribute or script tag)<script id="z-i18n">)Place this in your document <head> or before any editor components:
<script id="z-i18n" type="application/json">
{
"z-rte": {
"word-counter-singular": "Wort",
"word-counter-plural": "Wörter",
"tooltip-bold": "Fett",
"tooltip-italic": "Kursiv",
"tooltip-underline": "Unterstrichen",
"tooltip-strikethrough": "Durchgestrichen",
"tooltip-list": "Aufzählung",
"tooltip-list-ordered": "Nummerierte Liste",
"tooltip-h1": "Überschrift 1",
"tooltip-h2": "Überschrift 2",
"tooltip-h3": "Überschrift 3",
"tooltip-h4": "Überschrift 4",
"tooltip-align-left": "Linksbündig",
"tooltip-align-center": "Zentriert",
"tooltip-align-right": "Rechtsbündig",
"tooltip-align-justify": "Blocksatz",
"tooltip-blockquote": "Zitat",
"aria-toolbar": "Formatierungsoptionen",
"aria-editor": "Rich-Text-Editor"
}
}
</script>| Key | Default | Description |
|---|---|---|
word-counter-singular | 'word' | Label used when the word count is exactly 1. |
word-counter-plural | 'words' | Label used when the word count is 0 or > 1. |
tooltip-bold | 'Bold' | Tooltip and aria-label for the bold button. |
tooltip-italic | 'Italic' | Tooltip and aria-label for the italic button. |
tooltip-underline | 'Underline' | Tooltip and aria-label for the underline button. |
tooltip-strikethrough | 'Strikethrough' | Tooltip and aria-label for the strike button. |
tooltip-list | 'List' | Tooltip and aria-label for the bullet list. |
tooltip-list-ordered | 'Ordered List' | Tooltip and aria-label for the ordered list. |
tooltip-h1 | 'Heading 1' | Tooltip and aria-label for the H1 button. |
tooltip-h2 | 'Heading 2' | Tooltip and aria-label for the H2 button. |
tooltip-h3 | 'Heading 3' | Tooltip and aria-label for the H3 button. |
tooltip-h4 | 'Heading 4' | Tooltip and aria-label for the H4 button. |
tooltip-align-left | 'Align Left' | Tooltip and aria-label for left alignment. |
tooltip-align-center | 'Align Center' | Tooltip and aria-label for center alignment. |
tooltip-align-right | 'Align Right' | Tooltip and aria-label for right alignment. |
tooltip-align-justify | 'Align Justify' | Tooltip and aria-label for justify alignment. |
tooltip-blockquote | 'Blockquote' | Tooltip and aria-label for blockquote. |
aria-toolbar | 'Formatting options' | Accessible aria-label for the toolbar region. |
aria-editor | 'Rich text editor' | Accessible aria-label for the editable area. |
The Rich Text Editor component supports custom CSS classes through the cls attribute. This allows you to style specific elements within the editor without modifying the component’s internal structure.
Apply a class to the default element (editor):
<z-rte cls="prose min-h-48"></z-rte>Target specific elements within the editor:
<z-rte
cls='{
"container": "z-rte custom-rte-wrapper",
"header": "z-rte-header",
"toolbar": "z-rte-toolbar",
"toolbar-group": "z-rte-toolbar-group",
"button": "z-btn z-btn-ghost z-btn-icon z-btn-sm",
"body": "z-rte-body",
"editor": "prose max-w-none min-h-40",
"footer": "z-rte-footer text-muted"
}'
></z-rte><z-rte>
<script type="application/json" data-fn="config">
{
"cls": {
"button": "z-btn z-btn-ghost z-btn-icon z-btn-sm",
"editor": "prose max-w-none min-h-40"
}
}
</script>
</z-rte>| Target | Default Class | Description |
|---|---|---|
container | z-rte | Outer wrapper element ([data-part="container"]). |
header | z-rte-header | Header container wrapping the toolbar ([data-part="header"]). |
toolbar | z-rte-toolbar | Scrollable toolbar container ([data-part="toolbar"]). |
toolbar-group | z-rte-toolbar-group | Wrapper around each group of buttons ([data-part="toolbar-group"]). |
button | "" | Individual toolbar action buttons ([data-part="button"]). |
body | z-rte-body | Mount container for the editor ([data-part="body"]). |
editor | "" | Default target. The editable .ProseMirror content element ([data-part="editor"]). |
footer | z-rte-footer | Footer container showing the word count ([data-part="footer"]). |
The Rich Text Editor component supports custom inline styles through the stl attribute. This allows you to apply specific CSS styles to individual elements within the component.
Apply styles to the default element (editor):
<z-rte stl="min-height\: 200px; max-height\: 400px;"></z-rte>Target specific elements with custom inline styles:
<z-rte
stl='{
"container": "max-width: 720px;",
"editor": "min-height: 220px; padding: 1rem;",
"footer": "text-align: right;"
}'
></z-rte><z-rte>
<script type="application/json" data-fn="config">
{
"stl": {
"editor": "min-height: 220px; max-height: 500px;"
}
}
</script>
</z-rte>The stl attribute supports the same targets as the cls attribute. See the Available cls targets table above for a complete list of targetable elements.
To indicate an error state in the form, simply add the .z-form-danger class to the cls attribute. This will apply a “danger” state to the component, providing visual feedback to the user.
When loading Web Components, a brief delay may cause a flash of unstyled content. To mitigate this issue, consider setting a predefined height on the parent element to prevent layout shift and ensure a smooth user experience.
<div class="[min-h]" style="--min-h: 7.5rem">
<z-rte name="content"></z-rte>
</div>role="toolbar" with grouped role="group" containers, while the editable area uses role="textbox" with aria-multiline="true", aria-required, and aria-disabled.tabindex navigation (ArrowLeft, ArrowRight, Home, and End), allowing keyboard users to tab directly from the toolbar into the editor with a single Tab press.aria-pressed="true|false" based on the current cursor selection.aria-live="polite" and aria-atomic="true" to announce word count updates non-disruptively.The following attributes are available for this component:
| Name | Type | Default | Description |
|---|---|---|---|
name | String | "" | Form field name for the hidden <input type="hidden"> element. |
placeholder | String | "" | Placeholder text displayed when the editor is empty. |
disabled | Boolean | false | Disables the editor and toolbar buttons, preventing content editing. |
required | Boolean | false | Marks the editor as required (aria-required="true"). |
toolbar | String | "" | Customizes or hides the toolbar groups (supports bracket, pipe, or JSON). |
cls | String | "" | Custom CSS classes for component elements (defaults to targeting editor). |
stl | String | "" | Custom inline styles for component elements (defaults to targeting editor). |
i18n | String | "" | Internationalization strings for toolbar tooltips, labels, and word count. |
force-prevent-rerender | Boolean | false | Forcefully prevents component rerendering after initial mount. |
The Rich Text Editor component triggers the following events:
| Name | Description |
|---|---|
z-rte:input | Fired when editor content changes, providing { value: string } in event.detail. |