Usage
FileSize formats a number of bytes into a human-readable file size (1.45 kB, 4.8 GB).
It renders text without a wrapping element:
| File | Size |
|---|---|
| avatar.png | 15.36 kB |
| report.pdf | 1.45 MB |
| backup.zip | 4.8 GB |
SI (decimal) and binary units
By default, FileSize scales by 1000 and displays kB, MB, GB.
Set unitSystem="binary" to scale by 1024 and display KiB, MiB, GiB:
| Bytes | Decimal (SI) | Binary |
|---|---|---|
| 1450 | 1.45 kB | 1.42 KiB |
| 1048576 | 1.05 MB | 1 MiB |
| 1500000000 | 1.5 GB | 1.4 GiB |
Bytes and bits
Set unit="bit" to measure the value in bits instead of bytes, for example to display network speed:
Storage: 8 MB
Throughput: 8 Mb
Unit display
Set unitDisplay to long (1.45 megabytes) or narrow (1.45MB) to change how the unit is rendered:
short: 1.45 MB
long: 1.45 megabytes
narrow: 1.45MB
Locale
Set locale to format the number for a specific locale. Always set it when rendering
on the server, the server and client default locales may differ:
en-US: 1.45 MB
de-DE: 1,45 MB
fr-FR: 1,45 Mo
Maximum fraction digits
Use maximumFractionDigits to limit the number of digits after the decimal point:
formatBytes function
Use formatBytes when you need a string instead of a component, for example in aria-label:
| Function call | Result |
|---|---|
| formatBytes(1450) | 1.45 kB |
| formatBytes(1450, { unitSystem: 'binary' }) | 1.42 KiB |
| formatBytes(8_000_000, { unit: 'bit' }) | 8 Mb |
| formatBytes(1450, { locale: 'de-DE' }) | 1,45 kB |
formatBytes options
FileSize supports the same options as props: