A tokenizer running entirely in your browser that can load tokenizer.json and tokenizer_config.json from any repository on HuggingFace. You can use it to count tokens and compare how different large language model vocabularies work. It's also useful for debugging prompt templates.
- No server required: Client-side tokenization with Hugging Face's Rust tokenizers compiled to WebAssembly
- Compare models: Load multiple tokenizers simultaneously to see how different models tokenize the same text
- Visual token display: Each token is displayed with its original text and token ID using colour-coded backgrounds
- Share configurations: Generate shareable URLs with your text and model selection
- Persistent settings: Model lists are saved in localStorage across browser sessions, and the text survives a reload until the tab is closed
- HuggingFace integration: Load any tokenizer directly from HuggingFace Hub
- Dark mode support: Automatic theme detection with appropriate colour schemes
- Offline capability: Once models are loaded, tokenization works completely offline
Copy model names from HuggingFace (e.g., from the title of model pages like "microsoft/Phi-3-mini-4k-instruct") and paste into the "Add from Hugging Face" field. Press Enter or click "Add tokenizer".
Click the bin button on any model card. You'll get a confirmation prompt and cannot delete the last model.
Click "Copy share link" to copy a URL containing your current text and model selection. Share this URL with others to let them see the same tokenization. The text is compressed into the fragment (#text=...), which browsers never send to the server, so even long texts make a working link.
You can also write links to specific configurations by hand using URL parameters:
?text=your%20text&models=model1,model2,model3
- Each word/subword piece shows the original text above and the token number below
- Different background colours help distinguish adjacent tokens (cycling through 10 colours)
- Newlines are preserved in the display, and tokens containing a line break show a ↵ symbol
- The token count overview compares models at a glance; click a model name to jump to its card, and "All models" to come back
- Tokens show their exact text (
" ."keeps its space). A per-model "Clean up spaces before punctuation" switch shows the text as the model's decoder would tidy it, next to that model's own default. It never changes the IDs or the count
- Rust tokenizers in WebAssembly: The same tokenization code as Hugging Face's Python and Rust libraries, built from the wasm binding in huggingface/tokenizers#2450
- Web Workers: Each tokenizer loads and runs in its own worker, in parallel and off the main thread. The WebAssembly module is compiled once and shared
- Progressive rendering: Models appear and update individually as they finish loading, providing immediate feedback
- Debounced input processing: Text changes are debounced by 300ms to prevent excessive re-tokenization during typing
- Ruby annotations: Tokens are displayed using HTML
<ruby>elements with text above and token numbers below - Space preservation: Automatically detects and removes tokenizer space-stripping to accurately show whitespace tokens
- Caching: Tokenizer files are kept with the Cache API, so reloading doesn't download them again. Deleting a model stops its worker
The project consists of these files:
index.html- Main HTML structure and UItokenizer.css- Styling including dark mode supporttokenizer.js- UI logic, and one worker per modeltokenizer-worker.js- Fetches a model's tokenizer files and tokenizes in a Web Workertokenizers_wasm.jsandtokenizers_wasm_bg.wasm- The vendored tokenizers build
Serve the folder over HTTP (e.g. python3 -m http.server) and open index.html. Module workers and WebAssembly don't load from file://. No build step required.
The browser tests use Playwright. They stand in for the Hub with a tiny tokenizer that each test releases in the order it chooses (tests/hub.js), so they run offline, apart from tests/huggingface.spec.js, which loads a real tokenizer:
npm install
npx playwright install chromium firefox webkit
npm test- tokenizers, compiled to WebAssembly and vendored.
scripts/tokenizers-wasm/build.shrebuilds it from a pinned commit of daaain/tokenizers@claude/wasm-integration: the upstream wasm binding (huggingface/tokenizers#2450) plus fixes still in review upstream.scripts/tokenizers-wasm/parity.mjschecks a build against transformers.js. Once the binding is released, this can switch to the published package
Works in all modern browsers that support:
- ES6 modules, including module Web Workers
- WebAssembly
- Async/await
- LocalStorage
- Clipboard API (for share functionality)
If you're wondering why there are so many models under Xenova, it's because they work for HuggingFace and re-upload just the tokenizers, so it's possible to load them without agreeing to model licences.
Contributions are welcome! Please feel free to submit a Pull Request.
See LICENCE file for details.
Try it at: danieldemmel.me/tokenizer