Skip to content
shadcn.io
shadcn.io is not affiliated with official shadcn/ui

Shadcn Format for React and Tailwind

Format numbers, bytes, and time with Intl API.

File size120 kB

Installation

bunx --bun shadcn@latest add https://kit.dev/r/format.json

Usage

import { 
  FormatByte, 
  FormatNumber, 
  FormatRelativeTime 
} from "@/registry/react/components/format";
<FormatByte value={120_000} />
<FormatNumber value={1234567} />
<FormatRelativeTime value={new Date("2025-05-05")} />

Examples

Format Byte

Format byte values as file sizes.

Unit display

Use the unitDisplay prop to control how the unit is displayed.

Unit system

Use unitSystem to choose between decimal (1000 bytes) or binary (1024 bytes).

Format Relative Time

Format dates as relative time.

Style

Use the style prop for long, short, or narrow format.

Format Number

Format numbers with locale-aware options.

Currency

Use style="currency" with the currency prop for currency formatting.

Percentage

Use style="percent" to format numbers as percentages.

Compact notation

Use notation="compact" for compact display.

API Reference

FormatByte

PropTypeDefault
valuenumber-
unit"byte" | "bit""byte"
unitDisplay"long" | "short" | "narrow"-
unitSystem"decimal" | "binary"-
localestring-

FormatRelativeTime

PropTypeDefault
valueDate | number-
numeric"always" | "auto"-
style"long" | "short" | "narrow"-
localestring-

FormatNumber

PropTypeDefault
valuenumber-
localestring-
style"decimal" | "percent" | "currency" | "unit""decimal"
currencystring-
unitstring-
notation"standard" | "compact" | "scientific" | "engineering""standard"
minimumFractionDigitsnumber-
maximumFractionDigitsnumber-

For a complete list of props, see the Ark UI documentation.