What should designers know about Pretext?
Pretext measures every line of text instantly, without asking the browser. No more guessing container heights, broken masonry, or bloated chat bubbles. Here's what it means for designers.
Every time a browser displays text, it has to figure out how tall each block will be. Where do lines break? How tall is each line? How much space does the whole paragraph take? This calculation (called a reflow) has always required asking the browser itself, which is slow and can freeze the page.
Think of it like this: Imagine you’re laying out a magazine, but every time you want to know how tall an article is, you have to print it, measure it with a ruler, then re-layout the page. That’s essentially what browsers have been doing, thousands of times per second on complex pages.
Pretext solves this by computing text layout in pure JavaScript, no printing required. It can measure 100,000 text blocks in under 50ms, enabling layouts that were previously impossible or impractical.
Demo 1: Shrinkwrapped chat bubbles
This is the clearest win for product designers. CSS has no way to make a chat bubble hug its content precisely — a multiline message gets a bubble as wide as its max-width, leaving the shorter lines floating in empty space. Drag the slider to see the difference.
Both sides wrap to the exact same number of lines. The only difference is width. Pretext binary-searches for the minimum container width that produces the same line count — no DOM reads, no reflow, just arithmetic.
Demo 2: Masonry grids that actually work
Masonry layouts (Pinterest-style) have been a CSS holy grail for years. The problem: to position a card without a gap, you must know the height of every card above it. Without text measurement, developers guess, and visible gaps appear when guesses are wrong.
Pretext measures all items in one pass, then positions them perfectly at 120fps, even as you resize the window. No layout thrashing. No red bars in Chrome DevTools.
Demo 3: Dynamic truncation with precision
Truncating text with CSS ellipsis is blunt. You set a fixed height and cut. With Pretext, you can truncate based on actual line count at any container width, and add a “read more” exactly where the real break is.
Already shipping in Cursor
This isn’t theoretical. Cursor, the AI code editor, already uses Pretext to truncate file paths in the middle of their diff panel. The filename is always readable, no matter how narrow the panel gets.
Before Pretext, the only options were: truncate from the end (losing the filename) or accept overflow. Now there’s a third option: measure precisely, truncate smartly.
What this unlocks for designers
For years, the split between “beautiful but slow” and “fast but boxy” has been a real tradeoff. Editorial layouts with flowing text, magazine-style columns, perfectly-hugged labels, all of these required expensive DOM measurements that made them impractical at scale.
Text height = guess or reflow. Dense UIs required fixed heights. Dynamic content caused jank. AI chat interfaces with variable-length outputs were especially painful.
Text height = computed in userland. Virtualize 100k cards. Shrinkwrap any element. Lay out entire pages without touching the DOM. AI UIs can resize at 120fps.
The AI connection
This matters especially now. AI-generated content is inherently variable; answers can be two lines or twenty. Chat interfaces, AI writing tools, and generative dashboards all suffer when containers can’t predict content height. Pretext makes variable-length AI outputs as easy to lay out as static text.
Designer takeaway: You can now spec layouts that hug their content, scroll virtual lists of thousands of AI responses, and build magazine-quality compositions, without handing engineers an unsolvable performance problem. The constraint that made you choose safe layouts is gone.
Based on Cheng Lou’s Pretext library, a fast, accurate, comprehensive text measurement algorithm in pure TypeScript. chenglou.me/pretext →