Skip to content
Haze UI

Price

A formatted price with a smaller currency and cents, an optional period, a struck-through old price and a discount tag.

pnpm dlx shadcn@latest add @haze/price
Open preview in a new tab
Liveno JavaScript

When to use

  • A plan card, product tile or cart row shows an amount in a currency and locale chosen by the page.
  • A sale needs the old price struck through with a computed 'Save 20%' tag and a clear spoken reading.
  • A plan is billed per month or year and the period should sit quietly next to the figure.

When not to use

  • The user types an amount; use price-input.
  • The number is a KPI or a trend, not something sold; use stat.
  • A whole plan card with features and a button is needed; use a pricing block such as pricing-three-tier.

Installation

Add the Haze registry to components.json once, then install Price with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/price
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
amountnumber24Price in major units (12.5 is twelve and a half, not 1250). 0 shows freeLabel instead of a figure.
currencystring"USD"ISO 4217 code passed to Intl.NumberFormat in the frontmatter, so the output is the same on every build.
localestring"en-US"BCP 47 locale for symbol placement, separators and digits, for example de-DE.
periodLabelstring"/ month"Text after the figure. Empty for a one-off price. Hidden when the price is free.
periodSrLabelstring–Spoken form of the period. Defaults to the label with a leading slash turned into 'per'.
compareAtnumber–Original price, struck through. Only shown when higher than amount.
discountLabelstring | false–Text of the discount tag. Undefined computes 'Save 20%' from compareAt; false hides the tag.
saveLabelstring"Save"Word before the computed percent. Translate it together with locale.
nowLabelstring"Now"Spoken prefix of the current price when compareAt is set.
wasLabelstring"Was"Spoken prefix of the old price.
freeLabelstring"Free"Shown instead of the figure when amount is 0.
fractionDigitsnumber–Decimal places. By default whole amounts show none and others use the currency's own count.
size"sm" | "md" | "lg" | "xl""md"Figure size from 16 to 48 px. Symbol, decimals and period stay smaller.
classstring–Extra classes for the wrapper.

Accessibility

  • The visual figure is hidden from assistive technology and replaced by one sr-only sentence such as "Now $192 per year. Was $240. Save 20%.", so split symbols and digits are never read piecemeal.
  • The struck-through price is never the only cue: the spoken text names it as the old price with the 'Was' label.
  • Figures use tabular numerals so a column of prices lines up; the discount tag has text, not color alone.
  • Pass translated nowLabel, wasLabel, saveLabel, freeLabel and periodSrLabel when the locale is not English.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Price" with `npx shadcn@latest add @haze/price`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Price from "@/components/haze/ui/price.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/price.md

  • Customize with real content

    Adapt the Haze price ui for our product. Replace the demo values of these props with our real content: amount, currency, locale, periodLabel, periodSrLabel, compareAt, discountLabel, saveLabel, nowLabel, wasLabel, freeLabel, fractionDigits, size, class. Keep the layout, the heading level rules and these accessibility details: The visual figure is hidden from assistive technology and replaced by one sr-only sentence such as "Now $192 per year. Was $240. Save 20%.", so split symbols and digits are never read piecemeal. The struck-through price is never the only cue: the spoken text names it as the old price with the 'Was' label. Figures use tabular numerals so a column of prices lines up; the discount tag has text, not color alone. Pass translated nowLabel, wasLabel, saveLabel, freeLabel and periodSrLabel when the locale is not English. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using price, check it fits: use it when a plan card, product tile or cart row shows an amount in a currency and locale chosen by the page.; a sale needs the old price struck through with a computed 'save 20%' tag and a clear spoken reading.; a plan is billed per month or year and the period should sit quietly next to the figure.. Avoid it when the user types an amount; use price-input.; the number is a kpi or a trend, not something sold; use stat.; a whole plan card with features and a button is needed; use a pricing block such as pricing-three-tier.. Alternatives: @haze/price-input, @haze/stat, @haze/animated-number.

Dependencies

  • @haze/tag
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog