03Date input with auto-slash
Type digits only and slashes appear automatically every two digits, like 2026/09/11.
Best forBirthdate entry, manual booking-date entry
YYYY/MM/DD숫자만 허용자동 슬래시

<main class="stage">
<div class="dt is-demo" id="wrap">
<label class="dt__label" for="dt-input">Birthdate</label>
<input class="dt__input" id="dt-input" type="text" inputmode="numeric" placeholder="YYYY/MM/DD" aria-describedby="dt-hint">
<p class="dt__hint" id="dt-hint">Type digits only — slashes are added automatically</p>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────────────────
$duration: $dur-quick; // 테두리 색 전환 시간
$easing: $ease-out; // 포커스 이징
$color: $stage-orange; // 포커스 강조 색
// ── 데모 무대 ──────────────────────────────────────────
@include stage($stage-orange);
.dt {
box-sizing: border-box;
width: min(272px, 84vw);
background: #fff;
border-radius: $r-card;
padding: $sp-4;
box-shadow: $shadow-raised;
&__label {
display: block;
margin: 0 0 $sp-1;
font-weight: 700;
font-size: 12px;
line-height: 1;
font-family: inherit;
color: $stage-ink;
}
&__input {
box-sizing: border-box;
width: 100%;
border: 2px solid transparent;
border-radius: $r-control;
padding: $sp-3 $sp-4;
font-weight: 600;
font-size: clamp(14px, 4.2vw, 18px);
font-family: inherit;
letter-spacing: .04em;
color: $stage-ink;
background: rgba(23, 20, 26, .06);
transition: border-color $duration $easing, background $duration $easing;
&:focus {
outline: none;
border-color: $color;
background: #fff;
}
}
&__hint {
margin: $sp-1 0 0;
font-size: 11px;
line-height: 1.4;
font-family: inherit;
color: rgba($stage-ink, .72);
}
}
@media (prefers-reduced-motion: reduce) {
.dt__input {
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);
}
.dt {
box-sizing: border-box;
width: min(272px, 84vw);
background: #fff;
border-radius: 16px;
padding: 16px;
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
}
.dt__label {
display: block;
margin: 0 0 4px;
font-weight: 700;
font-size: 12px;
line-height: 1;
font-family: inherit;
color: #17141a;
}
.dt__input {
box-sizing: border-box;
width: 100%;
border: 2px solid transparent;
border-radius: 12px;
padding: 12px 16px;
font-weight: 600;
font-size: clamp(14px, 4.2vw, 18px);
font-family: inherit;
letter-spacing: 0.04em;
color: #17141a;
background: rgba(23, 20, 26, 0.06);
transition: border-color 220ms ease-out, background 220ms ease-out;
}
.dt__input:focus {
outline: none;
border-color: #ff4d1f;
background: #fff;
}
.dt__hint {
margin: 4px 0 0;
font-size: 11px;
line-height: 1.4;
font-family: inherit;
color: rgba(23, 20, 26, 0.72);
}
@media (prefers-reduced-motion: reduce) {
.dt__input {
transition: none;
}
}(function () {
var wrap = document.getElementById('wrap');
var input = document.getElementById('dt-input');
function format(raw) {
var digits = raw.replace(/\D/g, '').slice(0, 8);
var out = digits.slice(0, 4);
if (digits.length > 4) out += '/' + digits.slice(4, 6);
if (digits.length > 6) out += '/' + digits.slice(6, 8);
return out;
}
input.addEventListener('input', function () {
input.value = format(input.value);
});
function stopDemo() {
if (!wrap.classList.contains('is-demo')) return;
wrap.classList.remove('is-demo');
clearInterval(timer);
}
input.addEventListener('pointerdown', stopDemo);
input.addEventListener('keydown', stopDemo);
var digits = '20260911';
var raw = '';
var phase = 'focus';
var pauseUntil = 0;
var timer = setInterval(function () {
var now = Date.now();
if (now < pauseUntil) return;
if (phase === 'focus') {
input.focus({ preventScroll: true });
phase = 'type';
return;
}
if (phase === 'type') {
if (raw.length < digits.length) {
raw += digits[raw.length];
input.value = raw;
input.dispatchEvent(new Event('input', { bubbles: true }));
} else {
phase = 'hold';
pauseUntil = now + 900;
}
return;
}
if (phase === 'hold') {
raw = '';
input.value = '';
input.dispatchEvent(new Event('input', { bubbles: true }));
input.blur();
phase = 'blurhold';
pauseUntil = now + 500;
return;
}
if (phase === 'blurhold') {
phase = 'focus';
}
}, 140);
})();import { useState } from "react";
import styles from "./DateAutoSlashInput.module.scss";
export type DateAutoSlashInputProps = {
label?: string;
hint?: string;
};
function formatDate(raw: string): string {
const digits = raw.replace(/\D/g, "").slice(0, 8);
let out = digits.slice(0, 4);
if (digits.length > 4) out += "/" + digits.slice(4, 6);
if (digits.length > 6) out += "/" + digits.slice(6, 8);
return out;
}
export default function DateAutoSlashInput({
label = "생년월일",
hint = "숫자만 입력하면 슬래시가 자동으로 붙어요",
}: DateAutoSlashInputProps) {
const [value, setValue] = useState("");
const onChange = (e: any) => {
setValue(formatDate(e.target.value));
};
return (
<div className={styles.dt}>
<label className={styles.label} htmlFor="dt-input">
{label}
</label>
<input
className={styles.input}
id="dt-input"
type="text"
inputMode="numeric"
placeholder="YYYY/MM/DD"
aria-describedby="dt-hint"
value={value}
onChange={onChange}
/>
<p className={styles.hint} id="dt-hint">
{hint}
</p>
</div>
);
}03 Date input with auto-slash — Measured area 8.603% · moving frames 10/23Original by GODRICH · SCSS and React ship in the zip · Register Form Design: 9 Keyboard-Friendly Inputs
The post this demo lives in
Register Form Design: 9 Keyboard-Friendly InputsRegister form design lives or dies in the fields, not the submit button. These nine inputs cover everything a signup scr See all demos in this post
If you like this effect - similar demos
Inputs03 Currency input with auto commaCSS Input Design: 9 Form Widgets You Can Paste In
Inputs02 Expiry-separator value toggle — once the month and year digit values fill in, a separator value automatically appears between themCredit Card Input UI: 9 Patterns
Inputs03 An Input Whose Underline Chases the Caret with InertiaCSS Floating Label: 9 Inputs on Spring Physics