Help
Quick start · npm package · Widgets · Handwritten codes · Ready-made recognizers · Custom symbols · Handwriting input · Games · Privacy & data · Supported devices · Troubleshooting · How it works
Quick start
- Want drawn reactions or star ratings on your site? Hosted widgets are coming: join the waitlist, and you'll get two lines of HTML to paste.
- Need to recognize handwritten letters or numbers? Test them on the home page,
download one of the ready-made zips, unzip it into your site, and call
recognize(strokes). Every zip includes a workingindex.htmlexample. - Want to recognize custom symbols? Use the Character recognition builder. Draw or upload a few examples of each symbol, test it right on the page, and download a zip.
- Using npm? Run
npm install millirecand jump to the npm section. - Want a handwritten text box? Check out Handwriting input, where users write letters on top of each other in one box. It embeds with a single script tag.
- Just want to try it out? Play the handwritten games on digitizer.fun. They all use millirec behind the scenes.
The npm package
All of the recognizers on this site are available in the millirec
npm package. It is MIT licensed, has zero dependencies, and ships as ES modules. Everything runs locally in the browser.
npm install millirec
Tell createRecognizer what you want to recognize and it will load the right engine for you:
import { createRecognizer } from 'millirec'
const rec = await createRecognizer('digits') // or 'capitals', 'lowercase', 'all', 'punctuation'
const rec = await createRecognizer({ alphabet: 'lowercase', priority: 'small' }) // 'accurate' (default) | 'fast' | 'small'
const rec = await createRecognizer({ examples: { yes: [y1, y2, y3], no: [n1, n2, n3] } }) // your own symbols
rec.attach(document.querySelector('#pad')) // mount a drawing pad
await rec.recognize(strokes, { only: '0123' }) // or pass strokes directly, limited to certain characters
Under the hood, it uses small neural networks (char-cnn) for letters and digits because they are
trained on hundreds of different writers and handle general handwriting well. For punctuation or custom symbols,
it uses the stroke matcher (char-lite), which can learn new shapes from just a few drawings.
(Note that char-lite's built-in sets were recorded by a single writer and measured on that writer
only, so they read that hand best; adding your own examples helps.) Both engines share the same core API — recognize(strokes, { only }),
attach(), teach(), and forget() — and you can import either one directly:
| import | what it does | customizable? |
|---|---|---|
millirec | exports createRecognizer() (and char-lite) | — |
millirec/char-lite | matches any symbol you give it examples for (digits, letters, punctuation, emoji, shapes) | yes — add samples or new classes |
millirec/char-cnn | reads capitals, lowercase, digits, or all 62 (the options below), plus custom symbols via teach() | teach() new symbols instantly, or personalize() to a writer |
millirec/char-lite/core, millirec/char-cnn/core | same recognizers without the built-in drawing pad UI | same |
millirec/pad | just the drawing pad component, if you want to wire it up yourself | — |
millirec/overlap/… (script tag) | reads whole words written letter-over-letter in one box | — |
Digits, letters, or custom symbols (char-lite)
import { MillirecCharLite, loadSet } from 'millirec/char-lite'
const training = await loadSet('digits') // 'all' | 'capitals' | 'digits' | 'lowercase' | 'punctuation'
const rec = await MillirecCharLite.create({ training })
rec.attach(document.querySelector('#pad')) // mount a drawing pad
document.querySelector('#pad').addEventListener('millirec:result', (e) => {
console.log(e.detail.results) // [{ char: '7', prob: 0.91 }, …] best first
})
// or pass your own strokes: an array of strokes, each an array of {x, y} points
const top3 = await rec.recognize([[{ x: 50, y: 10 }, { x: 52, y: 120 }]])
// add a user's handwriting or a brand-new symbol — class names can be any string
const mine = MillirecCharLite.withSamples(training, { '7': [seven1, seven2], '★': [s1, s2, s3] })
const personal = await MillirecCharLite.create({ training: mine })
Passing { replace: true } as the third argument to withSamples replaces the
built-in samples for that character instead of adding to them. That's a good option once you have 3 or 4
examples from the user. Millirec doesn't store anything on its own, so save the strokes yourself (for example in
localStorage) and rebuild the training data when the page loads.
Letters and digits (char-cnn)
import { MillirecCharCnn } from 'millirec/char-cnn'
const rec = await MillirecCharCnn.create({ option: 'fast' }) // capitals: 'accurate' (default) | 'fast' | 'small'
// or 'digits', 'lowercase', 'all' — each also -fast, -small
rec.attach(document.querySelector('#pad'))
await rec.recognize(strokes, { only: 'AEIOU' }) // restrict guesses to these characters
await rec.personalize({ A: [a1, a2, a3] }) // adapt to a specific writer
rec.destroy() // clean up when you're done
Custom symbols without training
const rec = await MillirecCharCnn.create()
await rec.teach({ star: [s1, s2, s3], heart: [h1, h2, h3], '✓': [t1, t2, t3] }) // a few drawings of each
await rec.recognize(strokes) // [{ char: 'star', prob: 0.93 }, …]
rec.forget() // switch back to the built-in alphabet
teach() keeps each example as what the neural network makes of it, and gives a new drawing the
name of its nearest example. It runs right in the browser with no training step. Even using the capital-letter
network (which has never seen a digit), 3 examples per digit read 96% of one writer's other digits, and
5 examples read 99%. If you need higher accuracy across many different writers, the
GitHub repo
has a short guide for training your own model.
The drawing pad
attach(el) creates a drawing pad for a single character. After every stroke, it fires a
millirec:result event with the top guesses in detail.results. If the user pauses
for two seconds and starts writing again, the pad fades the old drawing and starts fresh. Scribbling over the
drawing clears it too. Both actions fire millirec:clear with a detail.reason and an
undo() function. When the pad is empty, it reports an empty result list.
Serving the asset files
The recognizers load a Web Worker, a WebAssembly file, and model files relative to the script URL. If you
serve straight from node_modules or a CDN, this works automatically. If you use a bundler
like Vite, webpack, or esbuild, it will bundle the JavaScript but leave the data files behind. Copy
node_modules/millirec/dist/char-lite/ (and/or dist/char-cnn/) into your public folder
and pass assetBase:
const base = '/millirec/char-lite/' // e.g. in Vite: public/millirec/char-lite/
const training = await loadSet('digits', { assetBase: base })
const rec = await MillirecCharLite.create({ training, assetBase: base })
If your site uses a Content-Security-Policy, allow worker-src blob: and
script-src 'wasm-unsafe-eval' 'unsafe-eval' (the WebAssembly loader uses new Function).
Importing the package during SSR is safe; just wait until the browser to call create().
Plain script-tag builds are also in dist/, such as
https://cdn.jsdelivr.net/npm/millirec@0.2.0/dist/overlap/millirec-overlap.min.js. See the
npm README for the full API and TypeScript types.
Widgets: drawn reactions & ratings
Add a reaction bar or star rating where visitors draw a heart, checkmark, or star instead of clicking. Recognition happens in the browser, and the server tracks one vote per visitor without requiring accounts. If you turn on the public wall of visitor drawings, the server double-checks each drawing before showing it. Random scribbles or words still count as a vote, but they won't show up on your page.
Votes and drawings need a server. Hosted widgets are coming: we'll run the server and give you a widget to embed — join the waitlist to hear when they open. Embedding will look like this:
- Add the script tag once per page, then place a
<div>wherever you want a widget:
Use<script async src="https://…/embed/millirec-widget.js"></script> <div data-millirec="reactions" data-widget="YOUR-ID" data-target="this-page"></div> <div data-millirec="ratings" data-widget="YOUR-ID" data-target="this-page"></div>data-targetto identify each post or item so one widget can be reused across your site. You can also usereactions-countandrating-averageto display totals without a drawing pad. - Pick your reactions, symbols and colors in the widget editor, and open the moderation page to view, hide, or delete drawings and choose whether new drawings appear immediately or wait for your approval.
The server is MIT-licensed: if you'd rather run it yourself, the source and its README are available, but self-hosting isn't supported.
Drawing the same reaction twice toggles it off; drawing a new star rating updates the previous one. Votes are linked to a random token in the visitor's browser plus their IP hash, so each visitor gets one vote without needing an account.
Handwritten codes
Let people enter short 6-character codes by writing characters on top of each other in a single box. They're
handy for opening shared links or joining multiplayer rooms. The alphabet leaves out look-alike characters
(no O/0, l/1/I, or upper/lowercase pairs) to
prevent mix-ups. There's no millirec server involved: the box sends the visitor to your page for the code,
and your site decides what each code means.
<div data-millirec-code data-url="https://example.com/c/{code}"></div>
<script type="module">
import { scan } from 'millirec/code'
scan()
</script>
Add data-check="https://example.com/api/codes/{code}" to ask your server whether a code exists
before leaving (a typo then says "no code …" instead of landing on a missing page), or
data-codes="/codes.json" for a fixed list on a site with no backend. Your server makes new codes
with generateCode() from the same module, checks that it hasn't handed that one out yet, and tries
again if it has. The package README has every option.
Ready-made letter & digit recognizers
Downloadable, ready-to-use recognizers for capitals, lowercase letters, digits, or all 62 combined. Each set comes
in three flavors — accurate, fast, and small — and each zip includes the runtime, one or two
compact neural networks, a config.js, and a working demo page. Accuracy was tested on held-out
handwriting from hundreds of people (EMNIST: 7,800 capitals, 7,800 lowercase, 3,000 digits, 18,600 mixed).
| option | description | accuracy | per char | zip | |
|---|---|---|---|---|---|
| accurate | A tiny network handles easy drawings (80%); a larger 4-bit network steps in for close calls. Uses WebAssembly. | 98.5% | 0.16 ms | 45 KB | download · try |
| fast | Same two-stage setup, but only escalates the toughest 5% to a pruned larger network. Uses WebAssembly. | 97.9% | 0.05 ms | 53 KB | download · try |
| small | One tiny 4-bit network in plain JavaScript. No WebAssembly and no built-in drawing pad. | 96.8% | 0.14 ms | 13 KB | download · try |
| digits | Digits 0–9 (accurate two-stage pair). | 99.6% | 0.12 ms | 44 KB | download · try |
| digits-fast | Digits 0–9 (fast two-stage pair). | 99.5% | 0.04 ms | 49 KB | download · try |
| digits-small | Digits 0–9 (single tiny network, plain JavaScript). | 99.1% | 0.14 ms | 13 KB | download · try |
| lowercase | Lowercase a–z (accurate pair). Most mistakes are look-alike pairs like g/q and i/l/j. | 93.8% | 0.08 ms | 46 KB | download · try |
| lowercase-fast | Lowercase a–z (fast pair). | 91.9% | 0.04 ms | 51 KB | download · try |
| lowercase-small | Lowercase a–z (single tiny network, plain JavaScript). | 90.4% | 0.14 ms | 13 KB | download · try |
| all | Digits, capitals, and lowercase combined (accurate pair). Because characters like c/C, o/O/0, s/S, and l/I/1 look identical in isolation, exact accuracy is lower; the number in parentheses shows accuracy within the same character type (e.g. capitals). | 77.2% (96.6% in class) | 0.24 ms | 49 KB | download · try |
| all-fast | Digits, capitals, and lowercase combined (fast pair). | 74.0% (95.0% in class) | 0.07 ms | 54 KB | download · try |
| all-small | Digits, capitals, and lowercase combined (single tiny network, plain JavaScript). | 71.5% (94.3% in class) | 0.14 ms | 14 KB | download · try |
| templates | Stroke matcher with built-in templates — also covers punctuation, one set per zip. | 98–100% (same writer) | 0.2–0.5 ms | 33–40 KB | capitals · lowercase · digits |
Times are for a single recognition in headless Chrome on a laptop (stroke preprocessing adds about 0.05 ms). Accuracy is top-1 accuracy on the test set. Note that the template matcher was tested on the original writer's own held-out handwriting, not on general users.
How to embed
<script src="config.js"></script>
<script src="millirec-char-cnn.min.js"></script>
<script type="module">
const rec = await MillirecCharCnn.create()
rec.attach(document.querySelector('#pad')) // mount a drawing pad (not included in the small option)
document.querySelector('#pad').addEventListener('millirec:result', (e) => {
console.log(e.detail.results) // [{char, prob} x3], best first
})
const r = await rec.recognize(strokes) // pass strokes directly: [[{x,y},...], ...]
r.stage // 0 = tiny network answered, 1 = larger network answered
</script>
Serve the unzipped folder over HTTP — browsers won't load WebAssembly files from file://.
You can edit config.js to tweak behavior: remove the second stage to run only the tiny network,
or remove kernel to run in plain JavaScript without WebAssembly. The small option leaves
out the drawing pad to stay under 14 KB, so you capture strokes yourself and pass them to recognize()
(the included index.html shows how in about 12 lines of code).
The drawing pad
The pad mounted by attach() reads one character at a time. If you pause for two seconds and start
drawing again, the old strokes fade out and a fresh character begins. Scribbling over the pad clears it right away.
Both fire a millirec:clear event with an undo() helper, and an empty pad emits an empty
result list so your UI never gets stuck showing an old letter.
teach() (above) or the
custom builder.Custom symbols: the Character recognition builder
The Character recognition builder lets you create a self-contained recognizer for any symbols you want — checkmarks, rating icons, shorthand, or your own alphabet. Draw or upload a few examples of each symbol, test it live on the page, and download a zip (~80 KB plus your samples) to host anywhere. No API keys or backend required.
If you know whether your users will draw on screen or upload photos, pick drawn strokes only or
photos only to keep the bundle smaller (one worker instead of two). A stroke-trained set can also read
photos if you choose both. Photo mode can even read grids of cells or multiple symbols in one image, and
can tell c from C by height when given a baseline.
<script src="training.js"></script>
<script src="millirec-char.min.js"></script>
<script type="module">
const rec = await MillirecChar.create()
rec.attach(document.querySelector('#pad'))
await rec.recognize(strokes) // or a canvas / image / file
await rec.recognizeGrid({ canvas, rows: 4, cols: 10 })
</script>
Your progress is automatically saved in your browser so you can come back to it later. The emoji mode in Sudoku on digitizer.fun uses this exact approach to learn nine custom symbols right in the browser.
Handwriting input: one box
A handwritten text box where you don't need to move across the screen — you write each letter right on top of the previous one. The widget figures out which strokes belong to which letter, fades out finished letters, clears them once you start the next one, and suggests matching words as you go. Tap a suggestion to accept it, click done to commit the best guess, or click undo to step back a stroke.
<script async src="https://millirec.com/embed/millirec-overlap.js"></script>
<div data-millirec-overlap data-target="#answer"></div>
<input id="answer">
- Character sets: Uses capital letters by default. Set
data-set="lowercase|digits|punctuation|all", or passdata-alphabet="ABC0123"to allow only specific characters. - Word lists: Matches against prefixes of words in your list, favoring earlier (more common) entries.
Pass words inline with
data-words, link a hosted list from the handwriting input page (data-list="ol_…"), or point to a text file. If a digits or punctuation box has no matching words in the list, it switches to free mode, treating every character equally (ideal for numbers and codes). - Punctuation: Trailing
,,., and:work automatically; apostrophes are recognized when they appear in the word list.
On one writer's held-out drills, overlapping letters achieved 96% word accuracy on capitals, 99% on lowercase, and 99% on random digit strings. Visit the handwriting input page for all options and the JavaScript API, or see docs/overlap.md for full benchmarks.
Games
You can try millirec in real games — Sudoku, crosswords, Handle, hangman, cryptograms, chess, quizzes, and more — over on digitizer.fun. Everything you write in those games is recognized locally in your browser. Check out Examples to see which recognizer each game uses and how to wire up the same thing yourself.
Privacy & data
Here is the short version. See the privacy page for the full details and the terms of use for licensing and usage rules.
- Do the character recognizers or games send my handwriting anywhere?
- No. They are static files that run entirely in your browser. Game progress, high scores, custom puzzles, and emoji samples stay in your browser's local storage.
- What does the builder save?
- Your training samples stay in your browser's local storage. Nothing is sent until you save: saving a library stores its definition on our server and gives you a link to resume it later.
- What does the handwriting input send?
- Nothing while you write. If you use a hosted word list, the widget fetches that list by ID when the page loads, and saving a list from the handwriting input page stores the words you gave it.
- What do the reaction and rating widgets send?
- Just the vote (which reaction or star rating) for that page. Recognition still happens in your browser. Strokes are only sent to the widgets server if the public wall of visitor drawings is on, so the server can verify and render the image. Votes use a random browser token plus an IP hash to limit votes to one per visitor without requiring accounts. The cards on this site's home page are live: they use our own widgets server, which holds every drawing for our approval before it goes on the wall (see the privacy page).
Supported devices
- Best experience: A tablet with a stylus or a phone with your finger, in Safari or Chrome. Every page adapts to mobile screens and supports touch, stylus, and mouse input.
- Desktop: A mouse or trackpad works fine too — recognition depends on the shape you draw, not the input device.
- All modern browsers are supported. The WebAssembly options require WebAssembly, which every modern browser includes.
Troubleshooting
- The demo page doesn't respond when I draw.
- Make sure you're opening it over HTTP (for example, run
python3 -m http.serverin the folder) instead of double-clicking the HTML file (file://). Browsers block WebAssembly files overfile://. The small option doesn't use WebAssembly, so it works from a local file. - It keeps misreading one of my letters.
- Try drawing a bit larger and near the center of the box, one letter at a time. The most common mix-ups are
the same ones humans make: V/U, O/D, C/L, and E/F. Every recognizer returns its top three guesses, so your
app can let users tap the second choice. If a specific letter doesn't match your handwriting style, you can
adapt it with
personalize()or train your own set in the builder. - My widget isn't showing vote counts.
- Check that the script tag points to the same server where you created the widget and that
data-widgetmatches its ID. Counts appear once the first vote is submitted. - My saved builder library disappeared.
- Builder projects are stored in your browser's site data. Clearing site data or using private browsing will remove them. If you saved a link to the server, you can still reopen it there.
How it works (for the curious)
Ready-made letters & digits: Each recognizer is a two-stage cascade of small convolutional neural networks. First, a tiny 24×24 network (~4–7 KB of weights) makes a fast guess. Only when the top two guesses are close does it hand the drawing to a larger 32×32 network (trained with 4-bit quantization-aware training so it stays tiny without losing accuracy). Both run in a small SIMD WebAssembly kernel or plain JavaScript.
Custom symbols: Uses a point-cloud template matcher. Each drawing is resampled into oriented points (position + stroke direction) and matched against your saved examples. Because it only needs a few examples per symbol, you can train new shapes right in the browser.
One-box handwriting input: Since strokes arrive in order, each letter is a contiguous group of strokes. After every stroke, a dynamic programming pass tests possible groupings against full and partial letter templates, weighted by your word list. Once a letter clearly beats the alternatives, it gets cleared to make room, while a small beam of top prefixes stays alive so later letters can still fix an earlier mistake.
Game probabilities: Games like Handle and Hangman use the recognizer's top three guesses (softened with a temperature parameter) instead of forcing a single rigid choice, so an ambiguous letter splits its weight. Quizzes match guesses to answers using an edit distance weighted by real confusion rates from the test set.
Every option offered here was measured on held-out writing before it was offered. If you want to dig into the benchmarks and experiments — including what worked and what didn't — see char-lite.md and overlap.md.