maxHTMLLength and maxTextLength

Two ways to cap how much a user can enter: maxHTMLLength counts the saved markup, maxTextLengthcounts the visible text. Type past a limit in either editor below and watch the counter — and what happens to your keystrokes.

maxHTMLLength: 200

Counts the saved markup. A short sentence wrapped in a few tags is already most of the budget, so this limit is reached far sooner than the visible text suggests.

HTML length: 0 / 200

maxTextLength: 120

Counts only what the reader sees. This is the limit that matches a number you would show a user.

Text length: 0 / 120

What happens at the limit

The check runs when an edit is about to be committed to the undo history, not on every keystroke. Once over, the editor reverts to the last snapshot under the limit— the offending keystrokes are discarded rather than blocked — and raises a customdialog event named reachmaxlength. If nothing handles that event it falls back to a browser alert().

Both defaults are worth replacing in a real application: handle the event to show your own message, and show a live counter like the ones above so the limit is visible before it is hit.

// Cap the saved markup, including tags.
new RichTextEditor("#editor1", { maxHTMLLength: 200 });

// Or cap what the reader actually sees.
new RichTextEditor("#editor2", { maxTextLength: 120 });

// Replace the default alert() with your own UI.
editor.attachEvent("customdialog", function (name, message) {
    if (name !== "reachmaxlength") return false;   // not ours: let it through
    showToast(message);
    return true;                                   // handled — suppress the alert
});

If you set both, maxHTMLLength is tested first and maxTextLengthonly when the HTML limit passes — so the markup limit wins whenever it is the one exceeded.

Configuration reference · Plain text output