# Pretext

> JavaScript and TypeScript library for measuring and laying out text

Worth exploring: Prepare text measurements once, then recalculate lines when the width changes.

Why it works: Reusing prepared measurements lets layout run again without remeasuring the same text and font.

Watch out: Prepare again when text, font, or options change to avoid using stale measurements.

- Category: UI components (`components`)
- Tags: `free`, `open-source`, `typography`
- Official: https://github.com/chenglou/pretext
- Wunderlust: https://wunderlust.xyz/r/pretext
- Image: https://wunderlust.xyz/media/pretext-poster.jpg
- Video preview: https://wunderlust.xyz/media/pretext.webm
- Added: 2026-11-22

## What it is

It measures paragraphs without querying DOM layout and can render lines in DOM, Canvas, or SVG. Preparation caches measurements for layout calculations.

## What it’s for

For chat developers who need to calculate message height before rendering.

## Benefits

- Paragraph measurement without DOM layout
- Manual line layout

## Similar on Wunderlust

- [prompt-kit](https://wunderlust.xyz/r/prompt-kit.md): AI interface components installed with the shadcn CLI
- [3dicons](https://wunderlust.xyz/r/3dicons.md): 3D icon library with a color and angle editor
- [motion-primitives](https://wunderlust.xyz/r/motion-primitives.md): Open source animated component kit to copy and paste
- [Colour Contrast Checker](https://wunderlust.xyz/r/colour-contrast-checker.md): Contrast checker for background and text, with AA and AAA grades
- [daisyUI](https://wunderlust.xyz/r/daisyui.md): Tailwind CSS plugin with ready-made components and themes, in pure CSS
- [React Bits](https://wunderlust.xyz/r/react-bits.md): A library of animated React components: text, backgrounds and microinteractions
