Rich Text for Canvas

Rich text for any canvas.

↑ This headline is a live text box. Click it to edit.

Any HTML canvas

Works with a standard HTML canvas element. No canvas library required.

Native on Konva

Text boxes are Konva nodes. Add them to your stage like any other shape.

Free to install and develop with. You need a license to go live.

Add it to your app in seconds

Install the package and create a text box. Typing, selection, copy and paste, undo and resize handles are all included.

You keep full control of your toolbar, selection and styling.

Free to develop with. Without a license key, each text box shows a faint "Development" watermark. When you go live, a license removes it on your site. See pricing
import { createCanvasRichText, createDocumentFromText }
  from "@mycreativeshop/rich-text";

// Works with any HTML canvas element
const rt = createCanvasRichText({ onChange: render });
rt.addBox({ x: 40, y: 40, width: 400,
  document: createDocumentFromText("Grand opening", 48) });

function render() {
  drawYourScene(ctx);
  rt.paint(ctx);        // the text
  rt.paintOverlay(ctx); // cursor, selection, handles
}
import { enableRichText, RichText, createDocumentFromText }
  from "@mycreativeshop/rich-text/konva";

// Turn on editing for a Konva stage
const rt = enableRichText(stage);

layer.add(new RichText({
  x: 40, y: 40, width: 400, draggable: true,
  document: createDocumentFromText("Grand opening", 48),
}));
The problem

Editable text on a canvas is hard to build

The canvas API only draws plain text: fillText() draws one line in one style, and browsers draw it slightly differently. Everything else is yours to build, and each piece below is a large project on its own. Rich Text for Canvas includes all of them.

Line wrapping

Included

Break text into lines when one line mixes sizes, and handle words too long for the box.

Text shaping

Included

Kerning, ligatures and accents. The canvas API doesn't expose them, so you need a shaping engine.

Mixed styles

Included

Different fonts, sizes and colors in one paragraph, measured and lined up on a shared baseline.

Cursor, selection and typing

Included

Place the cursor between letters, select across lines and styles, and support every keyboard shortcut.

Copy and paste

Included

Keep styles when copying between text boxes, and clean up text pasted from other apps.

Undo and redo

Included

Record every edit, style change, move and resize so each one can be undone.

Font loading

Included

Wait for fonts before measuring, and find a font for characters the chosen one lacks.

Vector text

Included

Draw letters as shapes from the font file, so text looks the same in every browser and in print.

Features

Try every feature

Each feature opens a live example in the demo.

Open the full demo →

Start here

Editing

Text formatting

Effects

Text boxes

Fonts and rendering

Data

Integrations

Why use a library

A first version is quick to build. The edge cases are the hard part.

These are cases real users run into. Each one is handled, and each one is covered by automated tests.

Cursor placement

Handled

The cursor lands exactly where you click, and moves correctly across lines, mixed sizes and lists.

Text pasted from other apps

Handled

Line breaks become new paragraphs, so pasted text keeps its shape.

Spellcheck

Handled

Misspelled words are underlined, with suggestions, Add to dictionary and Ignore on right-click.

Custom fonts

Handled

Load fonts from your server, a font vendor, or a file your user uploads. If a font can't load, you're told why.

A character the font doesn't have

Handled

It is drawn from a fallback font, and only that character is downloaded.

Bold in a font with no bold weight

Handled

Real weights are used when the font has them, and bold is synthesized only when it doesn't.

Emoji

Handled

Drawn from one emoji set, so they look the same on every device and in print.

Ligatures and accents

Handled

Shaped with HarfBuzz, so letters join and stack correctly.

Resizing a text box

Handled

Corner handles scale the text with the box, never out of proportion. Side handles rewrap it.

Text that doesn't fit its box

Handled

It shrinks to fit, so a paragraph pasted into a headline still fits.

Undo after a resize

Handled

Every edit, move and resize is one undo step.

The same text in two browsers

Handled

Vector rendering draws identical pixels in each one.

Tested

More than 1,300 automated tests run in real browsers. Rendered text is compared pixel by pixel with approved images, on HTML canvas and on Konva.

Proven in production

It's the text engine in the MyCreativeShop design editor. Customers use it every day to make flyers, postcards and signs that get printed and mailed.

Supported

Built and maintained by the team that depends on it. Email support, and updates when browsers change.

We built it because our own editor needed it. Every fix we make for our customers ships to yours.