Pretext
FreePretext measures and lays out text in JavaScript without forcing browser reflow, ideal for fast, framework‑agnostic text rendering.
Pretext is a plain JavaScript/TypeScript text measurement and layout engine by Cheng Lou. It avoids the usual need to render text in the DOM just to know its size, so you can calculate line breaks and heights without triggering synchronous browser reflow.
The library uses a two-step approach. prepare() measures glyphs via Canvas and Intl.Segmenter, then layout() does the maths to determine line breaks and box heights. That second step is extremely quick, reported at about 0.0002ms, and the project claims it can be roughly 600× faster than measuring via the DOM.
There’s an interactive playground and examples on the site that show virtual scrolling, chat bubbles, multilingual content and animated accordions. Pretext supports more than a dozen writing systems, including CJK, Arabic, Hebrew and Thai, and handles mixed bidirectional text.
- MIT licence, around 15KB
- Framework-agnostic: works with React, Vue, Svelte or vanilla JS
- Used at Midjourney for real-time AI text streaming
Tool Overview
- Category
- Web & Design
- Pricing
- Free
- Official Website
- pretextjs.dev
- Added
- May 3, 2026