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

https://github.com/chenglou/pretext

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.'



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'



'What if you had to keep your phone perfectly horizontal to read it?'



Some people are beginning to explore ways to use Pretext.

'A resume builder that ensures everything fits on one page, with real-time rendering.'



'This little glowing dragon is delighted with Pretext.'



'We transformed basic static pages into something that people actually want to interact with.'



'I know you're probably tired of seeing nothing but typography in the pretext demos!'



'It works well whether embedded directly into the DOM or natively within the canvas.'



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.'



'This has been easy to do for a long time; that's why the canvas API exists.'



'This is just a wrapper around measureText(), it's not a new paradigm.'



'Apple was doing this with the iPad 15 years ago.'



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.''



'I've never seen such a huge divide between people who can see possibilities beyond just the ball bouncing and those who can't!'



◆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.'

in AI,   Software, Posted by log1c_sh