Skip to content
WunderUI

Rich Text Editor

Free

Edit formatted text, such as a note, description or reply, with a toolbar for bold, italic, underline, lists and links.

npx wunderui-cli add rich-text-editor

Playground

Write a short note...

Installation

bash
npx wunderui-cli add rich-text-editor

Writes the source into your project with its dependencies and, on first use, the styles - see Installation.

Then import what you need:

tsx
import {
  RichTextEditor,
  RichTextEditorSkeleton,
} from "@/components/wunderui/rich-text-editor"
import type {
  RichTextEditorProps,
} from "@/components/wunderui/rich-text-editor"

Then use it:

tsx
import { useState } from "react"
import { Label } from "@/components/ui/label"
import { RichTextEditor } from "@/components/ui/rich-text-editor"

export function Notes() {
  const [html, setHtml] = useState("")

  return (
    <div className="flex flex-col gap-1">
      <Label id="notes-label" className="mb-1">
        Meeting notes
      </Label>
      <RichTextEditor aria-labelledby="notes-label" placeholder="Write a short note..." onChange={setHtml} />
      <p className="text-xs text-text-tertiary">{html}</p>
    </div>
  )
}

Expected result: You should see the label Meeting notes above a frame with a toolbar of six buttons and the grey placeholder. Type some text and press Bold: the button turns pressed and the HTML shows a strong tag.

When to use

Use Rich Text Editor for

  • Notes, descriptions and release notes where bold, lists and links make the text easier to scan
  • A reply or a comment that people format before they send it
  • Content that is stored as HTML and shown formatted somewhere else

Use something else for

  • Textarea for plain text over several lines, such as a message or feedback
  • Prompt Input for the message box of an AI chat, which is not a rich text editor
  • Input for one line of text, such as a title or a name

Content

The editor starts from the HTML you pass as content. Type to edit it and use the toolbar or shortcuts to format; a dash and a space at the start of a line begins a list.

Write a short note...

States

While the text is empty the placeholder shows. Focus is a real state: click into the text, or press Tab to reach the toolbar and then the text, and the whole frame takes the indigo border and ring.

Write a short note...

Label and helper

The editing area is a text box that you name with a visible label or an aria-label. A label cannot point at it with htmlFor, so link it with aria-labelledby, and a helper line with aria-describedby.

Describe the project...

Output

The change handler gives you the whole document as an HTML string after every edit. Store it, and pass it back as content when the person returns to edit.

Write something...

HTML from onChange

<p>Ship <strong>before Friday</strong>.</p>

Block menu

With slashMenu, typing / at the start of a line or after a space opens a menu of blocks at the caret: Heading 1 and 2, bulleted and numbered list, task, quote, divider and code. Type to filter, use the arrow keys and Enter or Tab, or click; Escape closes it and keeps the text. The editing area keeps the focus and points at the active block, and a live region says how many match. Pass your own list to change the blocks, or add to richTextEditorSlashItems. Without the prop the editor behaves as before.

Write something...

Keyboard interactions

Every toolbar button is its own tab stop, followed by the editing area. In the text the shortcuts are the ones of the editing engine, with Cmd instead of Ctrl on a Mac, and there is none for the link.

TaborShiftTab
Moves focus through the toolbar buttons and into the editing area. Inside a list item that has an item before it, Tab indents the item and Shift+Tab outdents it; when the item cannot move, Tab leaves the editor.
EnterorSpace
On a toolbar button: turns the format on or off. Link opens the browser's prompt for the address.
CtrlBorCtrlIorCtrlU
Toggles bold, italic or underline on the selected text, or for the text typed next.
CtrlShift8orCtrlShift7
Turns the paragraph into a bulleted or a numbered list, or back into a paragraph.
Enter
Starts a new paragraph, or a new list item inside a list.
ShiftEnter
Inserts a line break inside the same paragraph.
CtrlZorCtrlShiftZ
Undoes and redoes the last edit.

Behavior and motion

What the editor does with the text, the toolbar and the loading, and what it leaves to the page.

Loading
The editing engine is a separate chunk, so an app that never shows the editor never downloads it. A skeleton with the same frame shows until it loads, so nothing moves.
Content in and out
The content is the HTML the editor starts with, and the change handler gets the whole document as HTML after every edit. Changing the content later does nothing; a new key loads other text.
Toolbar state
Every button reads the selection and is pressed while the cursor is inside bold, italic or underlined text, a list or a link. A press keeps the focus in the text.
What it can write
Paragraphs and line breaks, bold, italic, underline, bulleted and numbered lists, and links. Other common elements such as headings and quotes survive pasting, but there is no button for them.
Links
The Link button asks for the address in the browser's prompt: an address sets the link, an empty answer removes it, Cancel leaves it. Clicking a link in the editor does not follow it.
Labelling
The editing area is a multi-line textbox, and aria-label, aria-labelledby and aria-describedby reach it. A click on a Label does not move focus into it, because labels only do that for form controls.
Focus
When the text has focus, the whole frame turns indigo with the 2 px ring, because the text itself has no outline. A toolbar button shows its own indigo border and ring.
Size
The editing area is at least 128 px tall and grows with the text, so the page scrolls, not the editor. After a list the document ends with an empty paragraph, so you can keep typing.
No disabled, read-only or invalid state
The Figma set draws disabled, read-only and invalid states, but the React editor does not take them yet. Render the saved HTML for read-only text, and colour the frame for an error.
Motion
The toolbar buttons change fill and colour quickly on hover and press. Nothing moves or scales, and typing never animates.
Reduced motion
With reduced motion the same colour change stays: it is a short fade, not movement.

Anatomy

Rich Text Editor is one frame: a toolbar of six formatting buttons above an editing area. The label and helper line are the parts you put around it.

Write something...
  • A 16 px frame with a 1 px border around the toolbar and the editing area. It loads its engine (Tiptap) on first render, shows a skeleton until then and gets an indigo ring on focus.

  • A row of 28 px icon buttons in 6 px of padding with a 2 px gap, closed off from the text by a 1 px line. The buttons are Bold, Italic, Underline, Bulleted list, Numbered list and Link.

  • A 28 px icon button with an 8 px corner. It is a toggle, shown pressed while the cursor is in text with that format, and Link asks for the address in the browser's prompt.

  • Optional

    A 1 px line, 20 px high, between the text styles, the lists and the link.

  • The editable text: a multi-line textbox at least 128 px tall with 12 px padding that grows with its content. While empty it shows the placeholder, and you name it with an aria-label.

  • Optional

    The empty frame with the placeholder that shows until the editor has loaded, 38 px of toolbar and 128 px of text. Export it for your own loading state.

Best practices

  • Do

    Name the editing area with aria-labelledby pointing to a visible Label, or an aria-label when there is no room. A label with htmlFor cannot reach it, because the area is not a form control.

  • Do

    Store the HTML from the change handler and pass it back as the content when the person returns. The content is the starting text only, so use a new key to load other content.

  • Do

    Sanitize the HTML on your server before you store it or show it to other people. The editor limits the tags it produces, but a server should never trust the browser.

  • Do

    Say what is wrong next to the editor and keep the text. The editor has no invalid state of its own, so colour the frame with the error border and link the message with aria-describedby.

  • Do

    Turn on slashMenu for longer documents such as notes and briefs: "/" opens a block menu at the caret (headings, lists, task, quote, divider, code). Keep it off for short replies, where the toolbar is enough.

  • Don’t

    Don't use it for text that must stay plain, such as a name, a title or a search term. The output is HTML, not plain text, and a one-line Input is easier to fill in.

  • Don’t

    Don't use it as the composer of an AI chat. That is a Prompt Input: it sends on Enter, grows with the message and has attach and send buttons, not a formatting toolbar.

  • Don’t

    Don't rely on a shortcut for the link. There is none: the toolbar button is the way to add or remove a link.

API reference

RichTextEditor wraps no primitive, so it takes only the props below. The four accessibility props go to the editing area, not the frame.

A 16 px frame with a 1 px border around the toolbar and the editing area. It loads its engine (Tiptap) on first render, shows a skeleton until then and gets an indigo ring on focus.

PropTypeDefaultDescription
contentstring—The HTML the editor starts with, for example . It is read once: later changes to the prop do not replace what was typed, so use a new to load other content.
onChange(html) => void—Called with the whole document as an HTML string after every edit. Store it, and pass it back as when the person returns.
placeholderstring—The grey text shown while the editor is empty. Defaults to . It is not a label.
aria-labelstring—The accessible name of the editing area when there is no visible label.
aria-labelledbystring—The id of the element that names the editing area, such as a visible . Use it instead of , which does not reach a text box that is not a form control.
aria-describedbystring—The id of the element that describes the editing area, such as a helper line or an error message.
idstring—The of the editing area, for and of other elements to point at.
classNamestring—Extra classes on the frame, for example to mark a problem or a width.
slashMenuboolean | SlashItem[]—Typing "/" at the start of a line or after a space opens a block menu at the caret: arrow keys pick, Enter or Tab inserts, Escape closes, typing filters. shows the default blocks (headings, lists, task, quote, divider, code); pass y…

The empty frame with the placeholder that shows until the editor has loaded, 38 px of toolbar and 128 px of text. Export it for your own loading state.

PropTypeDefaultDescription
placeholderstring—The text shown in the skeleton, so it matches the placeholder of the editor that replaces it.
classNamestring—Extra classes on the frame of the skeleton, the same as on the editor.

Notes for AI

Give your coding assistant the Markdown reference instead of screenshots.

MCPget_component("rich-text-editor")
Installnpx wunderui-cli add rich-text-editor

The full library index for assistants is at /llms.txt.