Skip to the page content

Rich text editor

Rich text fields with a full toolbar, Markdown, mentions, merge fields, revisions and a character limit.

8 editors

Rich text editor, full toolbar

A contentEditable field that saves clean HTML. Use it for long copy that needs structure. The toolbar has bold, italic, underline, text styles, lists, links, emoji, undo and clear formatting, plus an HTML source view and full screen. Word count, reading time and unsaved-changes status sit underneath, and the preview beside it shows the saved HTML as it will render.

Full toolbar

Sculpted Shoulder Blazer

A blazer built in Maine from grain de poudre wool. It weighs just 13 ounces and keeps you warm on a cold platform at seven in the morning.

  • Built by Hollis Atelier in coastal Maine
  • Horn buttons, ribbed cuffs, two pockets
  • Pairs with the Cat-Eye Sunglasses and the Bar Loafers
The one our customers reach for when a coat is too much and a shirt too little.

0 words0 charactersUnder a minute to read

Saved

Show code
<div class="fe-toolbar" role="toolbar" aria-label="Formatting">
  <button class="fe-tool" data-fe-cmd="bold" aria-pressed="false" aria-label="Bold">…</button>
  <select class="fe-toolbar-select" data-fe-block>…</select>
</div>
<div class="fe-editor-body" contenteditable="true" role="textbox"
     aria-multiline="true" aria-label="Product description">…</div>

// Arrow keys move along the toolbar, one Tab stop for the whole row.
document.execCommand('formatBlock', false, 'h3');

Markdown editor with preview

A plain textarea that stores Markdown and renders it side by side, or in tabs on narrow screens. Use it when the saved value should stay plain text. The toolbar inserts the symbols around the selection, Ctrl+B and Ctrl+I work, and the result copies as Markdown or HTML.

Markdown

0 words

Show code
// Wrap the selection, or insert a placeholder and select it.
function wrap(before, after, fallback) {
  const { selectionStart: s, selectionEnd: e, value } = text;
  const inner = value.slice(s, e) || fallback;
  text.setRangeText(before + inner + after, s, e, 'end');
  text.setSelectionRange(s + before.length, s + before.length + inner.length);
}
wrap('**', '**', 'bold text');

Inline editor, floating toolbar

A rich text field with no fixed toolbar. Select text and a small toolbar appears above it with bold, italic, highlight, heading and clear. Use it where the text should read like the finished page. From the keyboard, select with Shift and the arrows, then press Alt+F10.

Floating toolbar

Oakhaven Studio, 418 Moorings Street

Mrs Lowe's flat is on the third floor, past the second fire door by the lift. Ask the front desk for the spare key and sign it back in when you leave.

Her medication changed in June. If she seems drowsy again, check the blister pack first; the last two times it was a missed dose, not the new pills.

Select text for the toolbar. Esc closes it and puts you back in the text.

Show code
document.addEventListener('selectionchange', () => {
  const sel = getSelection();
  if (sel.isCollapsed || !body.contains(sel.anchorNode)) return hide();
  const r = sel.getRangeAt(0).getBoundingClientRect();
  bar.style.left = r.left + r.width / 2 - box.left + 'px';
  bar.style.top = r.top - box.top + 'px';
});

Textarea with character limit

A textarea with a hard limit, here 180 characters. The ring fills as you type, turns amber at 90% and red past the limit, and the overflow is highlighted in place so you can see what to trim. The field grows with its text and the limit is checked on save.

Character limit
180 left

Sent to the customer by SMS. Up to 180 characters.

Show code
<div class="fe-limit">
  <div class="fe-limit-mirror" aria-hidden="true"></div>
  <textarea class="fe-limit-text" data-max="180"></textarea>
</div>

// The mirror sits under the textarea and marks the overflow.
mirror.innerHTML = esc(v.slice(0, max)) + '<mark>' + esc(v.slice(max)) + '</mark>';
ring.classList.toggle('is-near', n >= max * 0.9 && n <= max);
ring.classList.toggle('is-over', n > max);

Required editor with a word minimum

A rich text field that validates like any other form field. It is required and needs 25 words; the counter in the toolbar checks off when the minimum is met. On submit the error shows under the field, and the summary at the top links straight to it.

Validation

Required, at least 25 words.

Show code
<label id="about-label">Tell us about your business</label>
<div id="about" contenteditable="true" role="textbox"
     aria-labelledby="about-label" aria-required="true"
     aria-describedby="about-help about-error" aria-invalid="false"></div>

<!-- Each error links to its field -->
<li><a href="#about">Tell us a bit more, 12 words to go</a></li>

Mentions and saved replies

A comment box that suggests as you type. @ lists people and inserts them as one unbreakable token; / inserts a saved reply. Use it for notes and comments where people need to be told. Arrow keys pick, Enter inserts, Esc closes, Ctrl+Enter posts.

Mentions

Order #10482 · 2 × Sculpted Blazer, 2 × Two-Tone Oxfords

  1. Todd RoachYesterday, 4:40 pm

    Arbor North Studio needs their PO number on the invoice. @Elaine Loy can you add it before this ships?

  2. Elaine LoyToday, 9:12 am

    Will do. The oxfords are short until Thursday though.

Try @ma or /split. Mentioned people get an email.

No one mentioned yet

Show code
<div contenteditable="true" role="textbox" aria-autocomplete="list"
     aria-controls="suggestions"></div>
<ul id="suggestions" role="listbox" hidden></ul>

// A mention is one piece the caret steps over, not loose text.
<span class="fe-mention" contenteditable="false">@Elaine Loy</span>

Template editor with merge fields

A rich text field for templates. Placeholders go in from the Insert field menu as tokens that delete whole, and curly-bracket fields in the subject line are filled too. Preview swaps every field for a real record, picked from the list.

Merge fields

Fields in curly brackets work here too.

Hi First name,

Your Plan care plan is due a visit. We've booked a Visit type for Next visit, between 8 and 12, and the visit is Amount.

Need a different day? Reply to this email or reschedule in the customer portal.

Show code
<span class="fe-field" contenteditable="false"
      data-field="first_name">First name</span>

// Preview: swap every field for the customer's value.
clone.querySelectorAll('[data-field]').forEach((f) => {
  f.replaceWith(person[f.dataset.field]);
});

Version history with word diff

A read-only view of saved versions of a text field. Pick a version to compare it with the one before: added words are underlined, removed ones struck through. Switch to a clean copy, and restore any older version.

Revisions
Version

Show code
// Word diff: the longest run the two versions share, then
// everything outside it is either added or removed.
<ins>within 30 days</ins> <del>within 14 days</del>

ins { text-decoration: underline; }
del { text-decoration: line-through; }