---
title: "Number Text"
description: "Shows a formatted number inside a line of text: a short count, money, a percent, a unit, or bytes. When the text is short, the full value shows in a tooltip."
url: https://gelatinui.com/components/number-text
markdown_url: https://gelatinui.com/components/number-text.md
access: free
install: "npx shadcn@latest add @gelatin-ui/number-text"
registry_item: https://gelatinui.com/r/number-text.json
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Number Text

> Shows a formatted number inside a line of text: a short count, money, a percent, a unit, or bytes. When the text is short, the full value shows in a tooltip.

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

## When to use it

Best for: A formatted number in a line of text: it takes the font, size, and color around it.

- Use `kind` for the format: `compact`, `currency`, `percent`, `bytes`, and others.
- Pass `end` for a range.
- Use `NumberTextEmpty` for a cell with no number.

## When not to use it

- For a price with its period, use a [Price](https://gelatinui.com/components/price.md).

## Notes for agents

- A shortened value is focusable and shows the full value in a Tooltip. A full value is plain text.
- A negative value writes the true minus U+2212.
- It has no size prop: set the size on the parent.

## Anatomy

```text
NumberText
└─ NumberTextEmpty (0..n)
```

## API reference

### NumberText

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `currency` | `string` |  | The ISO 4217 code of `currency` and `compactCurrency`. Default `"USD"`. |
| `unit` | `string` |  | The `Intl` unit of the value for `unit` (`"millisecond"`, `"meter"`, `"celsius"`). Required for `unit`. |
| `unitDisplay` | `"long" \| "narrow" \| "short"` |  | The unit text: `"short"` (default, `1.53 sec`, `1.8 MB`), `"narrow"` (`1.53s`), or `"long"` (`1.53 seconds`, `1.8 megabytes`). |
| `compactFrom` | `number` |  | `compact` and `compactCurrency` write the full value below this size. Default 10,000. |
| `signDisplay` | `union` |  | The sign rule of `Intl` (`"auto"`, `"always"`, `"exceptZero"`, `"negative"`, `"never"`). Default `"auto"`; `change` defaults to `"exceptZero"`, so 0 has no sign. |
| `minorDigits` | `"always" \| "auto"` |  | The minor digits (cents) of `currency` and of `compactCurrency` below `compactFrom`: `"auto"` (default) drops them from a whole value (`$49`, `$49.50`); `"always"` writes them on every value (`$49.00`), for a receipt, a price list, or a column of amounts that must line up. The currency sets the count (2 for USD, 0 for JPY: `¥12,000` in both modes). |
| `value` | `number \| null` |  | The number, or the start of a range. `null`, `undefined`, and `NaN` show the empty text. |
| `end` | `number \| null` |  | The end of a range: "$10–20K", "1st–3rd", "1.2–4.8 GB" (`formatRange`, so the locale picks the dash and writes the shared parts once). A range never rolls. |
| `kind` | `NumberKind` | "number" | The kind of text, the names of `createNumberFormat`: `number` (default), `compact` (`184K`), `currency`, `compactCurrency` (`$48.2K`), `percent` (a ratio: `0.024` is `2.4%`), `change` (a signed ratio: `+12.4%`), `unit` (with `unit`; it climbs a ladder: 1532 ms is `1.53 sec`), `bytes` (`720 GB`), `ordinal` (`1st`, `22nd` in English). |
| `format` | `NumberFormatOptions` |  | Raw `Intl.NumberFormat` options in place of `kind`, for a value that a page already formats with `Intl` (`{ style: "unit", unit: "fahrenheit" }`). Nothing is cut, so there is no Tooltip. |
| `tooltip` | `boolean` | true | When the text is shorter than the value (`184K`, `1.53 sec`): a dotted underline, a Tooltip with the full value on hover, focus, and press. Default `true`. `false` shows the short text only. |
| `animated` | `boolean` | false | Rolls the digits on a change (the Rolling Number). Default `false`: the text swaps. |
| `locale` | `string` |  | The BCP 47 locale. Default: the `DisplayLocaleProvider` locale, else `"en-US"`. |
| `children` | `ReactNode` |  | A `NumberTextEmpty` part: the words of no value. With a value, they are not drawn. |

### NumberTextEmpty

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `data-slot` | `string` |  | The `data-slot` of the root: the item's own slot (`"time-ago"`). Default `"empty-value"`. |

Also takes every prop of Base UI `UseRender`: https://base-ui.com/react/components/use-render

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| NumberText | `number-text` |  |  |  |
| NumberTextEmpty | `number-text-empty` |  |  |  |

## Usage

Pass the value and its kind. Put a `NumberTextEmpty` inside for a metric that has no data yet.

```tsx title="october-stats.tsx"
import { NumberText, NumberTextEmpty } from "@/components/stats/number-text";

const STATS: { label: string; value: number | null }[] = [
  { label: "Visitors", value: 184_312 },
  { label: "Signups", value: 4_218 },
  { label: "Referrals", value: null },
];

export function OctoberStats() {
  return (
    <dl className="grid grid-cols-3 gap-4">
      {STATS.map((stat) => {
        return (
          <div key={stat.label}>
            <dt className="text-sm text-muted-foreground">{stat.label}</dt>
            <dd className="text-2xl font-semibold">
              <NumberText value={stat.value} kind="compact">
                <NumberTextEmpty>No data</NumberTextEmpty>
              </NumberText>
            </dd>
          </div>
        );
      })}
    </dl>
  );
}
```

## 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/number-text
```

It adds 36 registry items: 33 files, 5796 lines, and the npm packages `@base-ui/react`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Full Value](https://gelatinui.com/components/full-value.md)
- [Rolling Number](https://gelatinui.com/components/rolling-number.md)

## 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

- [Price](https://gelatinui.com/components/price.md)
- [Table](https://gelatinui.com/components/table.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Tab | Moves to a shortened value and shows the full value in a Tooltip. |

## Accessibility

It renders a `data` element, and its `value` attribute keeps the raw number.

A range keeps both ends as `start/end`.

## Motion

| Part | Motion |
| --- | --- |
| Value | none · with `animated`, the digits roll on a change |
