03Currency input with auto comma
Type a number into a currency-prefixed field and thousands separators appear automatically.
Best forDonation amount fields, quote and invoice amount entry
₩ 접두어천 단위 콤마우측 정렬

<main class="stage">
<div class="field is-demo" id="field">
<label class="field__label" for="amount-input">Donation amount</label>
<div class="field__frame">
<span class="field__prefix" aria-hidden="true">₩</span>
<input class="field__input" id="amount-input" type="text" inputmode="numeric" placeholder="0" aria-describedby="amount-hint">
</div>
<p class="field__hint" id="amount-hint">Type digits and thousands separators are added automatically</p>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────────────────
$duration: $dur-quick;
$easing: $ease-out;
$color: $subject-blue;
// ── 데모 무대 ──────────────────────────────────────────
@include stage($stage-orange);
.field {
box-sizing: border-box;
width: min(260px, 84vw);
background: $subject-cream;
border-radius: $r-card;
padding: $sp-5 $sp-5 $sp-4;
box-shadow: $shadow-raised;
&__label {
display: block;
margin: 0 0 $sp-2;
font-weight: 700;
font-size: 13px;
line-height: 1;
font-family: inherit;
color: $stage-ink;
}
&__frame {
display: flex;
align-items: center;
gap: $sp-2;
border: 2px solid transparent;
border-radius: $r-control;
padding: $sp-3 $sp-4;
background: #fff;
transition: border-color $duration $easing;
&:focus-within { border-color: $color; }
}
&__prefix {
font-weight: 700;
font-size: clamp(15px, 4.4vw, 18px);
font-family: inherit;
color: rgba(23, 20, 26, .72);
}
&__input {
box-sizing: border-box;
flex: 1 1 auto;
min-width: 0;
border: 0;
padding: 0;
text-align: right;
font-weight: 700;
font-size: clamp(15px, 4.4vw, 18px);
font-family: inherit;
color: $stage-ink;
background: transparent;
&:focus { outline: none; }
}
&__hint {
margin: $sp-2 0 0;
font-size: 12px;
line-height: 1.4;
font-family: inherit;
color: rgba(23, 20, 26, .6);
}
}
@media (prefers-reduced-motion: reduce) {
.field__frame { transition: none; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ff4d1f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.field {
box-sizing: border-box;
width: min(260px, 84vw);
background: #fff7e6;
border-radius: 16px;
padding: 20px 20px 16px;
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
}
.field__label {
display: block;
margin: 0 0 8px;
font-weight: 700;
font-size: 13px;
line-height: 1;
font-family: inherit;
color: #17141a;
}
.field__frame {
display: flex;
align-items: center;
gap: 8px;
border: 2px solid transparent;
border-radius: 12px;
padding: 12px 16px;
background: #fff;
transition: border-color 220ms ease-out;
}
.field__frame:focus-within {
border-color: #2f6df6;
}
.field__prefix {
font-weight: 700;
font-size: clamp(15px, 4.4vw, 18px);
font-family: inherit;
color: rgba(23, 20, 26, 0.72);
}
.field__input {
box-sizing: border-box;
flex: 1 1 auto;
min-width: 0;
border: 0;
padding: 0;
text-align: right;
font-weight: 700;
font-size: clamp(15px, 4.4vw, 18px);
font-family: inherit;
color: #17141a;
background: transparent;
}
.field__input:focus {
outline: none;
}
.field__hint {
margin: 8px 0 0;
font-size: 12px;
line-height: 1.4;
font-family: inherit;
color: rgba(23, 20, 26, 0.6);
}
@media (prefers-reduced-motion: reduce) {
.field__frame {
transition: none;
}
}(function () {
var field = document.getElementById('field');
var input = document.getElementById('amount-input');
function format(v) {
var d = v.replace(/\D/g, '').replace(/^0+(?=\d)/, '').slice(0, 12);
return d ? Number(d).toLocaleString('ko-KR') : '';
}
input.addEventListener('input', function () {
input.value = format(input.value);
});
function stopDemo() {
if (!field.classList.contains('is-demo')) return;
field.classList.remove('is-demo');
clearInterval(timer);
input.value = '';
}
input.addEventListener('pointerdown', stopDemo);
input.addEventListener('keydown', stopDemo);
var digits = '1500000';
var i = 0;
var timer = setInterval(function () {
if (i > digits.length) { i = 0; input.value = ''; return; }
input.value = format(digits.slice(0, i));
i++;
}, 190);
})();import { useRef, useState } from "react";
import styles from "./CurrencyInput.module.scss";
export type CurrencyInputProps = {
label?: string;
hint?: string;
symbol?: string;
};
function format(raw: string): string {
const d = raw.replace(/\D/g, "").replace(/^0+(?=\d)/, "").slice(0, 12);
return d ? Number(d).toLocaleString("ko-KR") : "";
}
export default function CurrencyInput({
label = "후원 금액",
hint = "숫자만 입력하면 천 단위 콤마가 자동으로 붙습니다",
symbol = "₩",
}: CurrencyInputProps) {
const [value, setValue] = useState("");
const id = useRef("amount-input-" + Math.random().toString(36).slice(2)).current;
return (
<div className={styles.field}>
<label className={styles.label} htmlFor={id}>{label}</label>
<div className={styles.frame}>
<span className={styles.prefix} aria-hidden="true">{symbol}</span>
<input
className={styles.input}
id={id}
type="text"
inputMode="numeric"
placeholder="0"
aria-describedby={id + "-hint"}
value={value}
onChange={(e: any) => setValue(format(e.target.value))}
/>
</div>
<p className={styles.hint} id={id + "-hint"}>{hint}</p>
</div>
);
}03 Currency input with auto comma — Measured area 0.557% · moving frames 12/23Original by GODRICH · SCSS and React ship in the zip · CSS Input Design: 9 Form Widgets You Can Paste In
The post this demo lives in
CSS Input Design: 9 Form Widgets You Can Paste InCSS input design means the small form fields — phone numbers, card numbers, quantities, tags — that fill checkout and si See all demos in this post
If you like this effect - similar demos
Inputs03 Date input with auto-slashRegister Form Design: 9 Keyboard-Friendly Inputs
Inputs01 Digit-group value toggle — as the entered digit value reaches every fourth position, a spacing value automatically appears between groupsCredit Card Input UI: 9 Patterns
Inputs05 Tag Input That Splits a Pasted List Into Chips at Once9 Tag Input UI Patterns With CSS Chips