---
title: "Text Fit"
description: "Each line of a heading scales to fill the full width of its box, and stays fitted when the box resizes."
url: https://gelatinui.com/components/text-fit
markdown_url: https://gelatinui.com/components/text-fit.md
access: free
install: "npx shadcn@latest add @gelatin-ui/text-fit"
registry_item: https://gelatinui.com/r/text-fit.json
version: "2026-11-15"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Text Fit

> Each line of a heading scales to fill the full width of its box, and stays fitted when the box resizes.

Page: https://gelatinui.com/components/text-fit

## When to use it

Best for: A poster heading where each line scales to fill the width of its box.

- Put each line in its own Fit Text Line part.
- Use `maxSize` to stop a short line from growing too large.

## When not to use it

- For a heading that enters line by line, use [Text Split Headline](https://gelatinui.com/components/text-split-headline.md).
- For text on a curve, use [Text Circular](https://gelatinui.com/components/text-circular.md).

## Notes for agents

- Each line keeps its own size, so short lines are larger.
- It sizes again with smooth motion when its box resizes.

## Anatomy

```text
TextFit
└─ TextFitLine (0..n)
```

## API reference

### TextFit

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `locale` | `string` |  | The BCP 47 locale for the letter and word split (`Intl.Segmenter`). Default: the `DisplayLocaleProvider` locale, else `"en-US"`. |
| `children` | `ReactNode` |  | The lines: `TextFitLine` parts, or a string with one line per `\n`. |
| `maxSize` | `number` | Number.POSITIVE_INFINITY | The largest font size of a line, in px, so a short word does not grow without end. |

### TextFitLine

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `string` |  | The text of the line. It never wraps. |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| TextFit | `text-fit` |  |  |  |
| TextFitLine | `text-fit-line` |  |  |  |

## Usage

Put each line in a Fit Text Line part.

```tsx title="hero-title.tsx"
import { TextFit, TextFitLine } from "@/components/text/text-fit";

export function HeroTitle() {
  return (
    <section className="flex flex-col gap-4 py-16">
      <h1 className="w-md max-w-full font-semibold tracking-tight">
        <TextFit maxSize={160}>
          <TextFitLine>Design</TextFitLine>
          <TextFitLine>systems that</TextFitLine>
          <TextFitLine>feel alive</TextFitLine>
        </TextFit>
      </h1>
      <p className="text-muted-foreground">Each line fills the width of the column.</p>
    </section>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/text-fit
```

It adds 18 registry items: 17 files, 3416 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `clsx`, `motion`, `tailwind-merge`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Text Split Headline](https://gelatinui.com/components/text-split-headline.md)
- [Text Circular](https://gelatinui.com/components/text-circular.md)
- [Text Media](https://gelatinui.com/components/text-media.md)

## Motion

| Part | Motion |
| --- | --- |
| Resize | glide · each line scales to its new size when the box resizes |
