Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Input examples · Special

Currency Input for React

An amount field with a dollar sign inside it that accepts cents.

Framework
UI library

Money inputs need a currency and two decimals. This example puts a DollarSignIcon in an InputGroupAddon beside a number input with min 0 and step 0.01, so the field takes amounts like 19.99, and a description under it says the amount is in USD. Use it for prices, payments, donations and budgets.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

What does type number give this field?

A number field. step is 0.01, so the arrows and the browser's validation work in cents, and min is 0, so the browser rejects a negative amount when the form is submitted. The placeholder 0.00 hints at the format.

How is the icon placed inside the field?

The field is an InputGroup: InputGroupInput is the input and InputGroupAddon holds DollarSignIcon. The addon comes after the input in the markup and sits at the inline start, so it is on the left in left-to-right text and on the right in right-to-left text. Clicking it focuses the input.

Is the icon read by screen readers?

No. DollarSignIcon has aria-hidden, because the Amount label already names the field. The icon is a visual hint only.

How is Amount tied to the field?

Clicking the label focuses the field, and screen readers announce it with the field. FieldLabel sets htmlFor to currency-amount, the input's id.

Does the value include the dollar sign?

No. The icon is outside the input, so the value is a plain number such as 19.99. The currency is named by the icon and by the description, Enter amount in USD.

How do I use another currency?

Swap the icon, for example EuroIcon or PoundSterlingIcon, and change the description. For a currency code instead of a symbol, put the text in the addon with InputGroupText.