---
title: "File Size"
description: "Shows a number of bytes the way people read it, such as 1.8 MB or 1.2 of 4.8 GB. The exact bytes can show in a tooltip."
url: https://gelatinui.com/components/file-size
markdown_url: https://gelatinui.com/components/file-size.md
access: free
install: "npx shadcn@latest add @gelatin-ui/file-size"
registry_item: https://gelatinui.com/r/file-size.json
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# File Size

> Shows a number of bytes the way people read it, such as 1.8 MB or 1.2 of 4.8 GB. The exact bytes can show in a tooltip.

Page: https://gelatinui.com/components/file-size

## When to use it

Best for: A number of bytes as people read it, alone or as used of total.

- Pass `bytes`, and `total` for used of total.
- Use `base={1024}` for RAM or a Windows size ("1.8 MiB").
- Use `tooltip` when people need the exact bytes.

## When not to use it

- For a bar that shows how full a quota is, use a [Meter](https://gelatinui.com/components/meter.md).
- For other numbers, use [Number Text](https://gelatinui.com/components/number-text.md).

## Notes for agents

- Steps of 1000 by default. One decimal under 10 (1.8 MB), none above (18 MB).
- A negative size or `NaN` shows the empty text and warns in development. `null` shows the empty text.
- A `null` total shows the used size alone.
- The word "of" comes from `labels.of`: pass your language.

## Anatomy

```text
FileSize
└─ FileSizeEmpty (0..n)
```

## API reference

### FileSize

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `bytes` | `number \| null` |  | The size in bytes. `null`, `undefined`, `NaN`, and a negative size show the empty text. |
| `total` | `number \| null` |  | The whole, for "used of total": storage, a quota, an upload. "1.2 of 4.8 GB" when both round to one unit, else "12 MB of 2 GB". `null` (an unknown or unlimited total) shows the used size alone. |
| `base` | `1000 \| 1024` |  | The step: `1000` (default, SI: kB, MB, GB) or `1024` (IEC: KiB, MiB, GiB), for RAM and Windows. |
| `length` | `"long" \| "short"` | "short" | The unit words: `short` (default, "1.8 MB") or `long` ("1.8 megabytes"). |
| `tooltip` | `boolean` | false | A Tooltip with the exact bytes ("2,401,872 bytes") on hover, focus, and tap, a dotted underline, and one tab stop. Default `false`: the short text. |
| `locale` | `string` |  | The BCP 47 locale. Default: the `DisplayLocaleProvider` locale, else `"en-US"`. |
| `labels` | `Partial<{ of: string; }>` |  | The words (`FILE_SIZE_LABELS`). Keep the object stable. |
| `children` | `ReactNode` |  | A `FileSizeEmpty` part: the words of no value. With a value, they are not drawn. |

### FileSizeEmpty

| 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 |
| --- | --- | --- | --- | --- |
| FileSize | `file-size` |  |  |  |
| FileSizeEmpty | `file-size-empty` |  |  |  |

## Usage

Pass the size in bytes. Put a `FileSizeEmpty` inside for a file whose size is not known yet.

```tsx title="attachments.tsx"
import { FileSize, FileSizeEmpty } from "@/components/ui/file-size";

const FILES: { name: string; bytes: number | null }[] = [
  { name: "q3-report.pdf", bytes: 2_401_872 },
  { name: "site-photos.zip", bytes: 184_320_000 },
  { name: "contract-draft.docx", bytes: null },
];

export function Attachments() {
  return (
    <ul className="flex w-64 flex-col gap-1 text-sm">
      {FILES.map((file) => {
        return (
          <li key={file.name} className="flex justify-between gap-4">
            <span className="truncate">{file.name}</span>
            <FileSize bytes={file.bytes} className="text-muted-foreground">
              <FileSizeEmpty>Uploading</FileSizeEmpty>
            </FileSize>
          </li>
        );
      })}
    </ul>
  );
}
```

## 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/file-size
```

It adds 26 registry items: 23 files, 3796 lines, and the npm packages `@base-ui/react`, `clsx`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Full Value](https://gelatinui.com/components/full-value.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

- [Number Text](https://gelatinui.com/components/number-text.md)
- [Meter](https://gelatinui.com/components/meter.md)
- [Measurement](https://gelatinui.com/components/measurement.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Tab | With `tooltip`, moves to the size and shows the exact bytes in a Tooltip. |

## Accessibility

It renders a `data` element, and its `value` attribute keeps the bytes (`used/total` for used of total).

A narrow no-break space sits before the unit, so the size never wraps.
