Gravity Password V2
A password made of small amber beads. A wrong one puts their light out: they fall, bounce off the bottom edge and roll into the low corner. The right one lights the pile again, every bead lifts off and they settle into one even row, light runs along it and the button turns gold.
- Sign in & forms
- Free
- physics
- form
- password
- Added Oct 10, 2026
<style>
/* Gravity Password V2 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
.gp {
--bead: 14px;
--gold: #F7B544;
--error: #FF5A4C;
--ease-out: cubic-bezier(.23, 1, .32, 1);
width: 320px;
max-width: calc(100vw - 32px);
}
.gp .who {
display: flex;
align-items: center;
gap: 10px;
width: max-content;
margin: 0 auto 22px;
padding: 5px 14px 5px 5px;
border: 1px solid #2C2418;
border-radius: 999px;
background: #13100B;
color: #CFC4B1;
font-size: 14px;
}
.gp .who b {
display: grid;
place-items: center;
width: 26px;
height: 26px;
border-radius: 50%;
background: linear-gradient(135deg, #FFD88A, #E39A2A);
color: #2A1A06;
font-size: 13px;
}
.gp .top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.gp label { color: #A89C88; font-size: 13px; font-weight: 600; }
.gp .top a { color: #8C8170; font-size: 13px; text-decoration: none; }
.gp .field {
position: relative;
z-index: 1;
height: 66px;
transform-origin: 100% 50%;
border: 1.5px solid #2E2619;
border-radius: 14px;
background: #100D09;
transition: border-color .5s ease-out;
}
/* the warm light inside the field is its own layer: only its opacity changes */
.gp .field::before, .gp .field::after {
content: "";
position: absolute;
inset: 0;
border-radius: inherit;
opacity: 0;
pointer-events: none;
transition: opacity .5s ease-out;
}
.gp .field::before { background: radial-gradient(120% 150% at 50% 50%, rgba(247, 181, 68, .13), rgba(247, 181, 68, 0) 72%); }
.gp .field::after { background: radial-gradient(120% 150% at 50% 50%, rgba(255, 90, 76, .2), rgba(255, 90, 76, 0) 72%); }
.gp .field.focus::before { opacity: .65; }
.gp .field.ok::before { opacity: 1; }
.gp .field.error::after { opacity: 1; transition-duration: .08s; }
.gp .field.focus { border-color: rgba(247, 181, 68, .62); }
.gp .field.error { border-color: var(--error); transition-duration: .08s; }
.gp .field.ok { border-color: var(--gold); }
.gp input {
position: absolute;
inset: 0;
width: 100%;
box-sizing: border-box;
padding: 0 20px;
border: 0;
border-radius: inherit;
background: none;
color: transparent;
caret-color: transparent;
font: 22px system-ui, sans-serif;
outline: none;
}
.gp input::selection { background: transparent; }
.gp .beads { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; pointer-events: none; }
/* a bead is dark bronze glass; its light is a layer on top that goes out and comes back */
.gp .bead {
position: absolute;
left: 0;
top: 0;
width: var(--bead);
height: var(--bead);
border-radius: 50%;
background: radial-gradient(circle at 34% 30%, #8A7356 0 16%, #4A3A26 55%, #241B10 100%);
will-change: translate;
}
.gp .bead::before, .gp .bead::after {
content: "";
position: absolute;
border-radius: 50%;
transition: opacity .32s var(--ease-out);
/* the delay lives in a variable that only the light reads: a delay on the bead itself would hold back every move it makes */
transition-delay: var(--light-delay, 0ms);
}
.gp .bead::before { inset: 0; background: radial-gradient(circle at 34% 30%, #FFF7E0 0 16%, #FFD27C 44%, #E28B1C 100%); }
.gp .bead::after { inset: -7px; background: radial-gradient(circle, rgba(247, 181, 68, .42), rgba(247, 181, 68, 0) 68%); }
.gp .bead.dark::before, .gp .bead.dark::after { opacity: 0; transition-duration: 1.6s; }
.gp .field.ok .bead::after { animation: breathe 2.2s ease-in-out infinite alternate; animation-delay: var(--breathe-delay, 0ms); }
@keyframes breathe { from { opacity: .4; } to { opacity: 1; } }
.gp .sweep {
position: absolute;
top: 0;
bottom: 0;
left: -110px;
width: 110px;
background: linear-gradient(90deg, rgba(255, 232, 180, 0), rgba(255, 240, 205, .5), rgba(255, 232, 180, 0));
opacity: 0;
}
.gp .field.ok .sweep { animation: sweep 2.6s cubic-bezier(.77, 0, .175, 1) infinite; }
@keyframes sweep {
0% { transform: translateX(0); opacity: 0; }
8%, 30% { opacity: 1; }
45%, 100% { transform: translateX(600%); opacity: 0; }
}
.gp .caret {
position: absolute;
left: 0;
top: 50%;
width: 2px;
height: 26px;
margin-top: -13px;
border-radius: 1px;
background: var(--gold);
visibility: hidden;
}
.gp .field.focus .caret { visibility: visible; }
.gp .field.ok .caret { visibility: hidden; }
.gp .msg { height: 20px; margin: 14px 2px 8px; color: var(--error); font-size: 13px; font-weight: 600; text-align: right; opacity: 0; }
.gp button {
position: relative;
display: grid;
width: 100%;
height: 52px;
border: 1px solid #3A2F1E;
border-radius: 14px;
overflow: hidden;
background: linear-gradient(180deg, #2A2215, #1A150D);
color: #EADCC2;
font: 600 16px system-ui, sans-serif;
cursor: pointer;
transition: transform .16s var(--ease-out), border-color .3s ease;
}
.gp button::before {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(180deg, #FFD98C, #F0A53A);
opacity: 0;
transition: opacity .3s var(--ease-out);
}
.gp button span { grid-area: 1 / 1; position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; transition: opacity .24s ease, filter .24s ease, translate .24s var(--ease-out); }
.gp button .done { opacity: 0; filter: blur(2px); translate: 0 4px; color: #2A1A05; }
.gp button:active { transform: scale(.97); }
.gp.ok button { border-color: #F4B04A; box-shadow: 0 14px 28px -14px rgba(0, 0, 0, .8); }
.gp.ok button::before { opacity: 1; }
.gp.ok button .idle { opacity: 0; filter: blur(2px); translate: 0 -4px; }
.gp.ok button .done { opacity: 1; filter: none; translate: 0 0; }
@media (hover: hover) and (pointer: fine) {
.gp button:hover { border-color: #5A4728; }
}
@media (prefers-reduced-motion: reduce) {
.gp .field.ok .bead::after, .gp .field.ok .sweep { animation: none; }
.gp button span { transition: opacity .2s ease; translate: none !important; filter: none !important; }
}
</style>
<!-- EFFECT -->
<form class="gp" novalidate>
<div class="who"><b>A</b>alex@example.com</div>
<div class="top"><label for="gp-password">Password</label><a href="#">Forgot?</a></div>
<div class="field">
<input id="gp-password" type="password" autocomplete="current-password" aria-describedby="gp-msg">
<div class="beads" aria-hidden="true"><i class="sweep"></i><i class="caret"></i></div>
</div>
<p class="msg" id="gp-msg" role="alert"></p>
<button type="submit"><span class="idle">Sign in</span><span class="done"><svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path d="M3 8.5 6.4 12 13 4.5" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>Welcome back</span></button>
</form>
<!-- /EFFECT -->
<script>
/* Gravity Password V2 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
(() => {
const GRAVITY = 0.9;
const BOUNCE = 0.42;
const TILT = 1.6;
const STIFF = 0.06;
const DAMP = 0.78;
const DEMO_PASSWORD = 'sunshine!';
async function checkPassword(password) {
// ask your server here and return true when the password is right
return password === DEMO_PASSWORD;
}
const form = document.querySelector('.gp');
const field = form.querySelector('.field'), input = field.querySelector('input');
const layer = field.querySelector('.beads'), caret = layer.querySelector('.caret');
const msg = form.querySelector('.msg'), button = form.querySelector('button');
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
const STEP = 1 / 60, PAD = 20, GAP = 8, NAP = 20, GRIP = .9, ROLL = .985;
let typed = [], fallen = [], rising = [], seed = 7, blink, checking = false, signedIn = false;
let tries = 0, warned = false;
let R = 7, FLOOR = 0, LEFT = 0, RIGHT = 0, MID = 0;
const tilt = { angle: 0, velocity: 0, goal: 0 };
const rand = () => (seed = seed * 16807 % 2147483647) / 2147483647;
const clamp = (x, a, b) => Math.min(b, Math.max(a, x));
const put = (el, x, y) => { el.style.translate = `${x - R}px ${y - R}px`; };
const vibrate = p => { if (navigator.vibrate) navigator.vibrate(p); };
function measure() {
R = parseFloat(getComputedStyle(form).getPropertyValue('--bead')) / 2;
FLOOR = layer.clientHeight - R - 3; // the bottom edge of the field
MID = layer.clientHeight / 2;
LEFT = R + 4;
RIGHT = layer.clientWidth - R - 4;
}
// where the i-th of n beads sits on the line: evenly spaced, closer together when there are many
function slot(i, n) {
const step = Math.min(R * 2 + GAP, (layer.clientWidth - PAD * 2 - R * 2) / Math.max(n - 1, 1));
return PAD + R + i * step;
}
function layout() {
measure();
typed.forEach((b, i) => { b.x = slot(i, typed.length); b.y = MID; put(b.el, b.x, b.y); });
const at = Math.min(input.selectionStart ?? typed.length, typed.length);
caret.style.transform = `translateX(${(typed.length ? slot(at - 1, typed.length) + R + GAP / 2 : PAD) - 1}px)`;
}
function wake() {
blink?.cancel();
blink = caret.animate(
[{ opacity: 1 }, { opacity: 1, offset: .5 }, { opacity: 0, offset: .5 }, { opacity: 0 }],
{ duration: 1000, iterations: Infinity });
}
function bead() {
const el = document.createElement('i');
el.className = 'bead';
layer.insertBefore(el, caret);
return { el, x: 0, y: 0, vx: 0, vy: 0 };
}
function sync() {
if (signedIn) restart();
while (typed.length < input.value.length) {
const b = bead();
typed.push(b);
// every new bead drops onto the line and settles with one small bounce
if (!reduce) b.el.animate([
{ transform: 'translateY(-16px)', opacity: 0 },
{ transform: 'translateY(0)', opacity: 1, offset: .62 },
{ transform: 'translateY(-3px)', offset: .82 },
{ transform: 'translateY(0)' },
], { duration: 260, easing: 'cubic-bezier(.23, 1, .32, 1)' });
}
while (typed.length > input.value.length) {
const { el } = typed.pop();
el.animate([{ scale: 1, opacity: 1 }, { scale: .6, opacity: 0 }], { duration: 120, easing: 'ease-out', fill: 'forwards' }).onfinish = () => el.remove();
}
layout();
wake();
}
// wrong password: the light goes out of the beads and they fall onto the pile from the tries before
function collapse() {
tries++;
warned = true;
field.classList.add('error');
setTimeout(() => field.classList.remove('error'), 240);
msg.textContent = tries > 1 ? `Wrong password ×${tries}` : 'Wrong password';
msg.animate([{ opacity: 0, translate: '0 -4px' }, { opacity: 1, translate: '0 0' }], { duration: 200, easing: 'ease-out', fill: 'forwards' });
vibrate([18, 40, 18]);
measure();
tilt.goal = -TILT * Math.min(tries, 3) * Math.PI / 180;
typed.forEach((b, i) => {
b.el.style.setProperty('--light-delay', `${i * 18}ms`);
b.el.classList.add('dark');
const hop = -2.5 - rand() * 2.5;
const flight = (-hop + Math.sqrt(hop * hop + 2 * GRAVITY * (FLOOR - b.y))) / GRAVITY;
const aim = LEFT + rand() * R * 7;
Object.assign(b, { floor: FLOOR, wait: i * .025, rest: 0, from: { x: b.x, y: b.y }, vx: (aim - b.x) / flight, vy: hop });
fallen.push(b);
});
typed = [];
input.value = '';
layout();
input.focus();
if (reduce) { fallen.forEach(b => b.el.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 200, fill: 'forwards' }).onfinish = () => b.el.remove()); fallen = []; return; }
run();
}
// the right password: every bead lights up, lifts off and takes its place in one even row, left to right as they lie
function welcome() {
signedIn = true;
tries = 0;
hush();
measure();
const all = [...fallen, ...typed].sort((a, b) => a.x - b.x);
const fits = Math.floor((layer.clientWidth - PAD * 2) / (R * 1.15)) || 1;
all.splice(fits).forEach(b => b.el.animate([{ opacity: 1 }, { opacity: 0, scale: .6 }], { duration: 240, fill: 'forwards' }).onfinish = () => b.el.remove());
all.forEach((b, i) => {
b.el.style.setProperty('--light-delay', `${i * 32}ms`);
b.el.style.setProperty('--breathe-delay', `${i * 90}ms`);
b.el.classList.remove('dark');
b.goal = { x: slot(i, all.length), y: MID };
b.wait = .12 + i * .035;
b.vy = -(2 + rand() * 1.5); // a small push upwards first, so the lift reads before the beads find their place
b.vx = 0;
});
rising = all;
caret.style.visibility = 'hidden';
fallen = [];
typed = [];
tilt.goal = 0;
vibrate(24);
if (reduce) { rising.forEach(b => { b.x = b.goal.x; b.y = b.goal.y; put(b.el, b.x, b.y); }); arrive(); return; }
run();
}
// the row is in place: light runs along it and the button turns gold
function arrive() {
field.classList.add('ok');
form.classList.add('ok');
}
// typing after a right password clears the row and starts over
function restart() {
signedIn = false;
caret.style.visibility = '';
field.classList.remove('ok');
form.classList.remove('ok');
rising.forEach((b, i) => b.el.animate([{ opacity: 1, scale: 1 }, { opacity: 0, scale: .6 }], { duration: 160, delay: (rising.length - i) * 14, easing: 'ease-out', fill: 'forwards' }).onfinish = () => b.el.remove());
rising = [];
}
// every pair of fallen beads closer than reach, with the direction from the first to the second
function pairs(reach, visit) {
for (let i = 0; i < fallen.length; i++) {
for (let j = i + 1; j < fallen.length; j++) {
const a = fallen[i], b = fallen[j];
if (a.wait > 0 || b.wait > 0) continue;
const ma = a.rest > NAP ? 0 : 1, mb = b.rest > NAP ? 0 : 1; // a bead at rest stays where it is
if (!ma && !mb) continue;
const dx = b.x - a.x, dy = b.y - a.y, d = Math.hypot(dx, dy);
if (d < reach && d > 0) visit(a, b, dx / d, dy / d, d, ma, mb);
}
}
}
function step() {
const k = (2 * Math.PI / .5) ** 2, c = 4 * Math.PI * .4 / .5;
tilt.velocity += (-k * (tilt.angle - tilt.goal) - c * tilt.velocity) * STEP;
tilt.angle += tilt.velocity * STEP;
const lean = Math.sin(tilt.angle);
const loose = [];
for (const b of fallen) {
if (b.wait > 0) { b.wait -= STEP; continue; }
if (b.rest > NAP) continue;
loose.push(b);
b.touched = false;
b.vx += GRAVITY * lean;
b.vy += GRAVITY;
}
// beads that touch stop moving into each other, a hard hit bounces
for (let pass = 0; pass < 8; pass++) {
for (const b of loose) if (b.y === b.floor && b.vy > 0 && b.vy < GRAVITY * 2) b.vy = 0;
pairs(R * 2 + 1, (a, b, nx, ny, d, ma, mb) => {
a.touched = b.touched = true;
const vn = (b.vx - a.vx) * nx + (b.vy - a.vy) * ny;
if (vn >= 0) return;
const kick = -(1 + (!pass && vn < -GRAVITY * 3 ? BOUNCE : 0)) * vn / (ma + mb);
a.vx -= kick * nx * ma; a.vy -= kick * ny * ma;
b.vx += kick * nx * mb; b.vy += kick * ny * mb;
});
}
for (const b of loose) {
if (b.touched) { b.vx *= GRIP; b.vy *= GRIP; }
b.x += b.vx;
b.y += b.vy;
if (b.y > b.floor) {
b.y = b.floor;
b.vy *= -BOUNCE;
}
if (b.y === b.floor && Math.abs(b.vy) < GRAVITY) { b.vy = 0; b.vx *= ROLL; }
if (b.x < LEFT || b.x > RIGHT) { b.x = clamp(b.x, LEFT, RIGHT); b.vx *= -BOUNCE; }
}
// whatever still overlaps is pushed apart
for (let pass = 0; pass < 6; pass++) {
pairs(R * 2, (a, b, nx, ny, d, ma, mb) => {
const push = (R * 2 - d) / (ma + mb);
a.x = clamp(a.x - nx * push * ma, LEFT, RIGHT); a.y = Math.min(a.y - ny * push * ma, a.floor);
b.x = clamp(b.x + nx * push * mb, LEFT, RIGHT); b.y = Math.min(b.y + ny * push * mb, b.floor);
});
}
// a bead that has stayed within a pixel for a while goes to rest
const level = Math.abs(tilt.angle - tilt.goal) < .002;
for (const b of loose) {
if (Math.hypot(b.x - b.from.x, b.y - b.from.y) > 1 || !level) { b.from = { x: b.x, y: b.y }; b.rest = 0; }
else if (++b.rest > NAP) b.vx = b.vy = 0;
}
// the rise: two springs per bead, one across and one up, so each finds its slot from wherever it lay
let moving = false;
for (const b of rising) {
if (b.wait > 0) { b.wait -= STEP; moving = true; continue; }
b.vx += (b.goal.x - b.x) * STIFF;
b.vy += (b.goal.y - b.y) * STIFF;
b.vx *= DAMP; b.vy *= DAMP;
b.x += b.vx;
b.y += b.vy;
if (Math.abs(b.goal.x - b.x) + Math.abs(b.goal.y - b.y) > .2 || Math.abs(b.vx) + Math.abs(b.vy) > .05) moving = true;
else { b.x = b.goal.x; b.y = b.goal.y; }
}
if (rising.length && !moving && !field.classList.contains('ok')) arrive();
return moving || fallen.some(b => b.wait > 0 || b.rest <= NAP) || Math.abs(tilt.angle - tilt.goal) > 1e-4 || Math.abs(tilt.velocity) > 1e-3;
}
function draw() {
for (const b of fallen) put(b.el, b.x, b.y);
for (const b of rising) put(b.el, b.x, b.y);
field.style.transform = tilt.angle ? `rotate(${tilt.angle}rad)` : '';
}
let running = false, last = 0, acc = 0, calm = 0;
function frame(now) {
acc += Math.min((now - last) / 1000, .1);
last = now;
while (acc >= STEP) {
acc -= STEP;
calm = step() ? 0 : calm + 1;
}
if (calm > 30) {
tilt.angle = tilt.goal;
tilt.velocity = 0;
running = false;
}
draw();
if (running) requestAnimationFrame(frame);
}
function run() {
calm = 0;
if (running) return;
running = true;
requestAnimationFrame(t => { last = t; acc = 0; requestAnimationFrame(frame); });
}
function hush() {
if (!warned) return;
warned = false;
msg.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 150, easing: 'ease-out', fill: 'forwards' })
.onfinish = () => { if (!warned) msg.textContent = ''; };
}
input.addEventListener('input', () => { hush(); sync(); });
input.addEventListener('keyup', layout);
input.addEventListener('focus', () => { field.classList.add('focus'); layout(); wake(); });
input.addEventListener('blur', () => field.classList.remove('focus'));
form.addEventListener('submit', async e => {
e.preventDefault();
if (!input.value || checking || signedIn) { input.focus(); return; }
checking = true;
const ok = await checkPassword(input.value);
checking = false;
if (ok) welcome(); else collapse();
});
addEventListener('resize', layout);
})();
</script>
Type any password and press Sign in. Then type sunshine! and press Sign in again.
What you can change
Change a number, save, and reload the page to see the difference.
GRAVITY0.9How fast the beads fall, px per frame squared.
BOUNCE0.42How much speed a bead keeps when it hits the bottom. 0 lands dead, 0.8 is a rubber ball.
TILT1.6Degrees the field sinks with every wrong try. 0 keeps it level.
STIFF0.06How hard the right password pulls the beads into their row. 0.03 drifts up, 0.1 snaps.
DAMP0.78How much speed a rising bead keeps each frame. 0.7 settles still, 0.9 sways first.
Add it to your site
Sign in and unlock screens, PIN and passcode fields, any form where the right answer should feel like a reward.
CSS
Paste into your stylesheet, or inside a <style> tag in <head>.
/* Gravity Password V2 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */ .gp { --bead: 14px; --gold: #F7B544; --error: #FF5A4C; --ease-out: cubic-bezier(.23, 1, .32, 1); width: 320px; max-width: calc(100vw - 32px); } .gp .who { display: flex; align-items: center; gap: 10px; width: max-content; margin: 0 auto 22px; padding: 5px 14px 5px 5px; border: 1px solid #2C2418; border-radius: 999px; background: #13100B; color: #CFC4B1; font-size: 14px; } .gp .who b { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg, #FFD88A, #E39A2A); color: #2A1A06; font-size: 13px; } .gp .top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; } .gp label { color: #A89C88; font-size: 13px; font-weight: 600; } .gp .top a { color: #8C8170; font-size: 13px; text-decoration: none; } .gp .field { position: relative; z-index: 1; height: 66px; transform-origin: 100% 50%; border: 1.5px solid #2E2619; border-radius: 14px; background: #100D09; transition: border-color .5s ease-out; } /* the warm light inside the field is its own layer: only its opacity changes */ .gp .field::before, .gp .field::after { content: ""; position: absolute; inset: 0; border-radius: inherit; opacity: 0; pointer-events: none; transition: opacity .5s ease-out; } .gp .field::before { background: radial-gradient(120% 150% at 50% 50%, rgba(247, 181, 68, .13), rgba(247, 181, 68, 0) 72%); } .gp .field::after { background: radial-gradient(120% 150% at 50% 50%, rgba(255, 90, 76, .2), rgba(255, 90, 76, 0) 72%); } .gp .field.focus::before { opacity: .65; } .gp .field.ok::before { opacity: 1; } .gp .field.error::after { opacity: 1; transition-duration: .08s; } .gp .field.focus { border-color: rgba(247, 181, 68, .62); } .gp .field.error { border-color: var(--error); transition-duration: .08s; } .gp .field.ok { border-color: var(--gold); } .gp input { position: absolute; inset: 0; width: 100%; box-sizing: border-box; padding: 0 20px; border: 0; border-radius: inherit; background: none; color: transparent; caret-color: transparent; font: 22px system-ui, sans-serif; outline: none; } .gp input::selection { background: transparent; } .gp .beads { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; pointer-events: none; } /* a bead is dark bronze glass; its light is a layer on top that goes out and comes back */ .gp .bead { position: absolute; left: 0; top: 0; width: var(--bead); height: var(--bead); border-radius: 50%; background: radial-gradient(circle at 34% 30%, #8A7356 0 16%, #4A3A26 55%, #241B10 100%); will-change: translate; } .gp .bead::before, .gp .bead::after { content: ""; position: absolute; border-radius: 50%; transition: opacity .32s var(--ease-out); /* the delay lives in a variable that only the light reads: a delay on the bead itself would hold back every move it makes */ transition-delay: var(--light-delay, 0ms); } .gp .bead::before { inset: 0; background: radial-gradient(circle at 34% 30%, #FFF7E0 0 16%, #FFD27C 44%, #E28B1C 100%); } .gp .bead::after { inset: -7px; background: radial-gradient(circle, rgba(247, 181, 68, .42), rgba(247, 181, 68, 0) 68%); } .gp .bead.dark::before, .gp .bead.dark::after { opacity: 0; transition-duration: 1.6s; } .gp .field.ok .bead::after { animation: breathe 2.2s ease-in-out infinite alternate; animation-delay: var(--breathe-delay, 0ms); } @keyframes breathe { from { opacity: .4; } to { opacity: 1; } } .gp .sweep { position: absolute; top: 0; bottom: 0; left: -110px; width: 110px; background: linear-gradient(90deg, rgba(255, 232, 180, 0), rgba(255, 240, 205, .5), rgba(255, 232, 180, 0)); opacity: 0; } .gp .field.ok .sweep { animation: sweep 2.6s cubic-bezier(.77, 0, .175, 1) infinite; } @keyframes sweep { 0% { transform: translateX(0); opacity: 0; } 8%, 30% { opacity: 1; } 45%, 100% { transform: translateX(600%); opacity: 0; } } .gp .caret { position: absolute; left: 0; top: 50%; width: 2px; height: 26px; margin-top: -13px; border-radius: 1px; background: var(--gold); visibility: hidden; } .gp .field.focus .caret { visibility: visible; } .gp .field.ok .caret { visibility: hidden; } .gp .msg { height: 20px; margin: 14px 2px 8px; color: var(--error); font-size: 13px; font-weight: 600; text-align: right; opacity: 0; } .gp button { position: relative; display: grid; width: 100%; height: 52px; border: 1px solid #3A2F1E; border-radius: 14px; overflow: hidden; background: linear-gradient(180deg, #2A2215, #1A150D); color: #EADCC2; font: 600 16px system-ui, sans-serif; cursor: pointer; transition: transform .16s var(--ease-out), border-color .3s ease; } .gp button::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, #FFD98C, #F0A53A); opacity: 0; transition: opacity .3s var(--ease-out); } .gp button span { grid-area: 1 / 1; position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; transition: opacity .24s ease, filter .24s ease, translate .24s var(--ease-out); } .gp button .done { opacity: 0; filter: blur(2px); translate: 0 4px; color: #2A1A05; } .gp button:active { transform: scale(.97); } .gp.ok button { border-color: #F4B04A; box-shadow: 0 14px 28px -14px rgba(0, 0, 0, .8); } .gp.ok button::before { opacity: 1; } .gp.ok button .idle { opacity: 0; filter: blur(2px); translate: 0 -4px; } .gp.ok button .done { opacity: 1; filter: none; translate: 0 0; } @media (hover: hover) and (pointer: fine) { .gp button:hover { border-color: #5A4728; } } @media (prefers-reduced-motion: reduce) { .gp .field.ok .bead::after, .gp .field.ok .sweep { animation: none; } .gp button span { transition: opacity .2s ease; translate: none !important; filter: none !important; } }HTML
Put it where the effect should appear on your page.
<!-- EFFECT --> <form class="gp" novalidate> <div class="who"><b>A</b>alex@example.com</div> <div class="top"><label for="gp-password">Password</label><a href="#">Forgot?</a></div> <div class="field"> <input id="gp-password" type="password" autocomplete="current-password" aria-describedby="gp-msg"> <div class="beads" aria-hidden="true"><i class="sweep"></i><i class="caret"></i></div> </div> <p class="msg" id="gp-msg" role="alert"></p> <button type="submit"><span class="idle">Sign in</span><span class="done"><svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path d="M3 8.5 6.4 12 13 4.5" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>Welcome back</span></button> </form> <!-- /EFFECT -->JavaScript
Paste right before the closing </body> tag, inside <script></script>.
/* Gravity Password V2 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */ (() => { const GRAVITY = 0.9; const BOUNCE = 0.42; const TILT = 1.6; const STIFF = 0.06; const DAMP = 0.78; const DEMO_PASSWORD = 'sunshine!'; async function checkPassword(password) { // ask your server here and return true when the password is right return password === DEMO_PASSWORD; } const form = document.querySelector('.gp'); const field = form.querySelector('.field'), input = field.querySelector('input'); const layer = field.querySelector('.beads'), caret = layer.querySelector('.caret'); const msg = form.querySelector('.msg'), button = form.querySelector('button'); const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches; const STEP = 1 / 60, PAD = 20, GAP = 8, NAP = 20, GRIP = .9, ROLL = .985; let typed = [], fallen = [], rising = [], seed = 7, blink, checking = false, signedIn = false; let tries = 0, warned = false; let R = 7, FLOOR = 0, LEFT = 0, RIGHT = 0, MID = 0; const tilt = { angle: 0, velocity: 0, goal: 0 }; const rand = () => (seed = seed * 16807 % 2147483647) / 2147483647; const clamp = (x, a, b) => Math.min(b, Math.max(a, x)); const put = (el, x, y) => { el.style.translate = `${x - R}px ${y - R}px`; }; const vibrate = p => { if (navigator.vibrate) navigator.vibrate(p); }; function measure() { R = parseFloat(getComputedStyle(form).getPropertyValue('--bead')) / 2; FLOOR = layer.clientHeight - R - 3; // the bottom edge of the field MID = layer.clientHeight / 2; LEFT = R + 4; RIGHT = layer.clientWidth - R - 4; } // where the i-th of n beads sits on the line: evenly spaced, closer together when there are many function slot(i, n) { const step = Math.min(R * 2 + GAP, (layer.clientWidth - PAD * 2 - R * 2) / Math.max(n - 1, 1)); return PAD + R + i * step; } function layout() { measure(); typed.forEach((b, i) => { b.x = slot(i, typed.length); b.y = MID; put(b.el, b.x, b.y); }); const at = Math.min(input.selectionStart ?? typed.length, typed.length); caret.style.transform = `translateX(${(typed.length ? slot(at - 1, typed.length) + R + GAP / 2 : PAD) - 1}px)`; } function wake() { blink?.cancel(); blink = caret.animate( [{ opacity: 1 }, { opacity: 1, offset: .5 }, { opacity: 0, offset: .5 }, { opacity: 0 }], { duration: 1000, iterations: Infinity }); } function bead() { const el = document.createElement('i'); el.className = 'bead'; layer.insertBefore(el, caret); return { el, x: 0, y: 0, vx: 0, vy: 0 }; } function sync() { if (signedIn) restart(); while (typed.length < input.value.length) { const b = bead(); typed.push(b); // every new bead drops onto the line and settles with one small bounce if (!reduce) b.el.animate([ { transform: 'translateY(-16px)', opacity: 0 }, { transform: 'translateY(0)', opacity: 1, offset: .62 }, { transform: 'translateY(-3px)', offset: .82 }, { transform: 'translateY(0)' }, ], { duration: 260, easing: 'cubic-bezier(.23, 1, .32, 1)' }); } while (typed.length > input.value.length) { const { el } = typed.pop(); el.animate([{ scale: 1, opacity: 1 }, { scale: .6, opacity: 0 }], { duration: 120, easing: 'ease-out', fill: 'forwards' }).onfinish = () => el.remove(); } layout(); wake(); } // wrong password: the light goes out of the beads and they fall onto the pile from the tries before function collapse() { tries++; warned = true; field.classList.add('error'); setTimeout(() => field.classList.remove('error'), 240); msg.textContent = tries > 1 ? `Wrong password ×${tries}` : 'Wrong password'; msg.animate([{ opacity: 0, translate: '0 -4px' }, { opacity: 1, translate: '0 0' }], { duration: 200, easing: 'ease-out', fill: 'forwards' }); vibrate([18, 40, 18]); measure(); tilt.goal = -TILT * Math.min(tries, 3) * Math.PI / 180; typed.forEach((b, i) => { b.el.style.setProperty('--light-delay', `${i * 18}ms`); b.el.classList.add('dark'); const hop = -2.5 - rand() * 2.5; const flight = (-hop + Math.sqrt(hop * hop + 2 * GRAVITY * (FLOOR - b.y))) / GRAVITY; const aim = LEFT + rand() * R * 7; Object.assign(b, { floor: FLOOR, wait: i * .025, rest: 0, from: { x: b.x, y: b.y }, vx: (aim - b.x) / flight, vy: hop }); fallen.push(b); }); typed = []; input.value = ''; layout(); input.focus(); if (reduce) { fallen.forEach(b => b.el.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 200, fill: 'forwards' }).onfinish = () => b.el.remove()); fallen = []; return; } run(); } // the right password: every bead lights up, lifts off and takes its place in one even row, left to right as they lie function welcome() { signedIn = true; tries = 0; hush(); measure(); const all = [...fallen, ...typed].sort((a, b) => a.x - b.x); const fits = Math.floor((layer.clientWidth - PAD * 2) / (R * 1.15)) || 1; all.splice(fits).forEach(b => b.el.animate([{ opacity: 1 }, { opacity: 0, scale: .6 }], { duration: 240, fill: 'forwards' }).onfinish = () => b.el.remove()); all.forEach((b, i) => { b.el.style.setProperty('--light-delay', `${i * 32}ms`); b.el.style.setProperty('--breathe-delay', `${i * 90}ms`); b.el.classList.remove('dark'); b.goal = { x: slot(i, all.length), y: MID }; b.wait = .12 + i * .035; b.vy = -(2 + rand() * 1.5); // a small push upwards first, so the lift reads before the beads find their place b.vx = 0; }); rising = all; caret.style.visibility = 'hidden'; fallen = []; typed = []; tilt.goal = 0; vibrate(24); if (reduce) { rising.forEach(b => { b.x = b.goal.x; b.y = b.goal.y; put(b.el, b.x, b.y); }); arrive(); return; } run(); } // the row is in place: light runs along it and the button turns gold function arrive() { field.classList.add('ok'); form.classList.add('ok'); } // typing after a right password clears the row and starts over function restart() { signedIn = false; caret.style.visibility = ''; field.classList.remove('ok'); form.classList.remove('ok'); rising.forEach((b, i) => b.el.animate([{ opacity: 1, scale: 1 }, { opacity: 0, scale: .6 }], { duration: 160, delay: (rising.length - i) * 14, easing: 'ease-out', fill: 'forwards' }).onfinish = () => b.el.remove()); rising = []; } // every pair of fallen beads closer than reach, with the direction from the first to the second function pairs(reach, visit) { for (let i = 0; i < fallen.length; i++) { for (let j = i + 1; j < fallen.length; j++) { const a = fallen[i], b = fallen[j]; if (a.wait > 0 || b.wait > 0) continue; const ma = a.rest > NAP ? 0 : 1, mb = b.rest > NAP ? 0 : 1; // a bead at rest stays where it is if (!ma && !mb) continue; const dx = b.x - a.x, dy = b.y - a.y, d = Math.hypot(dx, dy); if (d < reach && d > 0) visit(a, b, dx / d, dy / d, d, ma, mb); } } } function step() { const k = (2 * Math.PI / .5) ** 2, c = 4 * Math.PI * .4 / .5; tilt.velocity += (-k * (tilt.angle - tilt.goal) - c * tilt.velocity) * STEP; tilt.angle += tilt.velocity * STEP; const lean = Math.sin(tilt.angle); const loose = []; for (const b of fallen) { if (b.wait > 0) { b.wait -= STEP; continue; } if (b.rest > NAP) continue; loose.push(b); b.touched = false; b.vx += GRAVITY * lean; b.vy += GRAVITY; } // beads that touch stop moving into each other, a hard hit bounces for (let pass = 0; pass < 8; pass++) { for (const b of loose) if (b.y === b.floor && b.vy > 0 && b.vy < GRAVITY * 2) b.vy = 0; pairs(R * 2 + 1, (a, b, nx, ny, d, ma, mb) => { a.touched = b.touched = true; const vn = (b.vx - a.vx) * nx + (b.vy - a.vy) * ny; if (vn >= 0) return; const kick = -(1 + (!pass && vn < -GRAVITY * 3 ? BOUNCE : 0)) * vn / (ma + mb); a.vx -= kick * nx * ma; a.vy -= kick * ny * ma; b.vx += kick * nx * mb; b.vy += kick * ny * mb; }); } for (const b of loose) { if (b.touched) { b.vx *= GRIP; b.vy *= GRIP; } b.x += b.vx; b.y += b.vy; if (b.y > b.floor) { b.y = b.floor; b.vy *= -BOUNCE; } if (b.y === b.floor && Math.abs(b.vy) < GRAVITY) { b.vy = 0; b.vx *= ROLL; } if (b.x < LEFT || b.x > RIGHT) { b.x = clamp(b.x, LEFT, RIGHT); b.vx *= -BOUNCE; } } // whatever still overlaps is pushed apart for (let pass = 0; pass < 6; pass++) { pairs(R * 2, (a, b, nx, ny, d, ma, mb) => { const push = (R * 2 - d) / (ma + mb); a.x = clamp(a.x - nx * push * ma, LEFT, RIGHT); a.y = Math.min(a.y - ny * push * ma, a.floor); b.x = clamp(b.x + nx * push * mb, LEFT, RIGHT); b.y = Math.min(b.y + ny * push * mb, b.floor); }); } // a bead that has stayed within a pixel for a while goes to rest const level = Math.abs(tilt.angle - tilt.goal) < .002; for (const b of loose) { if (Math.hypot(b.x - b.from.x, b.y - b.from.y) > 1 || !level) { b.from = { x: b.x, y: b.y }; b.rest = 0; } else if (++b.rest > NAP) b.vx = b.vy = 0; } // the rise: two springs per bead, one across and one up, so each finds its slot from wherever it lay let moving = false; for (const b of rising) { if (b.wait > 0) { b.wait -= STEP; moving = true; continue; } b.vx += (b.goal.x - b.x) * STIFF; b.vy += (b.goal.y - b.y) * STIFF; b.vx *= DAMP; b.vy *= DAMP; b.x += b.vx; b.y += b.vy; if (Math.abs(b.goal.x - b.x) + Math.abs(b.goal.y - b.y) > .2 || Math.abs(b.vx) + Math.abs(b.vy) > .05) moving = true; else { b.x = b.goal.x; b.y = b.goal.y; } } if (rising.length && !moving && !field.classList.contains('ok')) arrive(); return moving || fallen.some(b => b.wait > 0 || b.rest <= NAP) || Math.abs(tilt.angle - tilt.goal) > 1e-4 || Math.abs(tilt.velocity) > 1e-3; } function draw() { for (const b of fallen) put(b.el, b.x, b.y); for (const b of rising) put(b.el, b.x, b.y); field.style.transform = tilt.angle ? `rotate(${tilt.angle}rad)` : ''; } let running = false, last = 0, acc = 0, calm = 0; function frame(now) { acc += Math.min((now - last) / 1000, .1); last = now; while (acc >= STEP) { acc -= STEP; calm = step() ? 0 : calm + 1; } if (calm > 30) { tilt.angle = tilt.goal; tilt.velocity = 0; running = false; } draw(); if (running) requestAnimationFrame(frame); } function run() { calm = 0; if (running) return; running = true; requestAnimationFrame(t => { last = t; acc = 0; requestAnimationFrame(frame); }); } function hush() { if (!warned) return; warned = false; msg.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 150, easing: 'ease-out', fill: 'forwards' }) .onfinish = () => { if (!warned) msg.textContent = ''; }; } input.addEventListener('input', () => { hush(); sync(); }); input.addEventListener('keyup', layout); input.addEventListener('focus', () => { field.classList.add('focus'); layout(); wake(); }); input.addEventListener('blur', () => field.classList.remove('focus')); form.addEventListener('submit', async e => { e.preventDefault(); if (!input.value || checking || signedIn) { input.focus(); return; } checking = true; const ok = await checkPassword(input.value); checking = false; if (ok) welcome(); else collapse(); }); addEventListener('resize', layout); })();
Connect it to your backend
Ask your server in checkPassword(password) and return true when the password is right.
Good to know
- The beads are small elements drawn over a real password input, so Enter, autofill and password managers keep working.
- A wrong try is real physics: gravity, a bounce off the bottom edge and marble collisions, so new beads land on the pile from the tries before.
- The right try uses two springs per bead, one across and one up, so each bead finds its place in the row from wherever it lay, after a small push upwards.
- The light of a bead is a separate layer, only its opacity changes, so lighting and dimming stay cheap on a phone.
- While you are signed in the row breathes and a light runs along it every few seconds. Typing again clears the row.
- No canvas and no libraries.
- With reduced motion nothing falls or flies: the beads fade out on a wrong password and the row fades in on the right one.
Tilda, Webflow, WordPress
Press Copy all code at the top and paste it into one HTML block.
Add block, Other, T123 HTML code. Paste and save. Check the published page, the editor preview does not run scripts.
Add panel, Embed. Paste, then Save & Close. Custom code runs on the published site.
Add block, Custom HTML. Paste and press Update.



