The TypeScript library 'Pretext,' which solves the problem of calculating the height of multi-line text without DOM manipulation, is gaining attention.

The TypeScript library ' Pretext ,' released in March 2026, quickly gained popularity, with posts spreading rapidly on social media platforms like X (formerly Twitter). Pretext is described as a tool that calculates the number of lines and height of text on the web, but what exactly makes it so noteworthy?
chenglou/pretext: Fast, accurate & comprehensive text measurement & layout
This was posted by the creator, Cheng Lou, himself on March 28, 2026.
'A fast, accurate, and comprehensive text measurement algorithm written in pure TypeScript.' 'Can be used for the layout of the entire web page without using CSS, avoiding DOM measurement and reflow.'
My dear front-end developers (and anyone who's interested in the future of interfaces):
— Cheng Lou (@_chenglou) March 28, 2026
I have crawled through depths of hell to bring you, for the foreseeable years, one of the more important foundational pieces of UI engineering (if not in implementation then certainly at… pic.twitter.com/BKnwCDIp75
You can see the demo created by Cheng Lou at the following website.
Pretext Demos
https://chenglou.me/pretext/

◆Various reactions on X
The author's post has been met with a variety of reactions.
'Combining Apple's Vision Model with Expo Agent'
ok but now combine it with Apple vision models and Expo Agent https://t.co/TujtWDJrPW pic.twitter.com/CQjDQMmL4y
— Evan Bacon 🥓 (@Baconbrix) March 30, 2026
'What if you had to keep your phone perfectly horizontal to read it?'
Had to play with pretext today. What if you had to keep your phone perfectly straight to read anything? https://t.co/R2r9sYTKjD pic.twitter.com/4jeWeYmpCv
— Marius Hauken (@mhauken) March 29, 2026
Some people are beginning to explore ways to use Pretext.
'A resume builder that ensures everything fits on one page, with real-time rendering.'
Okay I think I finally found a good use for @_chenglou 's Pretext.
— Vlad (@VladArtym) March 29, 2026
A resume builder that always fits on one page
with realtime rendering. https://t.co/MZrPtiS9v0 pic.twitter.com/Y7dvXpAe5Q
'This little glowing dragon is delighted with Pretext.'
This little illuminated dragon is very happy about Pretext. He's too busy having fun to care about people's 'hot takes' on how 'it's not that special.'
— River Marchand (@Riyvir) March 29, 2026
(This little dragon also only works on desktop right now but maybe I'll do mobile later) https://t.co/k9FH6p1G0T https://t.co/8sxaxlssJ6 pic.twitter.com/wNhFk1ZBwM
'We transformed basic static pages into something that people actually want to interact with.'
Messed around with pretext and literally couldn't stop. Turned my basic static page into something you actually wanna touch.
— Vadim (@ukint_vs) March 29, 2026
Particle text, scroll trails, scramble transitions.
Pure canvas, 60fps, smooth af. https://t.co/vRgk9ctUbF https://t.co/bXvDdg26Ah pic.twitter.com/h5UVtsdJzs
'I know you're probably tired of seeing nothing but typography in the pretext demos!'
I know you're all getting mighty tired of seeing typography on your timeline today!
— Robin (@solarise_webdev) March 29, 2026
But here's a pretext.js demo that (hopefully) isn't a crime against justification and indentation. pic.twitter.com/VwzcMcgrWg
'It works well whether embedded directly into the DOM or natively within the canvas.'
Yep this works wildly well in @threejs - both via direct DOM embedding and natively within the canvas. Nice. pic.twitter.com/BALqbW2wQX
— Sam B (@SamJB1234) March 29, 2026
On the other hand, some calmly point out that it's nothing more than existing technology.
'That problem was solved 30 years ago and is already present in the word processor's algorithm.'
The problem was solved 30 years ago; it's been there in the word processor algorithms. We can look ahead if things are simple. But what if the paragraph is composed of multiple fonts and sizes? Then we need something like a DOM structure. This little cute trick can be applied to…
— Kevin Lee (@kevinleeus) March 29, 2026
'This has been easy to do for a long time; that's why the canvas API exists.'
I like Cheng, he's extremely smart guy. But the amount of hype this got… I'm sorry you could've done that very easily all this time.
— Dmitriy Kovalenko (@neogoose_btw) March 28, 2026
There is even a canvas api for that existing for years. Or you could've gone even further and parse ttfs to get the underlying font data and… https://t.co/YLw4YzNWrZ
'This is just a wrapper around measureText(), it's not a new paradigm.'
So many slop influences hailing this as a revolution when it's just a wrapper around the canvas element's existing measureText() function. This is not some new paradigm. Canvas-based text measurement is many years old! https://t.co/CnEN0QiKPD
— Domenic Denicola (@domenic) March 29, 2026
'Apple was doing this with the iPad 15 years ago.'
apple did this on an iPad 15 years ago btw. https://t.co/oVoCCKI0Fc pic.twitter.com/zpNlHWH8Di
— sui ☄️ (@birdabo) March 29, 2026
Some people point out that the evaluation might differ between designers and engineers.
'The front-end developers were like, 'Check out this fun demo,' while the engineers were like, 'You can't read the text, and this was something we could do 15 years ago.''
so funny seeing the divide between designers and engineers reacting to @_chenglou 's pretext library. frontend folk are like; 'look at this whimsical demo I made full of play', while engineers are like 'the text is unreadable, and we could already do this 15 years ago'
— maarten (@0xmrtn) March 29, 2026
'I've never seen such a huge divide between people who can see possibilities beyond just the ball bouncing and those who can't!'
Actually I haven't seen such a divide!
— Cheng Lou (@_chenglou) March 29, 2026
The divide has been more along the axis of folks who see possibilities beyond bouncing balls, and folks who don't (either due to lack of domain experience, or too much exp that made them overfit. Overfitting can cause cynicism during shifts) https://t.co/1BRRgr74dM
◆Discussion on Hacker News
Pretext is also a hot topic on the social news site Hacker News.
Pretext: TypeScript library for multiline text measurement and layout | Hacker News
https://news.ycombinator.com/item?id=47556290
The main features of Pretext can be summarized as follows:
• Efficient text measurement : Calculating the height of text before rendering reduces rendering costs, especially when dealing with large amounts of text.
• High performance : Performance is improved by pre-calculating and caching the width and height of individual segments such as words.
• Custom layout algorithm : Implements the browser's text wrapping algorithm with custom code to support various character types and wrapping methods, including hyphenation, emojis, and Chinese.
- Addressing browser differences : Tests were conducted using actual browsers to address subtle differences in rendering algorithms between browsers such as Safari.
• Anticipated use cases : Intended for use in situations where text layouts change frequently, such as data table virtualization or dynamic width changes in desktop applications.
The points being discussed are as follows:
·performance
There were performance concerns raised, such as the fact that Pretext takes approximately 2200ms to measure ASCII text, while a simpler library like uWrap can complete the same task in 80ms. At the time of writing, there were multiple pull requests on Pretext's GitHub repository aimed at performance improvements, and further improvements are expected. Some suggested that this might be a drawback of AI coding, but others countered that it was simply a problem due to the scope of the libraries used. There were also concerns that using the Canvas measureText API might be slower compared to the native rendering text width API.
Functions and scope
uWrap focuses solely on Latin characters and handles only specific CSS properties, while Pretext aims to support a wider range of typography and text layouts (normal and pre-wrap). However, some have pointed out that demos of Pretext have issues displaying basic Latin characters. Additionally, some argue that Pretext simply renders and measures text on a canvas and does not bypass the browser's native layout system.
• The role of AI
Pretext was likely developed using AI, and it's estimated that its implementation would have been much more difficult and laborious without it. The specific role of the AI is thought to have been to perform measurement and iteration based on learning from actual browser rendering results, helping to absorb differences between browsers.
Expectations for standard browser features
Many believe that text layout measurement functionality should be provided as a standard browser API (Web API) in the future. As of the time of writing, while APIs such as CSS Houdini 's FontMetrics API have been proposed, it has been pointed out that browser vendors are slow to respond. Fundamentally, questions have been raised about why browsers do not implement basic functions such as 'calculating the number of lines and height of text.'
◆Summary
While Pretext garnered attention for its visually innovative demo, it can also be said that it was a project that raised important questions about 'the complexity of browser text layouts,' 'the need for native APIs to solve text layout problems,' and 'the impact of AI on development.'
Related Posts:







