Firefly Login V3
A green firefly lights up a dark sign in form, and it is not alone: two more drift behind the glass, a whole wood of far-off lights glows out of focus behind them, and the glow answers your typing, one pulse per key.
- Sign in & forms
- Free
- canvas
- particles
- spring
- glass
- Added Sep 23, 2026
<style>
/* Firefly Login V3 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
/* the dark around the form. every firefly cuts its own hole in it, the working one a wide one */
.night { position: fixed; inset: 0; z-index: 5; pointer-events: none; transition: opacity .6s ease;
background: rgba(7,6,10,.78);
-webkit-mask-image:
radial-gradient(circle at var(--x, -200px) var(--y, 50%), transparent 0, rgba(0,0,0,.45) 95px, #000 190px),
radial-gradient(circle at var(--ax, -200px) var(--ay, 50%), transparent 0, rgba(0,0,0,.5) 34px, #000 120px),
radial-gradient(circle at var(--bx, -200px) var(--by, 50%), transparent 0, rgba(0,0,0,.5) 34px, #000 120px);
mask-image:
radial-gradient(circle at var(--x, -200px) var(--y, 50%), transparent 0, rgba(0,0,0,.45) 95px, #000 190px),
radial-gradient(circle at var(--ax, -200px) var(--ay, 50%), transparent 0, rgba(0,0,0,.5) 34px, #000 120px),
radial-gradient(circle at var(--bx, -200px) var(--by, 50%), transparent 0, rgba(0,0,0,.5) 34px, #000 120px);
-webkit-mask-composite: source-in; mask-composite: intersect; }
.night.day { opacity: .35; }
/* the wood behind the glass: far-off lights out of focus, and slow motes of pollen */
.air { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.air i { position: absolute; left: 0; top: 0; border-radius: 50%; }
.air .far { width: 26px; height: 26px; margin: -13px 0 0 -13px; filter: blur(7px);
background: radial-gradient(circle, rgba(182,255,130,.5), rgba(120,255,90,0) 70%); }
.air .far.warm { background: radial-gradient(circle, rgba(255,224,150,.5), rgba(255,200,90,0) 70%); }
.air .mote { width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; filter: blur(1.4px);
background: radial-gradient(circle, rgba(206,255,150,.85), rgba(162,255,71,0) 70%); }
.air .mote.warm { background: radial-gradient(circle, rgba(255,236,178,.85), rgba(255,210,120,0) 70%); }
/* the colony: two more fireflies, drifting behind the glass */
.colony { position: fixed; inset: 0; z-index: 1; pointer-events: none; }
.colony i { position: absolute; left: 0; top: 0; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%;
background: radial-gradient(circle, rgba(222,255,190,.8), rgba(162,255,71,.35) 42%, rgba(151,255,50,0) 72%);
filter: blur(4px); opacity: .62; }
/* the form is a sheet of glass: the far fireflies read through it, blurred and dimmer */
.login { position: relative; z-index: 2; box-sizing: border-box; width: min(360px, 92vw); display: grid; gap: 16px;
margin: 0; padding: 22px; border-radius: 22px; background: rgba(14,26,18,.42);
-webkit-backdrop-filter: blur(14px) saturate(140%); backdrop-filter: blur(14px) saturate(140%);
box-shadow: inset 0 1px 0 rgba(214,255,190,.22), inset 0 0 0 1px rgba(162,255,71,.1), 0 30px 60px -30px rgba(0,0,0,.9);
animation: materialize .5s cubic-bezier(.23, 1, .32, 1); }
/* a sheet of glass arrives as a material: blur and scale together, not a plain fade */
@keyframes materialize { from { opacity: 0; transform: scale(.96); filter: blur(10px); } }
.field { position: relative; height: 52px; border-radius: 14px; background: #16141A; overflow: hidden;
box-shadow: inset 0 0 0 1.2px rgba(255,238,215,.11); transition: box-shadow .3s cubic-bezier(.23, 1, .32, 1); }
.field:focus-within, .field.lit { box-shadow: inset 0 0 0 1.6px rgba(174,255,95,.9), 0 0 0 4px rgba(162,255,71,.16); }
/* light under the surface while the firefly is inside the field */
.field::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .2s ease;
background: radial-gradient(90px 46px at var(--gx, -100px) 50%, rgba(176,255,100,.4), rgba(156,255,60,.1) 50%, transparent 75%); }
.field.inside::before { opacity: 1; }
.field input { position: relative; box-sizing: border-box; width: 100%; height: 100%; padding: 0 52px 0 18px; border: 0; outline: 0; background: transparent;
font: 500 16px system-ui, sans-serif; color: #F4EFE6; caret-color: #A2FF47; }
.field input::placeholder { color: rgba(205,195,180,.45); }
/* password: the real input stays type="password", what you see is drawn next to it */
.pass input { color: transparent; caret-color: transparent; }
.mirror { position: absolute; left: 18px; right: 52px; top: 0; bottom: 0; pointer-events: none; overflow: hidden; font: 500 16px system-ui, sans-serif; }
.dots, .text { position: absolute; left: 0; top: 0; bottom: 0; display: flex; align-items: center; white-space: pre;
transition: opacity .3s cubic-bezier(.77, 0, .175, 1), filter .3s cubic-bezier(.77, 0, .175, 1); }
.dots i { flex: none; width: 14px; height: 14px; display: grid; place-items: center; }
.dots i::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #F4EFE6; }
.text { opacity: 0; filter: blur(3px); letter-spacing: .5px; }
.text b { font-weight: 500; }
.show .dots { opacity: 0; filter: blur(3px); }
.show .text { opacity: 1; filter: none; }
.dots i.new, .text b.new { animation: flash .5s cubic-bezier(.23, 1, .32, 1); }
@keyframes flash { from { filter: drop-shadow(0 0 5px #B6FF6E) brightness(1.7); } }
.caret { position: absolute; left: 0; top: 16px; width: 2px; height: 20px; background: #A2FF47; opacity: 0; }
.pass:focus-within .caret { opacity: 1; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.eye { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 10px; background: transparent;
display: grid; place-items: center; cursor: pointer; color: rgba(235,228,215,.55); transition: color .2s ease, transform .16s ease-out; }
.eye:active { transform: scale(.94); }
.eye:focus-visible { outline: 2px solid #A2FF47; outline-offset: 1px; }
.eye svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.eye .slash { stroke-dasharray: 26; stroke-dashoffset: 0; transition: stroke-dashoffset .25s cubic-bezier(.23, 1, .32, 1); }
.show .eye { color: #AEFF5F; }
.show .eye .slash { stroke-dashoffset: 26; }
/* the button fills with light from the point where the firefly dove in */
.send { position: relative; height: 54px; border: 0; border-radius: 27px; background: #211D24; box-shadow: inset 0 0 0 1.2px rgba(255,238,215,.10);
color: #EFE8DC; font: 600 16px system-ui, sans-serif; cursor: pointer; overflow: hidden; transition: transform .16s ease-out; }
.send:active { transform: scale(.97); }
.send:focus-visible { outline: 2px solid #A2FF47; outline-offset: 3px; }
.send::before { content: ""; position: absolute; inset: 0; background: linear-gradient(#B9FF74, #9BFF3A);
clip-path: circle(0 at var(--hx, 50%) 50%); transition: clip-path .5s cubic-bezier(.23, 1, .32, 1); }
.send.done::before { clip-path: circle(150% at var(--hx, 50%) 50%); }
.send span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 8px;
transition: opacity .3s ease-out, filter .3s ease-out, transform .3s cubic-bezier(.23, 1, .32, 1); }
.send .ok { color: #142305; opacity: 0; filter: blur(3px); transform: translateY(6px); }
.send .ok svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.send.done .go { opacity: 0; filter: blur(3px); transform: translateY(-6px); }
.send.done .ok { opacity: 1; filter: none; transform: none; transition-delay: .16s; }
@media (hover: hover) and (pointer: fine) {
.send:not(.done):hover { background: #2A252E; }
}
/* the firefly */
.spark { --pulse: 0; position: fixed; left: 0; top: 0; z-index: 6; width: 120px; height: 120px; margin: -60px 0 0 -60px;
pointer-events: none; transition: opacity .15s ease; }
/* every key gives the light one short pulse, on the same frame as the key */
.spark .glow, .spark .body { transition: filter .14s ease-out, scale .14s ease-out; }
.spark .glow { filter: brightness(calc(1 + var(--pulse) * .6)); }
.spark.inside { opacity: 0; }
.spark i { position: absolute; left: 50%; top: 50%; }
.spark .glow { left: 0; top: 0; width: 100%; height: 100%; border-radius: 50%; animation: glow-a 2.3s ease-in-out infinite, glow-b 1.7s ease-in-out infinite alternate;
background: radial-gradient(circle at 50% 56%, rgba(182,255,110,.6), rgba(156,255,60,.2) 22%, rgba(151,255,50,0) 58%); }
@keyframes glow-a { 0%, 100% { opacity: 1; } 18% { opacity: .72; } 34% { opacity: .95; } 61% { opacity: .64; } 78% { opacity: .9; } }
@keyframes glow-b { to { scale: .9; } }
.spark .wing { width: 22px; height: 10px; margin-top: -17px; border-radius: 50%; animation: .07s ease-in-out infinite alternate; }
.spark .wing.l { margin-left: -22px; transform-origin: 100% 60%; background: linear-gradient(270deg, rgba(242,255,230,.45), rgba(242,255,230,.08)); animation-name: flap-l; }
.spark .wing.r { margin-left: 0; transform-origin: 0 60%; background: linear-gradient(90deg, rgba(242,255,230,.45), rgba(242,255,230,.08)); animation-name: flap-r; }
@keyframes flap-l { from { rotate: 8deg; } to { rotate: 38deg; } }
@keyframes flap-r { from { rotate: -8deg; } to { rotate: -38deg; } }
.spark .head { width: 7px; height: 10px; margin: -15px 0 0 -3.5px; border-radius: 50%; background: #202B16; }
.spark .body { width: 22px; height: 24px; margin: -6px 0 0 -11px; border-radius: 50%; scale: calc(1 + var(--pulse) * .2);
background: radial-gradient(circle at 50% 45%, #F6FFEE, rgba(194,255,135,.95) 40%, rgba(161,255,70,0) 72%); }
.ember { position: fixed; z-index: 6; width: 9px; height: 9px; border-radius: 50%; pointer-events: none;
background: radial-gradient(circle, #DEFFBE, rgba(166,255,80,.5) 35%, transparent 70%); }
.trail { position: fixed; z-index: 6; width: 5px; height: 5px; margin: -2.5px 0 0 -2.5px; border-radius: 50%; pointer-events: none;
background: radial-gradient(circle, rgba(222,255,190,.8), rgba(166,255,80,.25) 50%, transparent 72%); }
@media (prefers-reduced-motion: reduce) {
.spark .wing, .spark .glow, .dots i.new, .text b.new { animation: none; }
.login { animation: none; }
.spark .glow, .spark .body { transition: opacity .14s ease-out; filter: none; scale: 1; }
.send span { transform: none !important; }
}
</style>
<div class="night" aria-hidden="true"></div>
<div class="air" aria-hidden="true"></div>
<div class="colony" aria-hidden="true"><i></i><i></i></div>
<form class="login" novalidate>
<div class="field mail">
<input id="email" type="email" name="email" placeholder="Email" autocomplete="username" aria-label="Email">
</div>
<div class="field pass">
<input id="pass" type="password" name="password" placeholder="Password" autocomplete="current-password" aria-label="Password">
<span class="mirror" aria-hidden="true"><span class="dots"></span><span class="text"></span><i class="caret"></i></span>
<button class="eye" type="button" aria-label="Show password" aria-pressed="false">
<svg viewBox="0 0 24 24"><path d="M1.5 12S5.5 4.5 12 4.5 22.5 12 22.5 12 18.5 19.5 12 19.5 1.5 12 1.5 12Z"/><circle cx="12" cy="12" r="3.2"/><path class="slash" d="M3.5 20.5 20.5 3.5"/></svg>
</button>
</div>
<button class="send" type="submit">
<span class="go">Sign in</span>
<span class="ok"><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>You're in</span>
</button>
</form>
<div class="spark" aria-hidden="true"><i class="glow"></i><i class="wing l"></i><i class="wing r"></i><i class="head"></i><i class="body"></i></div>
<script>
/* Firefly Login V3 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
// how long the firefly takes to settle, how loose the
// spring goes in the constellation, the speed that leaves
// a trail, and how long one pulse of typing light lasts
const RESP = 0.34, BOUNCE = 0.62;
const TRAIL = 130, PULSE = 0.14;
const $ = s => document.querySelector(s);
const form = $('.login'), email = $('#email'), pass = $('#pass'), eye = $('.eye'), send = $('.send');
const mailField = email.parentElement, passField = pass.parentElement;
const spark = $('.spark'), night = $('.night'), dots = $('.dots'), text = $('.text'), caret = $('.caret');
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
const wait = ms => new Promise(r => setTimeout(r, ms));
const pen = document.createElement('canvas').getContext('2d');
pen.font = '500 16px system-ui, sans-serif';
// where the firefly goes for each element: it lands on top of a field, into the middle of a button
function at(el) {
const r = el.getBoundingClientRect();
if (el === email || el === pass) return { x: r.left + 22, y: r.top - 4 };
return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
}
// while you type it follows the last character
function caretGoal(input) {
const r = input.getBoundingClientRect(), v = input.value;
if (input === email) return { x: r.left + 24 + Math.min(pen.measureText(v).width, r.width - 70), y: r.top - 4 };
const w = passField.classList.contains('show') ? pen.measureText(v).width + v.length * .5 : v.length * 14 - 7;
return { x: r.left + 18 + Math.min(Math.max(w, 6), r.width - 70), y: r.top + r.height / 2 };
}
let x = -60, y = innerHeight / 2, vx = 0, vy = 0;
let goal = { x, y }, dive = null, idle = true;
let demo = false; // play() turns it on, a touch turns it off
let last = performance.now(), acc = 0, step = 0, party = false;
// the wood: far-off lights out of focus and slow motes of pollen, all decoration
const air = $('.air');
const AIR = [];
{
const add = (cls, n, box) => {
for (let i = 0; i < n; i++) {
const el = document.createElement('i');
el.className = cls + (Math.random() < .38 ? ' warm' : '');
air.append(el);
AIR.push({ el, box, s: Math.random() * 6.28, sx: .5 + Math.random(), sy: .4 + Math.random() * .8,
x0: Math.random(), y0: Math.random(), rise: box === 'mote' ? 40 + Math.random() * 90 : 0,
life: 5 + Math.random() * 5, born: Math.random() * 10 });
}
};
add('far', 16, 'far');
add('mote', 18, 'mote');
}
function wood(now) {
const t = now / 1000;
for (const a of AIR) {
let x = a.x0 * innerWidth + Math.sin(t * .22 * a.sx + a.s) * 26;
let y = a.y0 * innerHeight + Math.sin(t * .18 * a.sy + a.s * 1.7) * 22;
let o = 1;
if (a.box === 'mote') { // motes lift, fade in and out, and start over
const k = ((t - a.born) % a.life) / a.life;
y -= k * a.rise * 3;
o = Math.sin(Math.PI * k) * (.45 + .55 * Math.sin(t * 1.6 + a.s));
} else {
o = .5 + .5 * Math.sin(t * .8 + a.s);
}
if (reduce) { a.el.style.opacity = a.box === 'mote' ? .3 : .5; a.el.style.translate = `${a.x0 * innerWidth}px ${a.y0 * innerHeight}px`; continue; }
a.el.style.opacity = Math.max(0, o).toFixed(3);
a.el.style.translate = `${x}px ${y}px`;
}
}
// the colony: two fireflies on a lazy drift behind the glass. they are decoration,
// so they get a soft spring of their own and never touch the working one
const flies = [...document.querySelectorAll('.colony i')].map((el, i) => ({
el, x: innerWidth * (i ? .72 : .28), y: innerHeight * (i ? .6 : .4), vx: 0, vy: 0, seed: i * 3.1, look: 0,
}));
function lookAt(ms = 900) {
const until = performance.now() + ms;
for (const f of flies) f.look = until;
}
function colony(now) {
const dt = 1 / 60;
for (const f of flies) {
const s = f.seed, tt = reduce ? 0 : now;
const dx = .5 + .3 * Math.sin(tt * .00021 + s)
+ .06 * Math.sin(tt * .00083 + s * 2);
const dy = .5 + .26 * Math.sin(tt * .00017 + s * 1.7)
+ .05 * Math.sin(tt * .00071 + s);
let gx = innerWidth * dx, gy = innerHeight * dy;
if (reduce) {
f.el.style.translate = `${gx}px ${gy}px`;
const t_ = s ? 'b' : 'a';
night.style.setProperty(`--${t_}x`, gx + 'px');
night.style.setProperty(`--${t_}y`, gy + 'px');
continue;
}
if (party) { // the three hold a constellation
const r = send.getBoundingClientRect();
gx = r.left + r.width / 2 + (s ? 86 : -86);
gy = r.top - 34;
} else if (now < f.look) { // they turn to the light
gx += (x + Math.cos(s + now * .001) * 96 - gx) * .8;
gy += (y + Math.sin(s + now * .001) * 72 - gy) * .8;
}
const w = 2 * Math.PI / (party ? .55 : 1.7);
f.vx += (w * w * (gx - f.x) - 2 * w * f.vx) * dt;
f.vy += (w * w * (gy - f.y) - 2 * w * f.vy) * dt;
f.x += f.vx * dt; f.y += f.vy * dt;
f.el.style.translate = `${f.x}px ${f.y}px`;
const tag = s ? 'b' : 'a'; // its own hole in the dark
night.style.setProperty(`--${tag}x`, f.x + 'px');
night.style.setProperty(`--${tag}y`, f.y + 'px');
}
}
// one short pulse of light per key, set on the same frame as the key
let pulseOff;
function pulse() {
spark.style.setProperty('--pulse', 1);
clearTimeout(pulseOff);
pulseOff = setTimeout(() => spark.style.setProperty('--pulse', 0), PULSE * 1000);
}
// until someone uses the form, the firefly just drifts over it
function idleGoal(now) {
const r = form.getBoundingClientRect();
return {
x: r.left + r.width * (.5 + .4 * Math.sin(now * .00037)),
y: r.top - 24 + Math.sin(now * .00052) * 30,
};
}
(function fly(now = performance.now()) {
if (idle && !demo) goal = idleGoal(reduce ? 0 : now); // it holds still with reduced motion
const box = dive && dive.getBoundingClientRect();
acc += Math.min(100, now - last); last = now;
// 60 steps a second on any screen
for (; acc >= 1000 / 60; acc -= 1000 / 60) {
// a critically damped spring: it arrives and stops.
// zeta drops below 1 only in the constellation
const w = 2 * Math.PI / RESP, dt = 1 / 60;
const zeta = party ? BOUNCE : 1;
vx += (w * w * (goal.x - x) - 2 * zeta * w * vx) * dt;
vy += (w * w * (goal.y - y) - 2 * zeta * w * vy) * dt;
x += vx * dt; y += vy * dt;
}
spark.style.translate = `${x}px ${y}px`;
const fast = Math.hypot(vx, vy) > TRAIL;
if (fast && !reduce && ++step % 3 === 0) trail(x, y + 3);
night.style.setProperty('--x', x + 'px');
night.style.setProperty('--y', y + 'px');
const inside = !!box && x > box.left && x < box.right
&& y > box.top && y < box.bottom;
spark.classList.toggle('inside', inside);
if (dive === passField) {
passField.classList.toggle('inside', inside);
if (inside) {
const gx = x - box.left + 'px';
passField.style.setProperty('--gx', gx);
}
}
colony(now);
wood(now);
requestAnimationFrame(fly);
})();
// a faint dot left behind on fast flight, it fades like light on the retina
function trail(tx, ty) {
const d = document.createElement('i'); d.className = 'trail';
d.style.left = tx + 'px'; d.style.top = ty + 'px'; document.body.append(d);
d.animate([{ opacity: .9, scale: 1 }, { opacity: 0, scale: .4 }], { duration: 420, easing: 'ease-out' }).onfinish = () => d.remove();
}
for (const el of [email, pass, eye, send])
el.onfocus = el.onclick = () => { idle = false; goal = at(el); lookAt(); };
email.addEventListener('input', () => { idle = false; goal = caretGoal(email); pulse(); });
function paintPassword(fresh) {
const v = [...pass.value], mark = (node, i) => { if (fresh && i === v.length - 1) node.className = 'new'; return node; };
dots.replaceChildren(...v.map((_, i) => mark(document.createElement('i'), i)));
text.replaceChildren(...v.map((ch, i) => { const b = mark(document.createElement('b'), i); b.textContent = ch; return b; }));
caret.style.translate = (passField.classList.contains('show') ? text.offsetWidth : v.length * 14) + 'px 0';
}
function diveIntoPassword() {
if (!pass.value) { dive = null; passField.classList.remove('inside'); goal = at(pass); return; }
if (dive !== passField) lookAt(1100);
dive = passField; goal = caretGoal(pass);
}
pass.addEventListener('input', () => { idle = false; paintPassword(true); diveIntoPassword(); pulse(); });
pass.addEventListener('focus', diveIntoPassword);
pass.addEventListener('blur', () => { if (dive === passField) { dive = null; passField.classList.remove('inside'); } });
eye.addEventListener('click', () => {
const on = passField.classList.toggle('show');
eye.setAttribute('aria-pressed', on);
eye.setAttribute('aria-label', on ? 'Hide password' : 'Show password');
paintPassword(false);
});
// Put your real request here. Return true when the server accepts the login.
async function signIn(login, password) {
await wait(250);
return true;
// const res = await fetch('/api/login', {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify({ login, password }),
// });
// return res.ok;
}
form.addEventListener('submit', async e => {
e.preventDefault();
if (send.classList.contains('done')) return;
const empty = !email.value ? email : !pass.value ? pass : null;
if (empty) { goal = at(empty); empty.focus(); return; }
dive = send; goal = at(send);
const [ok] = await Promise.all([signIn(email.value, pass.value), wait(300)]);
if (!ok) { dive = null; goal = at(pass); pass.focus(); return; }
send.style.setProperty('--hx', x - send.getBoundingClientRect().left + 'px');
send.classList.add('done');
night.classList.add('day');
party = true; lookAt(2200); // the colony comes in for the constellation
setTimeout(() => { party = false; lookAt(700); }, 1100);
if (!reduce) burst(send);
await wait(750);
dive = null;
const r = send.getBoundingClientRect();
goal = { x: r.left + r.width * .62, y: r.top - 8 };
});
function burst(el) {
const r = el.getBoundingClientRect();
for (let i = 0; i < 28; i++) {
const s = document.createElement('span'), side = Math.random() < .5 ? -1 : 1;
const ang = -Math.PI / 2 + (Math.random() - .5) * 2.9, d = 40 + 110 * Math.random();
s.className = 'ember';
s.style.left = r.left + r.width / 2 + side * r.width * (.15 + .3 * Math.random()) + 'px';
s.style.top = r.top + r.height / 2 + 'px';
document.body.append(s);
s.animate([
{ transform: 'translate(-50%, -50%) scale(1)', opacity: 1 },
{ transform: `translate(calc(-50% + ${Math.cos(ang) * d}px), calc(-50% + ${Math.sin(ang) * d * .8 + 20}px)) scale(.4)`, opacity: 0 },
], { duration: 700 + 500 * Math.random(), delay: 120 * Math.random(), easing: 'cubic-bezier(.23, 1, .32, 1)', fill: 'backwards' })
.onfinish = () => s.remove();
}
}
// demo: plays until you click or type anything
const stopDemo = () => {
if (!demo) return;
demo = false;
mailField.classList.remove('lit'); passField.classList.remove('lit');
reset();
};
addEventListener('pointerdown', stopDemo, true);
addEventListener('keydown', stopDemo, true);
function reset() {
email.value = pass.value = '';
idle = true;
passField.classList.remove('show', 'inside'); eye.setAttribute('aria-pressed', false);
send.classList.remove('done'); night.classList.remove('day');
paintPassword(false); dive = null;
}
async function play() {
demo = true; idle = false;
goal = at(email);
await wait(120); if (!demo) return;
mailField.classList.add('lit'); lookAt(900);
for (const ch of 'codinvisual@example.com') { if (!demo) return; email.value += ch; goal = caretGoal(email); pulse(); await wait(42); }
await wait(300); if (!demo) return;
mailField.classList.remove('lit'); passField.classList.add('lit');
for (const ch of 'fireflies') { if (!demo) return; pass.value += ch; paintPassword(true); diveIntoPassword(); pulse(); await wait(pass.value.length === 1 ? 380 : 72); }
await wait(250); if (!demo) return;
dive = null; passField.classList.remove('inside', 'lit');
goal = { x: at(eye).x, y: passField.getBoundingClientRect().top - 18 };
await wait(320); if (!demo) return;
goal = at(eye);
await wait(300); if (!demo) return;
eye.click();
await wait(380); if (!demo) return;
form.requestSubmit();
await wait(3600); if (!demo) return;
reset(); goal = { x: -60, y: innerHeight / 2 };
await wait(1400); if (demo) play();
}
</script>
Click a field and type. Nothing moves on its own: the firefly drifts over the form until you use it.
What you can change
Change a number, save, and reload the page to see the difference.
RESP0.34How long the firefly takes to settle on its goal, in seconds. Lower is snappier.
BOUNCE0.62How loose the spring goes in the victory constellation, the only place it overshoots.
PULSE0.14How long one pulse of typing light lasts, in seconds.
TRAIL130Speed, in pixels a second, at which the firefly starts leaving a trail.
#A2FF47--The green firefly light. Change it everywhere to retint the effect.
Add it to your site
Sign in and sign up pages, a waitlist form, any dark landing page with a form.
CSS
Paste into your stylesheet, or inside a <style> tag in <head>.
/* Firefly Login V3 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */ /* the dark around the form. every firefly cuts its own hole in it, the working one a wide one */ .night { position: fixed; inset: 0; z-index: 5; pointer-events: none; transition: opacity .6s ease; background: rgba(7,6,10,.78); -webkit-mask-image: radial-gradient(circle at var(--x, -200px) var(--y, 50%), transparent 0, rgba(0,0,0,.45) 95px, #000 190px), radial-gradient(circle at var(--ax, -200px) var(--ay, 50%), transparent 0, rgba(0,0,0,.5) 34px, #000 120px), radial-gradient(circle at var(--bx, -200px) var(--by, 50%), transparent 0, rgba(0,0,0,.5) 34px, #000 120px); mask-image: radial-gradient(circle at var(--x, -200px) var(--y, 50%), transparent 0, rgba(0,0,0,.45) 95px, #000 190px), radial-gradient(circle at var(--ax, -200px) var(--ay, 50%), transparent 0, rgba(0,0,0,.5) 34px, #000 120px), radial-gradient(circle at var(--bx, -200px) var(--by, 50%), transparent 0, rgba(0,0,0,.5) 34px, #000 120px); -webkit-mask-composite: source-in; mask-composite: intersect; } .night.day { opacity: .35; } /* the wood behind the glass: far-off lights out of focus, and slow motes of pollen */ .air { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; } .air i { position: absolute; left: 0; top: 0; border-radius: 50%; } .air .far { width: 26px; height: 26px; margin: -13px 0 0 -13px; filter: blur(7px); background: radial-gradient(circle, rgba(182,255,130,.5), rgba(120,255,90,0) 70%); } .air .far.warm { background: radial-gradient(circle, rgba(255,224,150,.5), rgba(255,200,90,0) 70%); } .air .mote { width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; filter: blur(1.4px); background: radial-gradient(circle, rgba(206,255,150,.85), rgba(162,255,71,0) 70%); } .air .mote.warm { background: radial-gradient(circle, rgba(255,236,178,.85), rgba(255,210,120,0) 70%); } /* the colony: two more fireflies, drifting behind the glass */ .colony { position: fixed; inset: 0; z-index: 1; pointer-events: none; } .colony i { position: absolute; left: 0; top: 0; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%; background: radial-gradient(circle, rgba(222,255,190,.8), rgba(162,255,71,.35) 42%, rgba(151,255,50,0) 72%); filter: blur(4px); opacity: .62; } /* the form is a sheet of glass: the far fireflies read through it, blurred and dimmer */ .login { position: relative; z-index: 2; box-sizing: border-box; width: min(360px, 92vw); display: grid; gap: 16px; margin: 0; padding: 22px; border-radius: 22px; background: rgba(14,26,18,.42); -webkit-backdrop-filter: blur(14px) saturate(140%); backdrop-filter: blur(14px) saturate(140%); box-shadow: inset 0 1px 0 rgba(214,255,190,.22), inset 0 0 0 1px rgba(162,255,71,.1), 0 30px 60px -30px rgba(0,0,0,.9); animation: materialize .5s cubic-bezier(.23, 1, .32, 1); } /* a sheet of glass arrives as a material: blur and scale together, not a plain fade */ @keyframes materialize { from { opacity: 0; transform: scale(.96); filter: blur(10px); } } .field { position: relative; height: 52px; border-radius: 14px; background: #16141A; overflow: hidden; box-shadow: inset 0 0 0 1.2px rgba(255,238,215,.11); transition: box-shadow .3s cubic-bezier(.23, 1, .32, 1); } .field:focus-within, .field.lit { box-shadow: inset 0 0 0 1.6px rgba(174,255,95,.9), 0 0 0 4px rgba(162,255,71,.16); } /* light under the surface while the firefly is inside the field */ .field::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .2s ease; background: radial-gradient(90px 46px at var(--gx, -100px) 50%, rgba(176,255,100,.4), rgba(156,255,60,.1) 50%, transparent 75%); } .field.inside::before { opacity: 1; } .field input { position: relative; box-sizing: border-box; width: 100%; height: 100%; padding: 0 52px 0 18px; border: 0; outline: 0; background: transparent; font: 500 16px system-ui, sans-serif; color: #F4EFE6; caret-color: #A2FF47; } .field input::placeholder { color: rgba(205,195,180,.45); } /* password: the real input stays type="password", what you see is drawn next to it */ .pass input { color: transparent; caret-color: transparent; } .mirror { position: absolute; left: 18px; right: 52px; top: 0; bottom: 0; pointer-events: none; overflow: hidden; font: 500 16px system-ui, sans-serif; } .dots, .text { position: absolute; left: 0; top: 0; bottom: 0; display: flex; align-items: center; white-space: pre; transition: opacity .3s cubic-bezier(.77, 0, .175, 1), filter .3s cubic-bezier(.77, 0, .175, 1); } .dots i { flex: none; width: 14px; height: 14px; display: grid; place-items: center; } .dots i::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #F4EFE6; } .text { opacity: 0; filter: blur(3px); letter-spacing: .5px; } .text b { font-weight: 500; } .show .dots { opacity: 0; filter: blur(3px); } .show .text { opacity: 1; filter: none; } .dots i.new, .text b.new { animation: flash .5s cubic-bezier(.23, 1, .32, 1); } @keyframes flash { from { filter: drop-shadow(0 0 5px #B6FF6E) brightness(1.7); } } .caret { position: absolute; left: 0; top: 16px; width: 2px; height: 20px; background: #A2FF47; opacity: 0; } .pass:focus-within .caret { opacity: 1; animation: blink 1s steps(1) infinite; } @keyframes blink { 50% { opacity: 0; } } .eye { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 10px; background: transparent; display: grid; place-items: center; cursor: pointer; color: rgba(235,228,215,.55); transition: color .2s ease, transform .16s ease-out; } .eye:active { transform: scale(.94); } .eye:focus-visible { outline: 2px solid #A2FF47; outline-offset: 1px; } .eye svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; } .eye .slash { stroke-dasharray: 26; stroke-dashoffset: 0; transition: stroke-dashoffset .25s cubic-bezier(.23, 1, .32, 1); } .show .eye { color: #AEFF5F; } .show .eye .slash { stroke-dashoffset: 26; } /* the button fills with light from the point where the firefly dove in */ .send { position: relative; height: 54px; border: 0; border-radius: 27px; background: #211D24; box-shadow: inset 0 0 0 1.2px rgba(255,238,215,.10); color: #EFE8DC; font: 600 16px system-ui, sans-serif; cursor: pointer; overflow: hidden; transition: transform .16s ease-out; } .send:active { transform: scale(.97); } .send:focus-visible { outline: 2px solid #A2FF47; outline-offset: 3px; } .send::before { content: ""; position: absolute; inset: 0; background: linear-gradient(#B9FF74, #9BFF3A); clip-path: circle(0 at var(--hx, 50%) 50%); transition: clip-path .5s cubic-bezier(.23, 1, .32, 1); } .send.done::before { clip-path: circle(150% at var(--hx, 50%) 50%); } .send span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 8px; transition: opacity .3s ease-out, filter .3s ease-out, transform .3s cubic-bezier(.23, 1, .32, 1); } .send .ok { color: #142305; opacity: 0; filter: blur(3px); transform: translateY(6px); } .send .ok svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; } .send.done .go { opacity: 0; filter: blur(3px); transform: translateY(-6px); } .send.done .ok { opacity: 1; filter: none; transform: none; transition-delay: .16s; } @media (hover: hover) and (pointer: fine) { .send:not(.done):hover { background: #2A252E; } } /* the firefly */ .spark { --pulse: 0; position: fixed; left: 0; top: 0; z-index: 6; width: 120px; height: 120px; margin: -60px 0 0 -60px; pointer-events: none; transition: opacity .15s ease; } /* every key gives the light one short pulse, on the same frame as the key */ .spark .glow, .spark .body { transition: filter .14s ease-out, scale .14s ease-out; } .spark .glow { filter: brightness(calc(1 + var(--pulse) * .6)); } .spark.inside { opacity: 0; } .spark i { position: absolute; left: 50%; top: 50%; } .spark .glow { left: 0; top: 0; width: 100%; height: 100%; border-radius: 50%; animation: glow-a 2.3s ease-in-out infinite, glow-b 1.7s ease-in-out infinite alternate; background: radial-gradient(circle at 50% 56%, rgba(182,255,110,.6), rgba(156,255,60,.2) 22%, rgba(151,255,50,0) 58%); } @keyframes glow-a { 0%, 100% { opacity: 1; } 18% { opacity: .72; } 34% { opacity: .95; } 61% { opacity: .64; } 78% { opacity: .9; } } @keyframes glow-b { to { scale: .9; } } .spark .wing { width: 22px; height: 10px; margin-top: -17px; border-radius: 50%; animation: .07s ease-in-out infinite alternate; } .spark .wing.l { margin-left: -22px; transform-origin: 100% 60%; background: linear-gradient(270deg, rgba(242,255,230,.45), rgba(242,255,230,.08)); animation-name: flap-l; } .spark .wing.r { margin-left: 0; transform-origin: 0 60%; background: linear-gradient(90deg, rgba(242,255,230,.45), rgba(242,255,230,.08)); animation-name: flap-r; } @keyframes flap-l { from { rotate: 8deg; } to { rotate: 38deg; } } @keyframes flap-r { from { rotate: -8deg; } to { rotate: -38deg; } } .spark .head { width: 7px; height: 10px; margin: -15px 0 0 -3.5px; border-radius: 50%; background: #202B16; } .spark .body { width: 22px; height: 24px; margin: -6px 0 0 -11px; border-radius: 50%; scale: calc(1 + var(--pulse) * .2); background: radial-gradient(circle at 50% 45%, #F6FFEE, rgba(194,255,135,.95) 40%, rgba(161,255,70,0) 72%); } .ember { position: fixed; z-index: 6; width: 9px; height: 9px; border-radius: 50%; pointer-events: none; background: radial-gradient(circle, #DEFFBE, rgba(166,255,80,.5) 35%, transparent 70%); } .trail { position: fixed; z-index: 6; width: 5px; height: 5px; margin: -2.5px 0 0 -2.5px; border-radius: 50%; pointer-events: none; background: radial-gradient(circle, rgba(222,255,190,.8), rgba(166,255,80,.25) 50%, transparent 72%); } @media (prefers-reduced-motion: reduce) { .spark .wing, .spark .glow, .dots i.new, .text b.new { animation: none; } .login { animation: none; } .spark .glow, .spark .body { transition: opacity .14s ease-out; filter: none; scale: 1; } .send span { transform: none !important; } }HTML
Put it where the effect should appear on your page.
<div class="night" aria-hidden="true"></div> <div class="air" aria-hidden="true"></div> <div class="colony" aria-hidden="true"><i></i><i></i></div> <form class="login" novalidate> <div class="field mail"> <input id="email" type="email" name="email" placeholder="Email" autocomplete="username" aria-label="Email"> </div> <div class="field pass"> <input id="pass" type="password" name="password" placeholder="Password" autocomplete="current-password" aria-label="Password"> <span class="mirror" aria-hidden="true"><span class="dots"></span><span class="text"></span><i class="caret"></i></span> <button class="eye" type="button" aria-label="Show password" aria-pressed="false"> <svg viewBox="0 0 24 24"><path d="M1.5 12S5.5 4.5 12 4.5 22.5 12 22.5 12 18.5 19.5 12 19.5 1.5 12 1.5 12Z"/><circle cx="12" cy="12" r="3.2"/><path class="slash" d="M3.5 20.5 20.5 3.5"/></svg> </button> </div> <button class="send" type="submit"> <span class="go">Sign in</span> <span class="ok"><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>You're in</span> </button> </form> <div class="spark" aria-hidden="true"><i class="glow"></i><i class="wing l"></i><i class="wing r"></i><i class="head"></i><i class="body"></i></div>JavaScript
Paste right before the closing </body> tag, inside <script></script>.
/* Firefly Login V3 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */ // how long the firefly takes to settle, how loose the // spring goes in the constellation, the speed that leaves // a trail, and how long one pulse of typing light lasts const RESP = 0.34, BOUNCE = 0.62; const TRAIL = 130, PULSE = 0.14; const $ = s => document.querySelector(s); const form = $('.login'), email = $('#email'), pass = $('#pass'), eye = $('.eye'), send = $('.send'); const mailField = email.parentElement, passField = pass.parentElement; const spark = $('.spark'), night = $('.night'), dots = $('.dots'), text = $('.text'), caret = $('.caret'); const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches; const wait = ms => new Promise(r => setTimeout(r, ms)); const pen = document.createElement('canvas').getContext('2d'); pen.font = '500 16px system-ui, sans-serif'; // where the firefly goes for each element: it lands on top of a field, into the middle of a button function at(el) { const r = el.getBoundingClientRect(); if (el === email || el === pass) return { x: r.left + 22, y: r.top - 4 }; return { x: r.left + r.width / 2, y: r.top + r.height / 2 }; } // while you type it follows the last character function caretGoal(input) { const r = input.getBoundingClientRect(), v = input.value; if (input === email) return { x: r.left + 24 + Math.min(pen.measureText(v).width, r.width - 70), y: r.top - 4 }; const w = passField.classList.contains('show') ? pen.measureText(v).width + v.length * .5 : v.length * 14 - 7; return { x: r.left + 18 + Math.min(Math.max(w, 6), r.width - 70), y: r.top + r.height / 2 }; } let x = -60, y = innerHeight / 2, vx = 0, vy = 0; let goal = { x, y }, dive = null, idle = true; let demo = false; // play() turns it on, a touch turns it off let last = performance.now(), acc = 0, step = 0, party = false; // the wood: far-off lights out of focus and slow motes of pollen, all decoration const air = $('.air'); const AIR = []; { const add = (cls, n, box) => { for (let i = 0; i < n; i++) { const el = document.createElement('i'); el.className = cls + (Math.random() < .38 ? ' warm' : ''); air.append(el); AIR.push({ el, box, s: Math.random() * 6.28, sx: .5 + Math.random(), sy: .4 + Math.random() * .8, x0: Math.random(), y0: Math.random(), rise: box === 'mote' ? 40 + Math.random() * 90 : 0, life: 5 + Math.random() * 5, born: Math.random() * 10 }); } }; add('far', 16, 'far'); add('mote', 18, 'mote'); } function wood(now) { const t = now / 1000; for (const a of AIR) { let x = a.x0 * innerWidth + Math.sin(t * .22 * a.sx + a.s) * 26; let y = a.y0 * innerHeight + Math.sin(t * .18 * a.sy + a.s * 1.7) * 22; let o = 1; if (a.box === 'mote') { // motes lift, fade in and out, and start over const k = ((t - a.born) % a.life) / a.life; y -= k * a.rise * 3; o = Math.sin(Math.PI * k) * (.45 + .55 * Math.sin(t * 1.6 + a.s)); } else { o = .5 + .5 * Math.sin(t * .8 + a.s); } if (reduce) { a.el.style.opacity = a.box === 'mote' ? .3 : .5; a.el.style.translate = `${a.x0 * innerWidth}px ${a.y0 * innerHeight}px`; continue; } a.el.style.opacity = Math.max(0, o).toFixed(3); a.el.style.translate = `${x}px ${y}px`; } } // the colony: two fireflies on a lazy drift behind the glass. they are decoration, // so they get a soft spring of their own and never touch the working one const flies = [...document.querySelectorAll('.colony i')].map((el, i) => ({ el, x: innerWidth * (i ? .72 : .28), y: innerHeight * (i ? .6 : .4), vx: 0, vy: 0, seed: i * 3.1, look: 0, })); function lookAt(ms = 900) { const until = performance.now() + ms; for (const f of flies) f.look = until; } function colony(now) { const dt = 1 / 60; for (const f of flies) { const s = f.seed, tt = reduce ? 0 : now; const dx = .5 + .3 * Math.sin(tt * .00021 + s) + .06 * Math.sin(tt * .00083 + s * 2); const dy = .5 + .26 * Math.sin(tt * .00017 + s * 1.7) + .05 * Math.sin(tt * .00071 + s); let gx = innerWidth * dx, gy = innerHeight * dy; if (reduce) { f.el.style.translate = `${gx}px ${gy}px`; const t_ = s ? 'b' : 'a'; night.style.setProperty(`--${t_}x`, gx + 'px'); night.style.setProperty(`--${t_}y`, gy + 'px'); continue; } if (party) { // the three hold a constellation const r = send.getBoundingClientRect(); gx = r.left + r.width / 2 + (s ? 86 : -86); gy = r.top - 34; } else if (now < f.look) { // they turn to the light gx += (x + Math.cos(s + now * .001) * 96 - gx) * .8; gy += (y + Math.sin(s + now * .001) * 72 - gy) * .8; } const w = 2 * Math.PI / (party ? .55 : 1.7); f.vx += (w * w * (gx - f.x) - 2 * w * f.vx) * dt; f.vy += (w * w * (gy - f.y) - 2 * w * f.vy) * dt; f.x += f.vx * dt; f.y += f.vy * dt; f.el.style.translate = `${f.x}px ${f.y}px`; const tag = s ? 'b' : 'a'; // its own hole in the dark night.style.setProperty(`--${tag}x`, f.x + 'px'); night.style.setProperty(`--${tag}y`, f.y + 'px'); } } // one short pulse of light per key, set on the same frame as the key let pulseOff; function pulse() { spark.style.setProperty('--pulse', 1); clearTimeout(pulseOff); pulseOff = setTimeout(() => spark.style.setProperty('--pulse', 0), PULSE * 1000); } // until someone uses the form, the firefly just drifts over it function idleGoal(now) { const r = form.getBoundingClientRect(); return { x: r.left + r.width * (.5 + .4 * Math.sin(now * .00037)), y: r.top - 24 + Math.sin(now * .00052) * 30, }; } (function fly(now = performance.now()) { if (idle && !demo) goal = idleGoal(reduce ? 0 : now); // it holds still with reduced motion const box = dive && dive.getBoundingClientRect(); acc += Math.min(100, now - last); last = now; // 60 steps a second on any screen for (; acc >= 1000 / 60; acc -= 1000 / 60) { // a critically damped spring: it arrives and stops. // zeta drops below 1 only in the constellation const w = 2 * Math.PI / RESP, dt = 1 / 60; const zeta = party ? BOUNCE : 1; vx += (w * w * (goal.x - x) - 2 * zeta * w * vx) * dt; vy += (w * w * (goal.y - y) - 2 * zeta * w * vy) * dt; x += vx * dt; y += vy * dt; } spark.style.translate = `${x}px ${y}px`; const fast = Math.hypot(vx, vy) > TRAIL; if (fast && !reduce && ++step % 3 === 0) trail(x, y + 3); night.style.setProperty('--x', x + 'px'); night.style.setProperty('--y', y + 'px'); const inside = !!box && x > box.left && x < box.right && y > box.top && y < box.bottom; spark.classList.toggle('inside', inside); if (dive === passField) { passField.classList.toggle('inside', inside); if (inside) { const gx = x - box.left + 'px'; passField.style.setProperty('--gx', gx); } } colony(now); wood(now); requestAnimationFrame(fly); })(); // a faint dot left behind on fast flight, it fades like light on the retina function trail(tx, ty) { const d = document.createElement('i'); d.className = 'trail'; d.style.left = tx + 'px'; d.style.top = ty + 'px'; document.body.append(d); d.animate([{ opacity: .9, scale: 1 }, { opacity: 0, scale: .4 }], { duration: 420, easing: 'ease-out' }).onfinish = () => d.remove(); } for (const el of [email, pass, eye, send]) el.onfocus = el.onclick = () => { idle = false; goal = at(el); lookAt(); }; email.addEventListener('input', () => { idle = false; goal = caretGoal(email); pulse(); }); function paintPassword(fresh) { const v = [...pass.value], mark = (node, i) => { if (fresh && i === v.length - 1) node.className = 'new'; return node; }; dots.replaceChildren(...v.map((_, i) => mark(document.createElement('i'), i))); text.replaceChildren(...v.map((ch, i) => { const b = mark(document.createElement('b'), i); b.textContent = ch; return b; })); caret.style.translate = (passField.classList.contains('show') ? text.offsetWidth : v.length * 14) + 'px 0'; } function diveIntoPassword() { if (!pass.value) { dive = null; passField.classList.remove('inside'); goal = at(pass); return; } if (dive !== passField) lookAt(1100); dive = passField; goal = caretGoal(pass); } pass.addEventListener('input', () => { idle = false; paintPassword(true); diveIntoPassword(); pulse(); }); pass.addEventListener('focus', diveIntoPassword); pass.addEventListener('blur', () => { if (dive === passField) { dive = null; passField.classList.remove('inside'); } }); eye.addEventListener('click', () => { const on = passField.classList.toggle('show'); eye.setAttribute('aria-pressed', on); eye.setAttribute('aria-label', on ? 'Hide password' : 'Show password'); paintPassword(false); }); // Put your real request here. Return true when the server accepts the login. async function signIn(login, password) { await wait(250); return true; // const res = await fetch('/api/login', { // method: 'POST', // headers: { 'Content-Type': 'application/json' }, // body: JSON.stringify({ login, password }), // }); // return res.ok; } form.addEventListener('submit', async e => { e.preventDefault(); if (send.classList.contains('done')) return; const empty = !email.value ? email : !pass.value ? pass : null; if (empty) { goal = at(empty); empty.focus(); return; } dive = send; goal = at(send); const [ok] = await Promise.all([signIn(email.value, pass.value), wait(300)]); if (!ok) { dive = null; goal = at(pass); pass.focus(); return; } send.style.setProperty('--hx', x - send.getBoundingClientRect().left + 'px'); send.classList.add('done'); night.classList.add('day'); party = true; lookAt(2200); // the colony comes in for the constellation setTimeout(() => { party = false; lookAt(700); }, 1100); if (!reduce) burst(send); await wait(750); dive = null; const r = send.getBoundingClientRect(); goal = { x: r.left + r.width * .62, y: r.top - 8 }; }); function burst(el) { const r = el.getBoundingClientRect(); for (let i = 0; i < 28; i++) { const s = document.createElement('span'), side = Math.random() < .5 ? -1 : 1; const ang = -Math.PI / 2 + (Math.random() - .5) * 2.9, d = 40 + 110 * Math.random(); s.className = 'ember'; s.style.left = r.left + r.width / 2 + side * r.width * (.15 + .3 * Math.random()) + 'px'; s.style.top = r.top + r.height / 2 + 'px'; document.body.append(s); s.animate([ { transform: 'translate(-50%, -50%) scale(1)', opacity: 1 }, { transform: `translate(calc(-50% + ${Math.cos(ang) * d}px), calc(-50% + ${Math.sin(ang) * d * .8 + 20}px)) scale(.4)`, opacity: 0 }, ], { duration: 700 + 500 * Math.random(), delay: 120 * Math.random(), easing: 'cubic-bezier(.23, 1, .32, 1)', fill: 'backwards' }) .onfinish = () => s.remove(); } } // demo: plays until you click or type anything const stopDemo = () => { if (!demo) return; demo = false; mailField.classList.remove('lit'); passField.classList.remove('lit'); reset(); }; addEventListener('pointerdown', stopDemo, true); addEventListener('keydown', stopDemo, true); function reset() { email.value = pass.value = ''; idle = true; passField.classList.remove('show', 'inside'); eye.setAttribute('aria-pressed', false); send.classList.remove('done'); night.classList.remove('day'); paintPassword(false); dive = null; } async function play() { demo = true; idle = false; goal = at(email); await wait(120); if (!demo) return; mailField.classList.add('lit'); lookAt(900); for (const ch of 'codinvisual@example.com') { if (!demo) return; email.value += ch; goal = caretGoal(email); pulse(); await wait(42); } await wait(300); if (!demo) return; mailField.classList.remove('lit'); passField.classList.add('lit'); for (const ch of 'fireflies') { if (!demo) return; pass.value += ch; paintPassword(true); diveIntoPassword(); pulse(); await wait(pass.value.length === 1 ? 380 : 72); } await wait(250); if (!demo) return; dive = null; passField.classList.remove('inside', 'lit'); goal = { x: at(eye).x, y: passField.getBoundingClientRect().top - 18 }; await wait(320); if (!demo) return; goal = at(eye); await wait(300); if (!demo) return; eye.click(); await wait(380); if (!demo) return; form.requestSubmit(); await wait(3600); if (!demo) return; reset(); goal = { x: -60, y: innerHeight / 2 }; await wait(1400); if (demo) play(); }
Connect it to your backend
Send the login and password from signIn() to your server and return true when they are correct. Never check passwords in the browser on a live site.
Good to know
- The working firefly runs on a critically damped spring, so it arrives and stops without overshoot; the only bounce in the whole effect is the victory constellation.
- The two background fireflies are decoration: their own soft spring, a lazy drift, and a short turn toward the light whenever a field is focused or the password is opened. On the win the three of them come together and the air lights up.
- The form is a sheet of glass with backdrop-filter, so the far fireflies read through it blurred and dimmer while the working one stays sharp in front.
- The panel materialises with blur and scale together, not a plain fade.
- Every key gives the light one short pulse, set on the same frame as the key.
- With reduced motion the background fireflies hold still, the pulse is opacity only, and the drift and the constellation are skipped.
- Behind the glass there is a wood of far-off lights out of focus and slow motes of pollen drifting up, so the scene reads as a place, not a black rectangle.
- The file does not play itself: the fields stay empty and the firefly just drifts until someone uses the form. Adding play() at the end of the script turns the demo on.
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.



