04A Wave Label Whose Letters Rise One by One on Hashed Delays
Each letter gets a delay from a coordinate hash and rises on its own spring, so the label stands up like a wave rather than as one block.
Best forNewsletter signup fields on landing pages
STAGGER_MSWAVE_AMPNOISE_SEEDSETTLE

<main class="stage">
<div class="fl is-demo" id="fl" data-demo="1">
<div class="fl__field">
<div class="fl__box" data-r="box">
<input class="fl__input" id="f1" data-r="input" type="text" autocomplete="name">
<label class="fl__label" for="f1" data-r="label">Name</label>
</div>
</div>
<div class="fl__field">
<div class="fl__box" data-r="box">
<input class="fl__input" id="f2" data-r="input" type="email" autocomplete="email">
<label class="fl__label" for="f2" data-r="label">Email address</label>
</div>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 핵심: 글자마다 좌표 해시 지연과 스프링으로 라벨이 물결처럼 올라간다. 라벨은 진짜 <label for> 이고 칸은 진짜 입력 요소다. 움직임 값은 JS 가 계산하고 CSS 는 모양만 맡는다.
@include stage($stage-ink);
$panel: mix($subject-cream, $stage-ink, 8%);
$box-bg: mix($subject-cream, $stage-ink, 5%);
$fg: $subject-cream;
$mute: $tick-mute;
$line: mix($subject-cream, $stage-ink, 32%);
$accent: $subject-lilac;
$err: $tick-down;
$menu-bg: mix($subject-cream, $stage-ink, 16%);
$box-h: 52px;
.fl {
position: relative;
box-sizing: border-box;
width: min(100%, 440px);
padding: $sp-5;
display: flex;
flex-direction: column;
gap: $sp-4;
border-radius: $r-card;
background: $panel;
color: $fg;
font-size: 16px;
line-height: 24px;
font-weight: 500;
}
.fl__field { position: relative; }
.fl__box {
--ln: #{$line};
position: relative;
z-index: 1;
height: $box-h;
border-radius: $r-sm;
background: $box-bg;
box-shadow: inset 0 0 0 1.5px var(--ln), 0 0 0 calc(var(--p, 0) * 3px) rgba($accent, .3);
}
.fl__box[data-up] { --ln: #{$accent}; }
.fl__box::after {
content: "";
position: absolute;
inset: 0;
z-index: 0;
border-radius: inherit;
background: $accent;
opacity: calc(var(--p, 0) * .12);
pointer-events: none;
}
.fl__input {
position: relative;
z-index: 1;
box-sizing: border-box;
display: block;
width: 100%;
height: 100%;
margin: 0;
padding: $sp-6 $sp-3 $sp-1;
border: 0;
border-radius: inherit;
background: transparent;
color: $fg;
font-family: inherit;
font-size: 16px;
line-height: 24px;
font-weight: 500;
outline: none;
}
.fl__input:focus-visible { outline: 2px solid $accent; outline-offset: 2px; }
.fl__label {
position: absolute;
left: $sp-3;
top: 0;
z-index: 2;
line-height: $box-h;
font-size: 16px;
font-weight: 500;
color: $mute;
white-space: nowrap;
transform-origin: 0 50%;
pointer-events: none;
will-change: transform;
}
.fl__box[data-up] .fl__label { color: $accent; }
.fl__ch { display: inline-block; white-space: pre; will-change: transform; }
@media (max-height: 250px) {
.fl__field:nth-child(n + 3) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
.fl__label, .fl__box { will-change: auto; }
}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);
}
.fl {
position: relative;
box-sizing: border-box;
width: min(100%, 440px);
padding: 20px;
display: flex;
flex-direction: column;
gap: 16px;
border-radius: 16px;
background: rgb(16.2980392157%, 14.9647058824%, 16.5960784314%);
color: #fff7e6;
font-size: 16px;
line-height: 24px;
font-weight: 500;
}
.fl__field {
position: relative;
}
.fl__box {
--ln: rgb(38.1333333333%, 36.3294117647%, 35.7960784314%);
position: relative;
z-index: 1;
height: 52px;
border-radius: 8px;
background: rgb(13.568627451%, 12.2941176471%, 14.1960784314%);
box-shadow: inset 0 0 0 1.5px var(--ln), 0 0 0 calc(var(--p, 0) * 3px) rgba(185, 160, 255, 0.3);
}
.fl__box[data-up] {
--ln: #b9a0ff;
}
.fl__box::after {
content: "";
position: absolute;
inset: 0;
z-index: 0;
border-radius: inherit;
background: #b9a0ff;
opacity: calc(var(--p, 0) * 0.12);
pointer-events: none;
}
.fl__input {
position: relative;
z-index: 1;
box-sizing: border-box;
display: block;
width: 100%;
height: 100%;
margin: 0;
padding: 24px 12px 4px;
border: 0;
border-radius: inherit;
background: transparent;
color: #fff7e6;
font-family: inherit;
font-size: 16px;
line-height: 24px;
font-weight: 500;
outline: none;
}
.fl__input:focus-visible {
outline: 2px solid #b9a0ff;
outline-offset: 2px;
}
.fl__label {
position: absolute;
left: 12px;
top: 0;
z-index: 2;
line-height: 52px;
font-size: 16px;
font-weight: 500;
color: #9a93a6;
white-space: nowrap;
transform-origin: 0 50%;
pointer-events: none;
will-change: transform;
}
.fl__box[data-up] .fl__label {
color: #b9a0ff;
}
.fl__ch {
display: inline-block;
white-space: pre;
will-change: transform;
}
@media (max-height: 250px) {
.fl__field:nth-child(n+3) {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
.fl__label, .fl__box {
will-change: auto;
}
}(function () {
const root = document.getElementById("fl");
const CLS = { ch: "fl__ch" };
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let demo = !reduce;
let raf = 0;
let last = -1;
const offs = [];
function q(sel) {
return root.querySelector(sel);
}
function qa(sel) {
const list = Array.prototype.slice.call(root.querySelectorAll(sel));
return list;
}
function clamp(v, lo, hi) {
return Math.max(lo, Math.min(hi, v));
}
function on(el, type, fn) {
el.addEventListener(type, fn);
offs.push(function () {
el.removeEventListener(type, fn);
});
}
// 좌표 해시: 같은 입력이면 같은 값 0~1. 난수 함수를 쓰지 않고 사인의 소수부만 쓴다.
function hash(x) {
const s = Math.sin(x * 127.1 + 311.7) * 43758.5453;
return s - Math.floor(s);
}
// 지수 접근: 프레임당 비율 per 만큼 목표에 다가간다. f 는 60fps 기준 프레임 수(dt * 60)라 프레임률이 달라도 같은 속도다.
function approach(x, target, per, f) {
return x + (target - x) * (1 - Math.pow(1 - per, f));
}
// 스프링 한 칸: 가속도 = -k (x - 목표) - c v. 반암시적 오일러를 1/120초 이하 부분 스텝으로 쪼갠다.
function springStep(s, target, k, c, dt) {
let left = dt;
while (left > 0) {
const h = Math.min(left, 1 / 120);
s.v += (-k * (s.x - target) - c * s.v) * h;
s.x += s.v * h;
left -= h;
}
}
// 값이 있으면 라벨은 올라가 있어야 한다. 브라우저 자동완성이 값을 채우면 input 이벤트가 없을 수 있어 :autofill 도 함께 본다.
function isFilled(el) {
if (el.value !== "") return true;
try {
return el.matches(":-webkit-autofill");
} catch (err) {
return false;
}
}
let leaveHook = null;
function stopDemo() {
if (!demo) return;
demo = false;
root.removeAttribute("data-demo");
root.classList.remove("is-demo");
resetFields();
}
function frame(ts) {
const dt = last < 0 ? 0.016 : Math.min(0.05, (ts - last) / 1000);
last = ts;
if (demo) script(ts);
step(dt, ts);
render();
raf = requestAnimationFrame(frame);
}
const ro = new ResizeObserver(function () {
relayout();
});
ro.observe(root);
if (document.fonts) {
document.fonts.ready.then(function () {
relayout();
});
}
// 시연 계획: 칸마다 포커스 구간(a~b), 타이핑 시작(s)·글자당 ms(rate)·글. 2초 주기로 되풀이하고 주기 첫머리엔 모두 비운다.
function runPlan(ts) {
const t = ts % 2000;
let changed = false;
for (let i = 0; i < PLAN.length; i += 1) {
const p = PLAN[i];
const f = fields[i];
const isOn = t >= p.a && t < p.b;
const n = t < p.s ? 0 : Math.min(p.text.length, Math.floor((t - p.s) / p.rate) + 1);
const v = p.text.slice(0, n);
if (f.input.value !== v) {
f.input.value = v;
changed = true;
}
if (f.focus !== isOn) {
f.focus = isOn;
changed = true;
if (!isOn && leaveHook) leaveHook(i);
}
}
if (changed) retarget();
}
function resetFields() {
for (let i = 0; i < fields.length; i += 1) {
fields[i].input.value = "";
fields[i].focus = false;
}
retarget();
}
function wire() {
fields.forEach(function (f, i) {
on(f.input, "focus", function () {
stopDemo();
f.focus = true;
retarget();
});
on(f.input, "blur", function () {
f.focus = false;
if (leaveHook) leaveHook(i);
retarget();
});
on(f.input, "input", function () {
retarget();
});
});
}
// 기법: 글자마다 좌표 해시로 출발 지연을 주고, 각자 스프링으로 올라간다. 라벨 전체가 아니라 글자 하나하나가 물결처럼 일어난다.
const STAGGER_MS = 260;
const WAVE_AMP = 90;
const NOISE_SEED = 7;
const SETTLE = 150;
const DAMP = 11;
const RISE_PX = 15;
const LABEL_SCALE = 0.74;
const fields = qa("[data-r=box]").map(function (box) {
const label = box.querySelector("label");
const text = label.textContent || "";
label.textContent = "";
const chars = [];
for (let i = 0; i < text.length; i += 1) {
const el = document.createElement("span");
el.className = CLS.ch;
el.textContent = text.charAt(i);
label.appendChild(el);
chars.push({ el: el, sp: { x: 0, v: 0 }, wait: 0, t: 0, fired: true, goal: 0 });
}
return { box: box, input: box.querySelector("input"), label: label, chars: chars, focus: false, up: false, dir: -1 };
});
const PLAN = [
{ a: 200, b: 950, s: 420, rate: 60, text: "Mina Seo" },
{ a: 950, b: 1700, s: 1050, rate: 60, text: "[email protected]" }
];
// 글자 i 의 출발 지연(초) = 좌표 해시 × STAGGER_MS. 같은 칸·같은 자리면 항상 같은 지연이라 되풀이해도 같은 물결이다.
function delayOf(fi, i) {
return hash(i * 17.3 + fi * 91.7 + NOISE_SEED) * STAGGER_MS / 1000;
}
function retarget() {
fields.forEach(function (f, fi) {
f.up = f.focus || isFilled(f.input);
if (f.up) f.box.setAttribute("data-up", "");
else f.box.removeAttribute("data-up");
const dir = f.up ? 1 : -1;
if (dir === f.dir) return;
f.dir = dir;
f.chars.forEach(function (c, i) {
c.wait = delayOf(fi, i);
c.t = 0;
c.fired = false;
if (reduce) {
c.sp.x = f.up ? -RISE_PX : 0;
c.sp.v = 0;
c.goal = c.sp.x;
c.fired = true;
}
});
});
if (reduce) render();
}
function relayout() {
retarget();
}
function script(ts) {
runPlan(ts);
}
function step(dt, ts) {
fields.forEach(function (f) {
f.chars.forEach(function (c) {
c.t += dt;
if (!c.fired && c.t >= c.wait) {
c.fired = true;
c.goal = f.up ? -RISE_PX : 0;
c.sp.v += (f.up ? -1 : 1) * WAVE_AMP;
}
springStep(c.sp, c.goal, SETTLE, DAMP, dt);
});
});
}
function render() {
fields.forEach(function (f) {
let mean = 0;
f.chars.forEach(function (c) {
c.el.style.transform = "translate3d(0," + c.sp.x.toFixed(2) + "px,0)";
mean += clamp(c.sp.x / -RISE_PX, 0, 1);
});
const r = mean / f.chars.length;
const s = 1 - (1 - LABEL_SCALE) * r;
f.label.style.transform = "scale(" + s.toFixed(3) + ")";
f.box.style.setProperty("--p", r.toFixed(3));
});
}
wire();
relayout();
if (reduce) {
render();
} else {
raf = requestAnimationFrame(frame);
}
})();// CharWaveLabel - vanilla 판(04-fl-char-wave-label) 의 React 포트. 같은 계산을 useEffect 안에서 돌린다.
import { useEffect, useRef } from "react";
import styles from "./CharWaveLabel.module.scss";
type Spring = { x: number; v: number };
type Plan = { a: number; b: number; s: number; rate: number; text: string };
type Base = { input: HTMLInputElement | HTMLTextAreaElement; focus: boolean; up: boolean };
type Ch = { el: HTMLElement; sp: Spring; wait: number; t: number; fired: boolean; goal: number };
type F = Base & { box: HTMLElement; label: HTMLElement; chars: Ch[]; dir: number };
export default function CharWaveLabel() {
const rootRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
const rootEl = rootRef.current;
if (!rootEl) return;
const root: HTMLElement = rootEl;
const CLS = { ch: styles["fl__ch"] };
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let demo = !reduce;
let raf: number = 0;
let last: number = -1;
const offs: Array<() => void> = [];
function q(sel: string): HTMLElement {
return root.querySelector(sel) as HTMLElement;
}
function qa(sel: string): HTMLElement[] {
const list: HTMLElement[] = Array.prototype.slice.call(root.querySelectorAll(sel));
return list;
}
function clamp(v: number, lo: number, hi: number): number {
return Math.max(lo, Math.min(hi, v));
}
function on(el: EventTarget, type: string, fn: (e: any) => void): void {
el.addEventListener(type, fn);
offs.push(function (): void {
el.removeEventListener(type, fn);
});
}
// 좌표 해시: 같은 입력이면 같은 값 0~1. 난수 함수를 쓰지 않고 사인의 소수부만 쓴다.
function hash(x: number): number {
const s = Math.sin(x * 127.1 + 311.7) * 43758.5453;
return s - Math.floor(s);
}
// 지수 접근: 프레임당 비율 per 만큼 목표에 다가간다. f 는 60fps 기준 프레임 수(dt * 60)라 프레임률이 달라도 같은 속도다.
function approach(x: number, target: number, per: number, f: number): number {
return x + (target - x) * (1 - Math.pow(1 - per, f));
}
// 스프링 한 칸: 가속도 = -k (x - 목표) - c v. 반암시적 오일러를 1/120초 이하 부분 스텝으로 쪼갠다.
function springStep(s: Spring, target: number, k: number, c: number, dt: number): void {
let left = dt;
while (left > 0) {
const h = Math.min(left, 1 / 120);
s.v += (-k * (s.x - target) - c * s.v) * h;
s.x += s.v * h;
left -= h;
}
}
// 값이 있으면 라벨은 올라가 있어야 한다. 브라우저 자동완성이 값을 채우면 input 이벤트가 없을 수 있어 :autofill 도 함께 본다.
function isFilled(el: HTMLInputElement | HTMLTextAreaElement): boolean {
if (el.value !== "") return true;
try {
return el.matches(":-webkit-autofill");
} catch (err) {
return false;
}
}
let leaveHook: ((i: number) => void) | null = null;
function stopDemo(): void {
if (!demo) return;
demo = false;
root.removeAttribute("data-demo");
root.classList.remove("is-demo");
resetFields();
}
function frame(ts: number): void {
const dt = last < 0 ? 0.016 : Math.min(0.05, (ts - last) / 1000);
last = ts;
if (demo) script(ts);
step(dt, ts);
render();
raf = requestAnimationFrame(frame);
}
const ro = new ResizeObserver(function (): void {
relayout();
});
ro.observe(root);
if (document.fonts) {
document.fonts.ready.then(function (): void {
relayout();
});
}
// 시연 계획: 칸마다 포커스 구간(a~b), 타이핑 시작(s)·글자당 ms(rate)·글. 2초 주기로 되풀이하고 주기 첫머리엔 모두 비운다.
function runPlan(ts: number): void {
const t = ts % 2000;
let changed = false;
for (let i = 0; i < PLAN.length; i += 1) {
const p = PLAN[i];
const f = fields[i];
const isOn = t >= p.a && t < p.b;
const n = t < p.s ? 0 : Math.min(p.text.length, Math.floor((t - p.s) / p.rate) + 1);
const v = p.text.slice(0, n);
if (f.input.value !== v) {
f.input.value = v;
changed = true;
}
if (f.focus !== isOn) {
f.focus = isOn;
changed = true;
if (!isOn && leaveHook) leaveHook(i);
}
}
if (changed) retarget();
}
function resetFields(): void {
for (let i = 0; i < fields.length; i += 1) {
fields[i].input.value = "";
fields[i].focus = false;
}
retarget();
}
function wire(): void {
fields.forEach(function (f: F, i: number): void {
on(f.input, "focus", function (): void {
stopDemo();
f.focus = true;
retarget();
});
on(f.input, "blur", function (): void {
f.focus = false;
if (leaveHook) leaveHook(i);
retarget();
});
on(f.input, "input", function (): void {
retarget();
});
});
}
// 기법: 글자마다 좌표 해시로 출발 지연을 주고, 각자 스프링으로 올라간다. 라벨 전체가 아니라 글자 하나하나가 물결처럼 일어난다.
const STAGGER_MS = 260;
const WAVE_AMP = 90;
const NOISE_SEED = 7;
const SETTLE = 150;
const DAMP = 11;
const RISE_PX = 15;
const LABEL_SCALE = 0.74;
const fields: F[] = qa("[data-r=box]").map(function (box: HTMLElement): F {
const label = box.querySelector("label") as HTMLElement;
const text = label.textContent || "";
label.textContent = "";
const chars: Ch[] = [];
for (let i = 0; i < text.length; i += 1) {
const el = document.createElement("span");
el.className = CLS.ch;
el.textContent = text.charAt(i);
label.appendChild(el);
chars.push({ el: el, sp: { x: 0, v: 0 }, wait: 0, t: 0, fired: true, goal: 0 });
}
return { box: box, input: box.querySelector("input") as HTMLInputElement, label: label, chars: chars, focus: false, up: false, dir: -1 };
});
const PLAN: Plan[] = [
{ a: 200, b: 950, s: 420, rate: 60, text: "Mina Seo" },
{ a: 950, b: 1700, s: 1050, rate: 60, text: "[email protected]" }
];
// 글자 i 의 출발 지연(초) = 좌표 해시 × STAGGER_MS. 같은 칸·같은 자리면 항상 같은 지연이라 되풀이해도 같은 물결이다.
function delayOf(fi: number, i: number): number {
return hash(i * 17.3 + fi * 91.7 + NOISE_SEED) * STAGGER_MS / 1000;
}
function retarget(): void {
fields.forEach(function (f: F, fi: number): void {
f.up = f.focus || isFilled(f.input);
if (f.up) f.box.setAttribute("data-up", "");
else f.box.removeAttribute("data-up");
const dir = f.up ? 1 : -1;
if (dir === f.dir) return;
f.dir = dir;
f.chars.forEach(function (c: Ch, i: number): void {
c.wait = delayOf(fi, i);
c.t = 0;
c.fired = false;
if (reduce) {
c.sp.x = f.up ? -RISE_PX : 0;
c.sp.v = 0;
c.goal = c.sp.x;
c.fired = true;
}
});
});
if (reduce) render();
}
function relayout(): void {
retarget();
}
function script(ts: number): void {
runPlan(ts);
}
function step(dt: number, ts: number): void {
fields.forEach(function (f: F): void {
f.chars.forEach(function (c: Ch): void {
c.t += dt;
if (!c.fired && c.t >= c.wait) {
c.fired = true;
c.goal = f.up ? -RISE_PX : 0;
c.sp.v += (f.up ? -1 : 1) * WAVE_AMP;
}
springStep(c.sp, c.goal, SETTLE, DAMP, dt);
});
});
}
function render(): void {
fields.forEach(function (f: F): void {
let mean = 0;
f.chars.forEach(function (c: Ch): void {
c.el.style.transform = "translate3d(0," + c.sp.x.toFixed(2) + "px,0)";
mean += clamp(c.sp.x / -RISE_PX, 0, 1);
});
const r = mean / f.chars.length;
const s = 1 - (1 - LABEL_SCALE) * r;
f.label.style.transform = "scale(" + s.toFixed(3) + ")";
f.box.style.setProperty("--p", r.toFixed(3));
});
}
wire();
relayout();
if (reduce) {
render();
} else {
raf = requestAnimationFrame(frame);
}
return () => {
cancelAnimationFrame(raf);
offs.forEach((f) => f());
ro.disconnect();
};
}, []);
return (
<main className={styles["stage"]}>
<div ref={rootRef} className={styles["fl"] + " is-demo"} data-demo="1">
<div className={styles["fl__field"]}>
<div className={styles["fl__box"]} data-r="box">
<input className={styles["fl__input"]} id="f1" data-r="input" type="text" autoComplete="name" />
<label className={styles["fl__label"]} htmlFor="f1" data-r="label">이름</label>
</div>
</div>
<div className={styles["fl__field"]}>
<div className={styles["fl__box"]} data-r="box">
<input className={styles["fl__input"]} id="f2" data-r="input" type="email" autoComplete="email" />
<label className={styles["fl__label"]} htmlFor="f2" data-r="label">이메일 주소</label>
</div>
</div>
</div>
</main>
);
}04 A Wave Label Whose Letters Rise One by One on Hashed Delays — Measured area 32.578% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · CSS Floating Label: 9 Inputs on Spring Physics
The post this demo lives in
CSS Floating Label: 9 Inputs on Spring PhysicsWithin 0.3 seconds of a tap on a field, the way a css floating label rises sets the first impression of the form — scene See all demos in this post
If you like this effect - similar demos
Inputs04 Mask value toggle — when the masking value turns on, all but the first few digit values switch to a symbol valueCredit Card Input UI: 9 Patterns
Inputs05 Select-all cascade toggle — when the parent box's select-all value turns on, each child box's checked value flips in order with a short staggerCSS Custom Checkbox: 9 Interaction Patterns
Inputs02 Floating label inputRegister Form Design: 9 Keyboard-Friendly Inputs