28 CSS Input Fields16 / 28

Pure CSSMIT licensed

Currency Input

Right-aligned numeric input with an inline `$` prefix. `inputmode="decimal"` brings up the right mobile keyboard; `:focus-within` lights the prefix to match the field accent.

Published

Live Demo
Try it

The code

<label class="if-16">
  <span class="if-16-label">Amount</span>
  <span class="if-16-wrap">
    <span class="if-16-prefix">$</span>
    <input type="text" name="amount" inputmode="decimal" pattern="[0-9.,]*" placeholder="0.00" />
    <span class="if-16-suffix">USD</span>
  </span>
</label>
.if-16 {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 280px;
}

.if-16-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #b8b6d4;
  text-transform: uppercase;
}

.if-16-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  background: #1a1a22;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  transition: border-color 0.2s, background 0.2s;
}

.if-16-wrap:focus-within {
  border-color: #f5a84a;
  background: #1f1f2a;
}

.if-16-prefix {
  color: #b8b6d4;
  font: 600 14px/1 system-ui, sans-serif;
  transition: color 0.2s;
}

.if-16-wrap:focus-within .if-16-prefix {
  color: #f5a84a;
}

.if-16 input {
  flex: 1;
  min-width: 0;
  padding: 12px 0;
  border: 0;
  outline: none;
  background: transparent;
  color: #f0eeff;
  font: 600 14px/1 system-ui, sans-serif;
  text-align: right;
  -moz-appearance: textfield;
}

.if-16 input::-webkit-outer-spin-button,
.if-16 input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.if-16 input::placeholder {
  color: #b8b6d4;
}

.if-16-suffix {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: #b8b6d4;
  letter-spacing: 0.06em;
}
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS Input Field from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Currency Input
Source: https://codefronts.com/components/css-input-fields/currency-input/

Right-aligned numeric input with an inline `$` prefix. `inputmode="decimal"` brings up the right mobile keyboard; `:focus-within` lights the prefix to match the field accent.
## HTML
```html
<label class="if-16">
  <span class="if-16-label">Amount</span>
  <span class="if-16-wrap">
    <span class="if-16-prefix">$</span>
    <input type="text" name="amount" inputmode="decimal" pattern="[0-9.,]*" placeholder="0.00" />
    <span class="if-16-suffix">USD</span>
  </span>
</label>
```
## CSS
```css
.if-16 {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 280px;
}

.if-16-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #b8b6d4;
  text-transform: uppercase;
}

.if-16-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  background: #1a1a22;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  transition: border-color 0.2s, background 0.2s;
}

.if-16-wrap:focus-within {
  border-color: #f5a84a;
  background: #1f1f2a;
}

.if-16-prefix {
  color: #b8b6d4;
  font: 600 14px/1 system-ui, sans-serif;
  transition: color 0.2s;
}

.if-16-wrap:focus-within .if-16-prefix {
  color: #f5a84a;
}

.if-16 input {
  flex: 1;
  min-width: 0;
  padding: 12px 0;
  border: 0;
  outline: none;
  background: transparent;
  color: #f0eeff;
  font: 600 14px/1 system-ui, sans-serif;
  text-align: right;
  -moz-appearance: textfield;
}

.if-16 input::-webkit-outer-spin-button,
.if-16 input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.if-16 input::placeholder {
  color: #b8b6d4;
}

.if-16-suffix {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: #b8b6d4;
  letter-spacing: 0.06em;
}
```

How this works

The wrapper is a flex row holding the $ prefix, the text input, and an optional USD suffix. inputmode="decimal" triggers the numeric keypad on iOS and Android without disabling desktop paste of commas or decimals; pattern="[0-9.,]*" keeps the field usable but hint-typed. :focus-within lifts the wrapper's border and recolours the prefix so the whole control reads as one field on focus.

Right-aligned digits plus font-variant-numeric: tabular-nums keep column widths stable as the user types — the tabular-nums currency input pattern used across Stripe Checkout, Shopify carts, and WooCommerce line items. For display (not entry), pair with Intl.NumberFormat(locale, { style: 'currency', currency: 'USD' }) to render locale-aware amounts.

Make it yours

  • Swap the prefix to , £, or ¥ — for RTL currencies (SAR, AED) move the prefix into a ::after instead.
  • Add font-variant-numeric: tabular-nums on the input to lock digit widths — critical for aligned totals.
  • Format on blur with Intl.NumberFormat and reparse on focus, keeping the raw number in a hidden field for submit.
  • Change the focus accent by editing #f5a84a or promote it to a --accent custom property.

Gotchas — read before shipping

  • Do not use type="number" for money — it strips leading zeros, rejects locale separators, and mishandles paste of "1,234.56".
  • Store cents as integers server-side; float math on 0.1 + 0.2 will burn you the moment a customer buys three of something.
  • inputmode="decimal" is respected on iOS 12.5+ and Firefox 95+ — older mobile browsers still see the alphanumeric keyboard.

Browser support

ChromeSafariFirefoxEdge
66+12.5+95+66+

inputmode="decimal" gates the mobile numeric keypad; visual chrome works everywhere.

Search CodeFronts

Loading…