09Inline input validation
While typing, a green check appears the moment the format is valid, or a red message if it isn't.
Best forSignup email and password validation, login form error display
실시간 검증role="status" 알림성공/실패 아이콘

<main class="stage">
<div class="valid is-demo" id="wrap">
<label class="valid__label" for="email-input">Email</label>
<div class="valid__frame" id="frame">
<input class="valid__input" id="email-input" type="email" placeholder="[email protected]" aria-describedby="email-msg">
<span class="valid__icon" id="icon" aria-hidden="true"></span>
</div>
<p class="valid__msg" id="email-msg" role="status"></p>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────────────────
$duration: $dur-quick;
$easing: $ease-pop;
$color: $error; // 오류 색 (성공은 토큰 blue 대신 아래 green 사용)
$ok: #4b976b;
// ── 데모 무대 ──────────────────────────────────────────
@include stage($stage-ink);
.valid {
box-sizing: border-box;
width: min(270px, 86vw);
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 {
position: relative;
border: 2px solid transparent;
border-radius: $r-control;
background: #fff;
transition: border-color $duration $easing;
&.is-ok { border-color: $ok; }
&.is-bad { border-color: $color; }
}
&__input {
box-sizing: border-box;
width: 100%;
border: 0;
border-radius: inherit;
padding: $sp-3 $sp-8 $sp-3 $sp-4;
font-weight: 500;
font-size: clamp(13px, 3.8vw, 15px);
font-family: inherit;
color: $stage-ink;
background: transparent;
&:focus { outline: none; }
}
&__icon {
position: absolute;
right: $sp-3;
top: 50%;
transform: translateY(-50%) scale(0);
font-weight: 800;
font-size: 15px;
line-height: 1;
transition: transform $duration $easing;
}
&__frame.is-ok &__icon { color: $ok; transform: translateY(-50%) scale(1); }
&__frame.is-bad &__icon { color: $color; transform: translateY(-50%) scale(1); }
&__msg {
margin: $sp-2 0 0;
min-height: 14px;
font-size: 12px;
line-height: 1.4;
font-weight: 600;
font-family: inherit;
color: $color;
}
}
@media (prefers-reduced-motion: reduce) {
.valid__frame, .valid__icon { transition: none; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.valid {
box-sizing: border-box;
width: min(270px, 86vw);
background: #fff7e6;
border-radius: 16px;
padding: 20px 20px 16px;
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
}
.valid__label {
display: block;
margin: 0 0 8px;
font-weight: 700;
font-size: 13px;
line-height: 1;
font-family: inherit;
color: #17141a;
}
.valid__frame {
position: relative;
border: 2px solid transparent;
border-radius: 12px;
background: #fff;
transition: border-color 220ms cubic-bezier(0.2, 1.4, 0.4, 1);
}
.valid__frame.is-ok {
border-color: #4b976b;
}
.valid__frame.is-bad {
border-color: #c2361a;
}
.valid__input {
box-sizing: border-box;
width: 100%;
border: 0;
border-radius: inherit;
padding: 12px 32px 12px 16px;
font-weight: 500;
font-size: clamp(13px, 3.8vw, 15px);
font-family: inherit;
color: #17141a;
background: transparent;
}
.valid__input:focus {
outline: none;
}
.valid__icon {
position: absolute;
right: 12px;
top: 50%;
transform: translateY(-50%) scale(0);
font-weight: 800;
font-size: 15px;
line-height: 1;
transition: transform 220ms cubic-bezier(0.2, 1.4, 0.4, 1);
}
.valid__frame.is-ok .valid__icon {
color: #4b976b;
transform: translateY(-50%) scale(1);
}
.valid__frame.is-bad .valid__icon {
color: #c2361a;
transform: translateY(-50%) scale(1);
}
.valid__msg {
margin: 8px 0 0;
min-height: 14px;
font-size: 12px;
line-height: 1.4;
font-weight: 600;
font-family: inherit;
color: #c2361a;
}
@media (prefers-reduced-motion: reduce) {
.valid__frame, .valid__icon {
transition: none;
}
}(function () {
var wrap = document.getElementById('wrap');
var frame = document.getElementById('frame');
var input = document.getElementById('email-input');
var icon = document.getElementById('icon');
var msg = document.getElementById('email-msg');
var RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
function check(v) {
frame.classList.remove('is-ok', 'is-bad');
if (!v) { icon.textContent = ''; msg.textContent = ''; return; }
if (RE.test(v)) {
frame.classList.add('is-ok'); icon.textContent = '✓'; msg.textContent = '';
} else {
frame.classList.add('is-bad'); icon.textContent = '!'; msg.textContent = 'Check the email format';
}
}
input.addEventListener('input', function () { check(input.value); });
input.addEventListener('pointerdown', stopDemo);
input.addEventListener('keydown', stopDemo);
function stopDemo() {
if (!wrap.classList.contains('is-demo')) return;
wrap.classList.remove('is-demo');
clearInterval(timer);
input.value = ''; check('');
}
var script = ['g', 'go', 'god', 'godrich', 'godrich@', 'godrich@mail', '[email protected]'];
var i = 0;
var timer = setInterval(function () {
if (i >= script.length) { i = 0; input.value = ''; check(''); return; }
input.value = script[i]; check(script[i]); i++;
}, 260);
})();import { useState } from "react";
import styles from "./InlineValidation.module.scss";
export type InlineValidationProps = {
label?: string;
};
const RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
export default function InlineValidation({ label = "이메일" }: InlineValidationProps) {
const [value, setValue] = useState("");
const state = value === "" ? "idle" : RE.test(value) ? "ok" : "bad";
return (
<div className={styles.valid}>
<label className={styles.label} htmlFor="email-field">{label}</label>
<div className={`${styles.frame} ${state === "ok" ? styles.ok : ""} ${state === "bad" ? styles.badState : ""}`}>
<input
className={styles.input}
id="email-field"
type="email"
placeholder="[email protected]"
aria-describedby="email-field-msg"
value={value}
onChange={(e: any) => setValue(e.target.value)}
/>
<span className={styles.icon} aria-hidden="true">
{state === "ok" ? "✓" : state === "bad" ? "!" : ""}
</span>
</div>
<p className={styles.msg} id="email-field-msg" role="status">
{state === "bad" ? "이메일 형식을 확인해 주세요" : ""}
</p>
</div>
);
}09 Inline input validation — Measured area 3.935% · moving frames 14/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

