Liquid Metal Login V4
The liquid metal login learns to say no. A wrong password drops rings into the chrome from where you pressed, the metal flushes red and says so, then the form opens again with the password field cleared and focused.
- Sign in & forms
- Free
- webgl
- liquid metal
- Added Sep 24, 2026
<style>
/* Liquid Metal Login V4 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
.mercury { position: relative; width: min(460px, calc(100vw - 32px)); aspect-ratio: 540 / 440; margin: 0; }
.mercury canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
/* everything below is laid out at 540 x 440 and scaled to the form width by the script */
.mercury .ui { position: absolute; left: 0; top: 0; width: 540px; height: 440px; transform-origin: 0 0; }
.mercury .go { position: absolute; left: 52px; top: 168px; width: 436px; height: 104px; padding: 0; border: 0; border-radius: 52px; background: none; cursor: pointer;
display: flex; align-items: center; justify-content: center; gap: 10px; font: 650 31px system-ui, sans-serif; color: #0B0D10;
text-shadow: 0 1.2px 0 rgba(255,255,255,.45); transition: opacity .15s ease-out; -webkit-tap-highlight-color: transparent; }
.mercury .go:focus-visible { outline: 2px solid #6CEBD9; outline-offset: 6px; }
.mercury .go svg { display: none; width: 30px; height: 30px; }
.mercury[data-state="done"] .go svg { display: block; }
.mercury[data-state="opening"] .go, .mercury[data-state="open"] .go, .mercury[data-state="closing"] .go { opacity: 0; pointer-events: none; }
.mercury .field { position: absolute; left: 38px; width: 464px; height: 88px; box-sizing: border-box; padding: 14px 26px 0; opacity: 0; pointer-events: none; transition: opacity .2s ease-out; }
.mercury[data-state="open"] .field { opacity: 1; pointer-events: auto; }
.mercury .f1 { top: 120px; }
.mercury .f2 { top: 232px; }
.mercury label { display: block; font: 500 17px system-ui, sans-serif; color: #8A93A3; }
.mercury[data-state="wrong"] .go { color: #FFF1F2; text-shadow: 0 1.2px 0 rgba(70,0,10,.55); }
.mercury .f2.warn label { color: #FF6B76; }
.mercury input { display: block; width: 100%; margin: 6px 0 0; padding: 0; border: 0; outline: 0; background: none; font: 500 25px system-ui, sans-serif; color: #F3F5F8; caret-color: #6CEBD9; }
</style>
<form class="mercury" id="mercury" data-state="idle" novalidate>
<canvas></canvas>
<div class="ui">
<div class="field f1"><label for="m-user">Username</label><input id="m-user" name="username" type="text" autocomplete="username" autocapitalize="off" spellcheck="false" tabindex="-1"></div>
<div class="field f2"><label for="m-pass">Password</label><input id="m-pass" name="password" type="password" autocomplete="current-password" tabindex="-1"></div>
<button class="go" type="button"><svg viewBox="0 0 30 30"><path d="M7 15.5l5 5L23 9.5" fill="none" stroke="#0B0D10" stroke-width="3.4" stroke-linecap="round" stroke-linejoin="round"/></svg><span>Sign in</span></button>
</div>
</form>
<script>
/* Liquid Metal Login V4 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
(() => {
const STRETCH = 240, SNAP = 0.94, RIPPLE = 1.15;
const DEMO_PASSWORD = 'Tr0ub4dor&3'; // the demo's only right answer, delete it once your server checks
const form = document.getElementById('mercury'), cv = form.querySelector('canvas'), ui = form.querySelector('.ui');
const btn = form.querySelector('.go'), label = btn.querySelector('span');
const f2 = form.querySelector('.f2'), passLabel = f2.querySelector('label');
const still = matchMedia('(prefers-reduced-motion: reduce)');
const user = form.querySelector('#m-user'), pass = form.querySelector('#m-pass');
const CX = 270, CY = 220, HW = 232, HR = 218, PH = 52, HH = 26, FH = 44, FGAP = 24, W0 = 192;
const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x));
const lerp = (a, b, k) => a + (b - a) * k;
const eout = k => 1 - Math.pow(1 - clamp(k), 3);
const eio = k => (k = clamp(k), k < .5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2);
const spring = (s, w, z) => s <= 0 ? 0 : 1 - Math.exp(-z * w * s) * (Math.cos(w * Math.sqrt(1 - z * z) * s) + z / Math.sqrt(1 - z * z) * Math.sin(w * Math.sqrt(1 - z * z) * s));
const FS = `#version 300 es
precision highp float;
uniform vec4 A, B, NECK, FX, ERR;
uniform vec3 KEY;
uniform vec2 RAD, P, ACT, RES;
uniform float THICK, rest, waist, snap, win, field, SCALE;
out vec4 o;
const float MELT = 24.;
const vec3 VIEW = vec3(0., 0., 1.), TINT = vec3(.42, 1., .9), ACCENT = vec3(.42, .92, .85);
const vec3 RED = vec3(1., .26, .3);
const vec2 C = vec2(270., 220.);
float box(vec2 p, vec2 b, vec4 r) {
r.xy = p.x > 0. ? r.xy : r.zw;
r.x = p.y > 0. ? r.x : r.y;
vec2 q = abs(p) - b + r.x;
return min(max(q.x, q.y), 0.) + length(max(q, 0.)) - r.x;
}
// a wrong password drops rings into the metal that run out from where you pressed and die away
float ripple(vec2 p) {
vec2 q = (p - ERR.zw) / vec2(1., .6);
float run = length(q) - 190. * ERR.x;
return cos(run * .12) * exp(-run * run / 1800.)
* exp(-ERR.x * 1.6) * step(0., ERR.x);
}
vec2 pill(vec2 p) { return vec2(box(p - C, P, vec4(P.y)) - 2.2 * rest * ripple(p), P.y); }
vec2 top(vec2 p) { return mix(vec2(box(p - A.xy, A.zw, RAD.yxyx), THICK), pill(p), rest); }
vec2 bot(vec2 p) { return mix(vec2(box(p - B.xy, B.zw, RAD.xyxy), THICK), pill(p), rest); }
vec2 join(vec2 a, vec2 b) { return a.x < b.x ? a : b; }
vec2 smin(vec2 a, vec2 b, float k) {
float h = clamp(.5 + .5 * (b.x - a.x) / k, 0., 1.);
return vec2(mix(b.x, a.x, h) - k * h * (1. - h), mix(b.y, a.y, h));
}
vec2 neck(vec2 p, float w) {
if (max(NECK.z, w) <= 0.) return vec2(1e5, 1.);
float y0 = NECK.x - A.w, y1 = NECK.y + B.w, len = max(y1 - y0, 1.);
float u = abs(2. * (p.y - y0) / len - 1.);
float rad = w + (NECK.z - w) * u * u, k = 4. * (NECK.z - w) * u / len;
float d = max((abs(p.x - C.x) - rad) / sqrt(1. + k * k), abs(p.y - (y0 + y1) * .5) - len * .5);
return vec2(d, max(rad, 1.5));
}
vec2 drops(vec2 p, float s) {
if (s <= 0. || s >= 1.) return vec2(1e5, 1.);
float k = s * s * (3. - 2. * s), mid = (NECK.x + NECK.y) * .5, r = 6. * (1. - .6 * s);
float a = length(p - vec2(C.x - 2., mix(mid - 6., NECK.x, k))) - r;
float b = length(p - vec2(C.x + 2., mix(mid + 6., NECK.y, k))) - r * .8;
return vec2(min(a, b), r);
}
vec2 shape(vec2 p) {
vec2 d = join(top(p), bot(p));
d = smin(d, neck(p, waist), MELT);
d = smin(d, drops(p, snap), MELT);
return d;
}
// the snap sends a shiver along both halves, out from where the neck let go
float shiver(vec2 p) {
float run = abs(p.x - C.x) - 260. * FX.w;
float edge = min(abs(p.y - NECK.x), abs(p.y - NECK.y));
return cos(run * .1) * exp(-run * run / 1400.) * exp(-FX.w * 2.4)
* exp(-edge * edge / 900.) * step(0., FX.w);
}
// between the two halves the metal is a round column that thins toward its waist, so it is lit like one
vec4 column(vec2 p) {
if (max(NECK.z, waist) <= 0. || p.y < NECK.x || p.y > NECK.y) return vec4(0.);
float y0 = NECK.x - A.w, y1 = NECK.y + B.w, len = max(y1 - y0, 1.);
float v = 2. * (p.y - y0) / len - 1.;
float rad = max(waist + (NECK.z - waist) * v * v, 1.5);
float slope = 4. * (NECK.z - waist) * v / len;
float sx = clamp((p.x - C.x) / rad, -1., 1.);
vec3 n = normalize(vec3(sx, -slope, sqrt(max(1. - sx * sx, 0.))));
float edge = min(p.y - NECK.x, NECK.y - p.y);
return vec4(n, smoothstep(-2., 5., edge) * smoothstep(1.5, -1.5, abs(p.x - C.x) - rad) * (1. - field));
}
vec3 normal(vec2 p, float s) {
vec2 e = vec2(.4, 0.);
vec2 g = vec2(shape(p + e.xy).x - shape(p - e.xy).x, shape(p + e.yx).x - shape(p - e.yx).x);
float slope = min((1. - s) / sqrt(max(1. - (1. - s) * (1. - s), 1e-4)), 14.);
vec2 dome = vec2((p.x - C.x) / P.x * .32 * (1. - field), 0.);
vec2 h = vec2(ripple(p + e.xy) - ripple(p - e.xy), ripple(p + e.yx) - ripple(p - e.yx)) / (2. * e.x);
vec2 v = vec2(shiver(p + e.xy) - shiver(p - e.xy), shiver(p + e.yx) - shiver(p - e.yx)) / (2. * e.x);
vec3 n = normalize(vec3(normalize(g + 1e-6) * slope + dome - h * 9. * rest - v * 7. * (1. - field), 1.));
vec4 c = column(p);
return normalize(mix(n, c.xyz, c.w));
}
float fresnel(float c) { return mix(.8, 1., pow(1. - c, 5.)); }
vec3 env(vec3 r) {
float el = asin(clamp(-r.y, -1., 1.)), az = atan(r.x, r.z);
float h = el + .45;
vec3 sky = mix(vec3(.58, .62, .7), vec3(.96, .98, 1.04), smoothstep(0., .8, h));
sky = mix(sky, vec3(.16, .17, .2), smoothstep(.62, .78, el) * smoothstep(1.02, .92, el));
sky = mix(sky, vec3(.42, .45, .52), smoothstep(1.3, 1.45, el));
vec3 grd = mix(vec3(.05, .045, .05), vec3(.012, .013, .016), smoothstep(0., .5, -h));
vec3 c = mix(grd, sky, smoothstep(-.012, .012, h)) + vec3(.7) * exp(-abs(h) * 45.);
c += vec3(1.8) * smoothstep(.95, 1.0, el) * smoothstep(1.3, 1.24, el);
c = mix(c, vec3(.02, .022, .03) + vec3(.06) * smoothstep(-.2, .6, -r.y), smoothstep(.05, -.35, r.z));
c += vec3(1., .5, .3) * 1.1 * exp(-pow((az + 1.75) * 1.8, 2.)) * exp(-pow((el - .12) * 2.6, 2.));
c += ACCENT * 1.1 * exp(-pow((az - 1.75) * 1.8, 2.)) * exp(-pow((el - .06) * 2.6, 2.));
float back = smoothstep(.1, -.5, r.z);
c += back * (vec3(1., .45, .26) * .35 * smoothstep(0., -.8, r.x) + ACCENT * .3 * smoothstep(0., .8, r.x));
return c;
}
void main() {
vec2 p = vec2(gl_FragCoord.x, RES.y - gl_FragCoord.y) / SCALE;
vec2 d = shape(p);
float s = clamp(-d.x / d.y, 0., 1.);
vec3 n = normal(p, s);
vec3 r = reflect(-VIEW, n);
vec3 col = env(r) * fresnel(n.z);
col += pow(max(dot(r, KEY), 0.), 32.);
col = mix(col, col * TINT, win);
col = mix(col, col * RED, ERR.y);
float deep = field * smoothstep(THICK - .5, THICK + 1.5, -d.x);
vec3 glass = vec3(.05, .056, .07) + .05 * smoothstep(40., -40., p.y - (p.y < C.y ? A.y : B.y));
col = mix(col, glass, deep);
float focus = p.y < C.y ? ACT.x : ACT.y;
col = mix(col, ACCENT, focus * field * smoothstep(1.6, 0., abs(-d.x - THICK)));
float mid = (NECK.x + NECK.y) * .5;
col += vec3(.85, .95, 1.) * FX.x * .18 * exp(-length(p - vec2(C.x, mid)) / 12.);
col += vec3(.9, 1., 1.) * FX.y * exp(-abs(p.y - C.y) / 4.) * smoothstep(0., -30., d.x);
float a = clamp(.5 - d.x * SCALE, 0., 1.);
float shadow = .6 * smoothstep(54., -24., shape(p - vec2(0., 36.)).x);
float glow = (FX.z * .45 + focus * field * .4) * exp(-max(d.x, 0.) / (FX.z > 0. ? 26. : 10.));
float flash = FX.x * .12 * exp(-length(p - vec2(C.x, mid)) / 16.);
float alarm = ERR.y * .55 * exp(-max(d.x, 0.) / 30.);
vec3 light = ACCENT * glow + vec3(.85, .95, 1.) * flash + RED * alarm;
o = vec4(clamp(col, 0., 1.) * a + light * (1. - a), a + clamp(shadow + glow + flash + alarm, 0., 1.) * (1. - a));
}`;
const gl = cv.getContext('webgl2', { premultipliedAlpha: true, antialias: false });
const sh = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw gl.getShaderInfoLog(s); return s; };
const prog = gl.createProgram();
gl.attachShader(prog, sh(gl.VERTEX_SHADER, '#version 300 es\nin vec2 a; void main() { gl_Position = vec4(a, 0., 1.); }'));
gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, FS)); gl.linkProgram(prog); gl.useProgram(prog);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
const U = {};
for (const n of ['A', 'B', 'NECK', 'FX', 'ERR', 'KEY', 'RAD', 'P', 'ACT', 'RES', 'THICK', 'rest', 'waist', 'snap', 'win', 'field', 'SCALE']) U[n] = gl.getUniformLocation(prog, n);
let scale = 1;
function fit() {
const k = form.clientWidth / 540, dpr = Math.min(devicePixelRatio || 1, 2);
ui.style.transform = `scale(${k})`;
cv.width = Math.round(540 * k * dpr); cv.height = Math.round(440 * k * dpr); scale = k * dpr;
last = '';
}
new ResizeObserver(fit).observe(form);
let state = 'idle', t0 = 0, mergeT = -9, press = 0, win = 0, actT = 0, actB = 0, submitting = false, last = '';
let wrongAt = -9, retry = false, hit = [CX, CY];
const now = () => performance.now() / 1000;
function go(s) { state = s; t0 = now(); form.dataset.state = s; }
function geo(t) {
const g = { hw: HR, rest: 1, gap: 0, hh: HH, field: 0, waist: -1e4, patch: 0, snap: 0, P: [HR + 3 * press, PH - 4 * press], flash: 0, merge: 0, shiver: -1 };
const tau = t - t0;
if (state === 'opening' || state === 'open') {
g.rest = 0;
if (tau < SNAP) {
const k = tau / SNAP;
g.rest = 1 - clamp(tau / .05);
g.gap = STRETCH * (1 - (1 - k) * (1 - k));
g.hw = lerp(HR, HW, eout(tau / .4));
g.hh = HH + 2.5 * Math.exp(-8 * tau) * Math.sin(30 * tau);
// a bridge of liquid is waisted from the start, holds, then goes all at once, down to a thread
g.waist = Math.max(1.6, .72 * W0 * Math.pow(1 - clamp(k), .66));
g.patch = Math.max(g.waist, lerp(W0, 70, eio(k)));
g.rOut = HH; g.rIn = Math.min(g.hh, 20 * eout(tau / .15));
return g;
}
const u = tau - SNAP;
g.hw = HW;
g.gap = Math.max(3, STRETCH + (FGAP - STRETCH) * spring(u, 11, .72));
g.hh = lerp(HH, FH, eio((u - .12) / .5)) + 3 * Math.exp(-7 * u) * Math.sin(22 * u);
g.field = eio((u - .22) / .45);
g.waist = -(g.gap * .5 + 20) * Math.pow(clamp(u / .4), 1.4);
g.patch = 70 * (1 - eout(u / .45));
g.snap = clamp(u / .34); g.flash = Math.exp(-u / .09); g.shiver = u < 1.2 ? u : -1;
} else if (state === 'closing') {
const c = clamp(tau / .38);
g.rest = eio((c - .55) / .45);
g.gap = FGAP * (1 - eio(c)); g.hw = lerp(HW, HR, eio(c));
g.hh = lerp(FH, HH, eio(c)); g.field = 1 - eio(c / .75);
}
if (state === 'wrong') { // the button gulps when the answer comes back wrong
const s = t - wrongAt, w = Math.exp(-4.5 * s) * Math.sin(19 * s);
g.P = [g.P[0] + 5 * w, g.P[1] - 4 * w];
}
const m = t - mergeT;
if (m >= 0 && m < 1.2) { const w = Math.exp(-7 * m) * Math.sin(24 * m); g.merge = Math.exp(-m / .12); g.P = [HR - 2 * w, PH + 4.5 * w]; }
g.rOut = Math.min(g.hh, lerp(HH, 16, g.field)); g.rIn = Math.min(g.hh, lerp(20, 16, g.field));
return g;
}
let prev = now();
function frame() {
const t = now(), dt = Math.min(.05, t - prev); prev = t;
if (state === 'opening' && t - t0 > SNAP + .5) { state = 'open'; form.dataset.state = 'open'; (retry ? pass : user).focus(); }
if (state === 'closing' && t - t0 >= .38) { mergeT = t; if (submitting) { go('loading'); send(); } else go('idle'); }
const g = geo(t);
const ease = k => Math.min(1, dt * k);
press += ((btn.matches(':active') && state === 'idle' ? 1 : 0) - press) * ease(22);
win += ((state === 'done' ? 1 : 0) - win) * ease(state === 'done' ? 9 : 6);
actT += ((document.activeElement === user ? 1 : 0) - actT) * ease(14);
actB += ((document.activeElement === pass ? 1 : 0) - actB) * ease(14);
const kx = state === 'loading' ? -.45 + 1.35 * Math.sin(2 * Math.PI * (t - t0) / .94) : -.45, kl = Math.hypot(kx, .75, .7);
const hh = g.hh, yT = CY - g.gap / 2 - hh, yB = CY + g.gap / 2 + hh;
const s = t - wrongAt;
const red = s < 0 || s > RIPPLE + .3 ? 0 : clamp(s / .06) * (1 - clamp((s - .42) / .62) ** 2 * (3 - 2 * clamp((s - .42) / .62)));
const rings = still.matches || s > RIPPLE + .3 ? -1 : s;
const vals = [CX, yT, g.hw, hh, CX, yB, g.hw, hh, CY - g.gap / 2, CY + g.gap / 2, g.patch, g.flash, g.merge, win * .8, kx, g.rOut, g.rIn, ...g.P, rings, red, g.shiver,
actT, actB, lerp(hh, 7, g.field), g.rest, g.waist, g.snap, win, g.field, scale, cv.width].map(v => v.toFixed(3)).join();
if (vals !== last) {
last = vals;
gl.uniform4f(U.A, CX, yT, g.hw, hh); gl.uniform4f(U.B, CX, yB, g.hw, hh);
gl.uniform4f(U.NECK, CY - g.gap / 2, CY + g.gap / 2, g.patch, 0); gl.uniform4f(U.FX, g.flash, g.merge, win * .8, still.matches ? -1 : g.shiver);
gl.uniform3f(U.KEY, kx / kl, -.75 / kl, .7 / kl);
gl.uniform4f(U.ERR, rings, red, hit[0], hit[1]);
gl.uniform2f(U.RAD, g.rOut, g.rIn); gl.uniform2f(U.P, g.P[0], g.P[1]); gl.uniform2f(U.ACT, actT, actB); gl.uniform2f(U.RES, cv.width, cv.height);
gl.uniform1f(U.THICK, lerp(hh, 7, g.field)); gl.uniform1f(U.rest, g.rest); gl.uniform1f(U.waist, g.waist);
gl.uniform1f(U.snap, g.snap); gl.uniform1f(U.win, win); gl.uniform1f(U.field, g.field); gl.uniform1f(U.SCALE, scale);
gl.viewport(0, 0, cv.width, cv.height); gl.clearColor(0, 0, 0, 0); gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
requestAnimationFrame(frame);
}
async function send() {
try {
// a real server request goes here, for example:
// const res = await fetch('/api/login', { method: 'POST', body: new FormData(form) });
// if (!res.ok) throw new Error('wrong user or password');
await new Promise(r => setTimeout(r, 1300));
if (pass.value !== DEMO_PASSWORD) throw new Error('wrong password');
const left = .94 - (now() - t0) % .94; // let the light finish its pass
setTimeout(() => {
go('done'); label.textContent = 'Signed in';
setTimeout(reset, 2600); // on your site, redirect here instead
}, left * 1000);
} catch (e) {
// the metal answers where the pointer was, or in the middle for a keyboard submit
submitting = false; wrongAt = now(); go('wrong'); label.textContent = 'Wrong password';
setTimeout(() => {
pass.value = ''; label.textContent = 'Sign in'; retry = true;
f2.classList.add('warn'); passLabel.textContent = 'Wrong password, try again';
go('opening');
}, RIPPLE * 1000);
}
}
function reset() { user.value = pass.value = ''; label.textContent = 'Sign in'; submitting = false; retry = false; go('idle'); }
pass.addEventListener('input', () => { f2.classList.remove('warn'); passLabel.textContent = 'Password'; });
form.addEventListener('pointermove', e => {
const r = form.getBoundingClientRect(), k = 540 / r.width;
hit = [clamp((e.clientX - r.left) * k, CX - HR + 30, CX + HR - 30), CY];
});
form.addEventListener('pointerleave', () => { hit = [CX, CY]; });
btn.addEventListener('click', () => { if (state === 'idle') { go('opening'); user.tabIndex = pass.tabIndex = 0; } });
user.addEventListener('keydown', e => { if (e.key === 'Enter') { e.preventDefault(); pass.focus(); } });
pass.addEventListener('keydown', e => {
if (e.key !== 'Enter') return;
e.preventDefault();
if (!user.value || !pass.value) { (user.value ? pass : user).focus(); return; }
submitting = true; document.activeElement.blur(); go('closing');
});
form.addEventListener('keydown', e => { if (e.key === 'Escape' && state === 'open') { submitting = false; document.activeElement.blur(); go('closing'); } });
form.addEventListener('submit', e => e.preventDefault());
fit(); requestAnimationFrame(frame);
})();
</script>
Click the button, type any username, press Enter, type a wrong password and press Enter. Then try Tr0ub4dor&3.
What you can change
Change a number, save, and reload the page to see the difference.
DEMO_PASSWORD'Tr0ub4dor&3'The demo's only right answer. Delete it once your server does the checking.
RIPPLE1.15Seconds the wrong answer stays on the button before the form opens again.
190.in ripple()How fast the rings run across the metal, in pixels per second.
REDvec3(1., .26, .3)The colour the metal flushes on a wrong answer, inside the shader.
STRETCH240How far the halves pull apart before the metal snaps.
TINTvec3(.42, 1., .9)The colour the metal turns after a successful sign in.
Add it to your site
Put it where your sign in button or login form should be.
CSS
Paste into your stylesheet, or inside a <style> tag in <head>.
/* Liquid Metal Login V4 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */ .mercury { position: relative; width: min(460px, calc(100vw - 32px)); aspect-ratio: 540 / 440; margin: 0; } .mercury canvas { position: absolute; inset: 0; width: 100%; height: 100%; } /* everything below is laid out at 540 x 440 and scaled to the form width by the script */ .mercury .ui { position: absolute; left: 0; top: 0; width: 540px; height: 440px; transform-origin: 0 0; } .mercury .go { position: absolute; left: 52px; top: 168px; width: 436px; height: 104px; padding: 0; border: 0; border-radius: 52px; background: none; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; font: 650 31px system-ui, sans-serif; color: #0B0D10; text-shadow: 0 1.2px 0 rgba(255,255,255,.45); transition: opacity .15s ease-out; -webkit-tap-highlight-color: transparent; } .mercury .go:focus-visible { outline: 2px solid #6CEBD9; outline-offset: 6px; } .mercury .go svg { display: none; width: 30px; height: 30px; } .mercury[data-state="done"] .go svg { display: block; } .mercury[data-state="opening"] .go, .mercury[data-state="open"] .go, .mercury[data-state="closing"] .go { opacity: 0; pointer-events: none; } .mercury .field { position: absolute; left: 38px; width: 464px; height: 88px; box-sizing: border-box; padding: 14px 26px 0; opacity: 0; pointer-events: none; transition: opacity .2s ease-out; } .mercury[data-state="open"] .field { opacity: 1; pointer-events: auto; } .mercury .f1 { top: 120px; } .mercury .f2 { top: 232px; } .mercury label { display: block; font: 500 17px system-ui, sans-serif; color: #8A93A3; } .mercury[data-state="wrong"] .go { color: #FFF1F2; text-shadow: 0 1.2px 0 rgba(70,0,10,.55); } .mercury .f2.warn label { color: #FF6B76; } .mercury input { display: block; width: 100%; margin: 6px 0 0; padding: 0; border: 0; outline: 0; background: none; font: 500 25px system-ui, sans-serif; color: #F3F5F8; caret-color: #6CEBD9; }HTML
Put it where the effect should appear on your page.
<form class="mercury" id="mercury" data-state="idle" novalidate> <canvas></canvas> <div class="ui"> <div class="field f1"><label for="m-user">Username</label><input id="m-user" name="username" type="text" autocomplete="username" autocapitalize="off" spellcheck="false" tabindex="-1"></div> <div class="field f2"><label for="m-pass">Password</label><input id="m-pass" name="password" type="password" autocomplete="current-password" tabindex="-1"></div> <button class="go" type="button"><svg viewBox="0 0 30 30"><path d="M7 15.5l5 5L23 9.5" fill="none" stroke="#0B0D10" stroke-width="3.4" stroke-linecap="round" stroke-linejoin="round"/></svg><span>Sign in</span></button> </div> </form>JavaScript
Paste right before the closing </body> tag, inside <script></script>.
/* Liquid Metal Login V4 by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */ (() => { const STRETCH = 240, SNAP = 0.94, RIPPLE = 1.15; const DEMO_PASSWORD = 'Tr0ub4dor&3'; // the demo's only right answer, delete it once your server checks const form = document.getElementById('mercury'), cv = form.querySelector('canvas'), ui = form.querySelector('.ui'); const btn = form.querySelector('.go'), label = btn.querySelector('span'); const f2 = form.querySelector('.f2'), passLabel = f2.querySelector('label'); const still = matchMedia('(prefers-reduced-motion: reduce)'); const user = form.querySelector('#m-user'), pass = form.querySelector('#m-pass'); const CX = 270, CY = 220, HW = 232, HR = 218, PH = 52, HH = 26, FH = 44, FGAP = 24, W0 = 192; const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x)); const lerp = (a, b, k) => a + (b - a) * k; const eout = k => 1 - Math.pow(1 - clamp(k), 3); const eio = k => (k = clamp(k), k < .5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2); const spring = (s, w, z) => s <= 0 ? 0 : 1 - Math.exp(-z * w * s) * (Math.cos(w * Math.sqrt(1 - z * z) * s) + z / Math.sqrt(1 - z * z) * Math.sin(w * Math.sqrt(1 - z * z) * s)); const FS = `#version 300 es precision highp float; uniform vec4 A, B, NECK, FX, ERR; uniform vec3 KEY; uniform vec2 RAD, P, ACT, RES; uniform float THICK, rest, waist, snap, win, field, SCALE; out vec4 o; const float MELT = 24.; const vec3 VIEW = vec3(0., 0., 1.), TINT = vec3(.42, 1., .9), ACCENT = vec3(.42, .92, .85); const vec3 RED = vec3(1., .26, .3); const vec2 C = vec2(270., 220.); float box(vec2 p, vec2 b, vec4 r) { r.xy = p.x > 0. ? r.xy : r.zw; r.x = p.y > 0. ? r.x : r.y; vec2 q = abs(p) - b + r.x; return min(max(q.x, q.y), 0.) + length(max(q, 0.)) - r.x; } // a wrong password drops rings into the metal that run out from where you pressed and die away float ripple(vec2 p) { vec2 q = (p - ERR.zw) / vec2(1., .6); float run = length(q) - 190. * ERR.x; return cos(run * .12) * exp(-run * run / 1800.) * exp(-ERR.x * 1.6) * step(0., ERR.x); } vec2 pill(vec2 p) { return vec2(box(p - C, P, vec4(P.y)) - 2.2 * rest * ripple(p), P.y); } vec2 top(vec2 p) { return mix(vec2(box(p - A.xy, A.zw, RAD.yxyx), THICK), pill(p), rest); } vec2 bot(vec2 p) { return mix(vec2(box(p - B.xy, B.zw, RAD.xyxy), THICK), pill(p), rest); } vec2 join(vec2 a, vec2 b) { return a.x < b.x ? a : b; } vec2 smin(vec2 a, vec2 b, float k) { float h = clamp(.5 + .5 * (b.x - a.x) / k, 0., 1.); return vec2(mix(b.x, a.x, h) - k * h * (1. - h), mix(b.y, a.y, h)); } vec2 neck(vec2 p, float w) { if (max(NECK.z, w) <= 0.) return vec2(1e5, 1.); float y0 = NECK.x - A.w, y1 = NECK.y + B.w, len = max(y1 - y0, 1.); float u = abs(2. * (p.y - y0) / len - 1.); float rad = w + (NECK.z - w) * u * u, k = 4. * (NECK.z - w) * u / len; float d = max((abs(p.x - C.x) - rad) / sqrt(1. + k * k), abs(p.y - (y0 + y1) * .5) - len * .5); return vec2(d, max(rad, 1.5)); } vec2 drops(vec2 p, float s) { if (s <= 0. || s >= 1.) return vec2(1e5, 1.); float k = s * s * (3. - 2. * s), mid = (NECK.x + NECK.y) * .5, r = 6. * (1. - .6 * s); float a = length(p - vec2(C.x - 2., mix(mid - 6., NECK.x, k))) - r; float b = length(p - vec2(C.x + 2., mix(mid + 6., NECK.y, k))) - r * .8; return vec2(min(a, b), r); } vec2 shape(vec2 p) { vec2 d = join(top(p), bot(p)); d = smin(d, neck(p, waist), MELT); d = smin(d, drops(p, snap), MELT); return d; } // the snap sends a shiver along both halves, out from where the neck let go float shiver(vec2 p) { float run = abs(p.x - C.x) - 260. * FX.w; float edge = min(abs(p.y - NECK.x), abs(p.y - NECK.y)); return cos(run * .1) * exp(-run * run / 1400.) * exp(-FX.w * 2.4) * exp(-edge * edge / 900.) * step(0., FX.w); } // between the two halves the metal is a round column that thins toward its waist, so it is lit like one vec4 column(vec2 p) { if (max(NECK.z, waist) <= 0. || p.y < NECK.x || p.y > NECK.y) return vec4(0.); float y0 = NECK.x - A.w, y1 = NECK.y + B.w, len = max(y1 - y0, 1.); float v = 2. * (p.y - y0) / len - 1.; float rad = max(waist + (NECK.z - waist) * v * v, 1.5); float slope = 4. * (NECK.z - waist) * v / len; float sx = clamp((p.x - C.x) / rad, -1., 1.); vec3 n = normalize(vec3(sx, -slope, sqrt(max(1. - sx * sx, 0.)))); float edge = min(p.y - NECK.x, NECK.y - p.y); return vec4(n, smoothstep(-2., 5., edge) * smoothstep(1.5, -1.5, abs(p.x - C.x) - rad) * (1. - field)); } vec3 normal(vec2 p, float s) { vec2 e = vec2(.4, 0.); vec2 g = vec2(shape(p + e.xy).x - shape(p - e.xy).x, shape(p + e.yx).x - shape(p - e.yx).x); float slope = min((1. - s) / sqrt(max(1. - (1. - s) * (1. - s), 1e-4)), 14.); vec2 dome = vec2((p.x - C.x) / P.x * .32 * (1. - field), 0.); vec2 h = vec2(ripple(p + e.xy) - ripple(p - e.xy), ripple(p + e.yx) - ripple(p - e.yx)) / (2. * e.x); vec2 v = vec2(shiver(p + e.xy) - shiver(p - e.xy), shiver(p + e.yx) - shiver(p - e.yx)) / (2. * e.x); vec3 n = normalize(vec3(normalize(g + 1e-6) * slope + dome - h * 9. * rest - v * 7. * (1. - field), 1.)); vec4 c = column(p); return normalize(mix(n, c.xyz, c.w)); } float fresnel(float c) { return mix(.8, 1., pow(1. - c, 5.)); } vec3 env(vec3 r) { float el = asin(clamp(-r.y, -1., 1.)), az = atan(r.x, r.z); float h = el + .45; vec3 sky = mix(vec3(.58, .62, .7), vec3(.96, .98, 1.04), smoothstep(0., .8, h)); sky = mix(sky, vec3(.16, .17, .2), smoothstep(.62, .78, el) * smoothstep(1.02, .92, el)); sky = mix(sky, vec3(.42, .45, .52), smoothstep(1.3, 1.45, el)); vec3 grd = mix(vec3(.05, .045, .05), vec3(.012, .013, .016), smoothstep(0., .5, -h)); vec3 c = mix(grd, sky, smoothstep(-.012, .012, h)) + vec3(.7) * exp(-abs(h) * 45.); c += vec3(1.8) * smoothstep(.95, 1.0, el) * smoothstep(1.3, 1.24, el); c = mix(c, vec3(.02, .022, .03) + vec3(.06) * smoothstep(-.2, .6, -r.y), smoothstep(.05, -.35, r.z)); c += vec3(1., .5, .3) * 1.1 * exp(-pow((az + 1.75) * 1.8, 2.)) * exp(-pow((el - .12) * 2.6, 2.)); c += ACCENT * 1.1 * exp(-pow((az - 1.75) * 1.8, 2.)) * exp(-pow((el - .06) * 2.6, 2.)); float back = smoothstep(.1, -.5, r.z); c += back * (vec3(1., .45, .26) * .35 * smoothstep(0., -.8, r.x) + ACCENT * .3 * smoothstep(0., .8, r.x)); return c; } void main() { vec2 p = vec2(gl_FragCoord.x, RES.y - gl_FragCoord.y) / SCALE; vec2 d = shape(p); float s = clamp(-d.x / d.y, 0., 1.); vec3 n = normal(p, s); vec3 r = reflect(-VIEW, n); vec3 col = env(r) * fresnel(n.z); col += pow(max(dot(r, KEY), 0.), 32.); col = mix(col, col * TINT, win); col = mix(col, col * RED, ERR.y); float deep = field * smoothstep(THICK - .5, THICK + 1.5, -d.x); vec3 glass = vec3(.05, .056, .07) + .05 * smoothstep(40., -40., p.y - (p.y < C.y ? A.y : B.y)); col = mix(col, glass, deep); float focus = p.y < C.y ? ACT.x : ACT.y; col = mix(col, ACCENT, focus * field * smoothstep(1.6, 0., abs(-d.x - THICK))); float mid = (NECK.x + NECK.y) * .5; col += vec3(.85, .95, 1.) * FX.x * .18 * exp(-length(p - vec2(C.x, mid)) / 12.); col += vec3(.9, 1., 1.) * FX.y * exp(-abs(p.y - C.y) / 4.) * smoothstep(0., -30., d.x); float a = clamp(.5 - d.x * SCALE, 0., 1.); float shadow = .6 * smoothstep(54., -24., shape(p - vec2(0., 36.)).x); float glow = (FX.z * .45 + focus * field * .4) * exp(-max(d.x, 0.) / (FX.z > 0. ? 26. : 10.)); float flash = FX.x * .12 * exp(-length(p - vec2(C.x, mid)) / 16.); float alarm = ERR.y * .55 * exp(-max(d.x, 0.) / 30.); vec3 light = ACCENT * glow + vec3(.85, .95, 1.) * flash + RED * alarm; o = vec4(clamp(col, 0., 1.) * a + light * (1. - a), a + clamp(shadow + glow + flash + alarm, 0., 1.) * (1. - a)); }`; const gl = cv.getContext('webgl2', { premultipliedAlpha: true, antialias: false }); const sh = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw gl.getShaderInfoLog(s); return s; }; const prog = gl.createProgram(); gl.attachShader(prog, sh(gl.VERTEX_SHADER, '#version 300 es\nin vec2 a; void main() { gl_Position = vec4(a, 0., 1.); }')); gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, FS)); gl.linkProgram(prog); gl.useProgram(prog); gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer()); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW); gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0); const U = {}; for (const n of ['A', 'B', 'NECK', 'FX', 'ERR', 'KEY', 'RAD', 'P', 'ACT', 'RES', 'THICK', 'rest', 'waist', 'snap', 'win', 'field', 'SCALE']) U[n] = gl.getUniformLocation(prog, n); let scale = 1; function fit() { const k = form.clientWidth / 540, dpr = Math.min(devicePixelRatio || 1, 2); ui.style.transform = `scale(${k})`; cv.width = Math.round(540 * k * dpr); cv.height = Math.round(440 * k * dpr); scale = k * dpr; last = ''; } new ResizeObserver(fit).observe(form); let state = 'idle', t0 = 0, mergeT = -9, press = 0, win = 0, actT = 0, actB = 0, submitting = false, last = ''; let wrongAt = -9, retry = false, hit = [CX, CY]; const now = () => performance.now() / 1000; function go(s) { state = s; t0 = now(); form.dataset.state = s; } function geo(t) { const g = { hw: HR, rest: 1, gap: 0, hh: HH, field: 0, waist: -1e4, patch: 0, snap: 0, P: [HR + 3 * press, PH - 4 * press], flash: 0, merge: 0, shiver: -1 }; const tau = t - t0; if (state === 'opening' || state === 'open') { g.rest = 0; if (tau < SNAP) { const k = tau / SNAP; g.rest = 1 - clamp(tau / .05); g.gap = STRETCH * (1 - (1 - k) * (1 - k)); g.hw = lerp(HR, HW, eout(tau / .4)); g.hh = HH + 2.5 * Math.exp(-8 * tau) * Math.sin(30 * tau); // a bridge of liquid is waisted from the start, holds, then goes all at once, down to a thread g.waist = Math.max(1.6, .72 * W0 * Math.pow(1 - clamp(k), .66)); g.patch = Math.max(g.waist, lerp(W0, 70, eio(k))); g.rOut = HH; g.rIn = Math.min(g.hh, 20 * eout(tau / .15)); return g; } const u = tau - SNAP; g.hw = HW; g.gap = Math.max(3, STRETCH + (FGAP - STRETCH) * spring(u, 11, .72)); g.hh = lerp(HH, FH, eio((u - .12) / .5)) + 3 * Math.exp(-7 * u) * Math.sin(22 * u); g.field = eio((u - .22) / .45); g.waist = -(g.gap * .5 + 20) * Math.pow(clamp(u / .4), 1.4); g.patch = 70 * (1 - eout(u / .45)); g.snap = clamp(u / .34); g.flash = Math.exp(-u / .09); g.shiver = u < 1.2 ? u : -1; } else if (state === 'closing') { const c = clamp(tau / .38); g.rest = eio((c - .55) / .45); g.gap = FGAP * (1 - eio(c)); g.hw = lerp(HW, HR, eio(c)); g.hh = lerp(FH, HH, eio(c)); g.field = 1 - eio(c / .75); } if (state === 'wrong') { // the button gulps when the answer comes back wrong const s = t - wrongAt, w = Math.exp(-4.5 * s) * Math.sin(19 * s); g.P = [g.P[0] + 5 * w, g.P[1] - 4 * w]; } const m = t - mergeT; if (m >= 0 && m < 1.2) { const w = Math.exp(-7 * m) * Math.sin(24 * m); g.merge = Math.exp(-m / .12); g.P = [HR - 2 * w, PH + 4.5 * w]; } g.rOut = Math.min(g.hh, lerp(HH, 16, g.field)); g.rIn = Math.min(g.hh, lerp(20, 16, g.field)); return g; } let prev = now(); function frame() { const t = now(), dt = Math.min(.05, t - prev); prev = t; if (state === 'opening' && t - t0 > SNAP + .5) { state = 'open'; form.dataset.state = 'open'; (retry ? pass : user).focus(); } if (state === 'closing' && t - t0 >= .38) { mergeT = t; if (submitting) { go('loading'); send(); } else go('idle'); } const g = geo(t); const ease = k => Math.min(1, dt * k); press += ((btn.matches(':active') && state === 'idle' ? 1 : 0) - press) * ease(22); win += ((state === 'done' ? 1 : 0) - win) * ease(state === 'done' ? 9 : 6); actT += ((document.activeElement === user ? 1 : 0) - actT) * ease(14); actB += ((document.activeElement === pass ? 1 : 0) - actB) * ease(14); const kx = state === 'loading' ? -.45 + 1.35 * Math.sin(2 * Math.PI * (t - t0) / .94) : -.45, kl = Math.hypot(kx, .75, .7); const hh = g.hh, yT = CY - g.gap / 2 - hh, yB = CY + g.gap / 2 + hh; const s = t - wrongAt; const red = s < 0 || s > RIPPLE + .3 ? 0 : clamp(s / .06) * (1 - clamp((s - .42) / .62) ** 2 * (3 - 2 * clamp((s - .42) / .62))); const rings = still.matches || s > RIPPLE + .3 ? -1 : s; const vals = [CX, yT, g.hw, hh, CX, yB, g.hw, hh, CY - g.gap / 2, CY + g.gap / 2, g.patch, g.flash, g.merge, win * .8, kx, g.rOut, g.rIn, ...g.P, rings, red, g.shiver, actT, actB, lerp(hh, 7, g.field), g.rest, g.waist, g.snap, win, g.field, scale, cv.width].map(v => v.toFixed(3)).join(); if (vals !== last) { last = vals; gl.uniform4f(U.A, CX, yT, g.hw, hh); gl.uniform4f(U.B, CX, yB, g.hw, hh); gl.uniform4f(U.NECK, CY - g.gap / 2, CY + g.gap / 2, g.patch, 0); gl.uniform4f(U.FX, g.flash, g.merge, win * .8, still.matches ? -1 : g.shiver); gl.uniform3f(U.KEY, kx / kl, -.75 / kl, .7 / kl); gl.uniform4f(U.ERR, rings, red, hit[0], hit[1]); gl.uniform2f(U.RAD, g.rOut, g.rIn); gl.uniform2f(U.P, g.P[0], g.P[1]); gl.uniform2f(U.ACT, actT, actB); gl.uniform2f(U.RES, cv.width, cv.height); gl.uniform1f(U.THICK, lerp(hh, 7, g.field)); gl.uniform1f(U.rest, g.rest); gl.uniform1f(U.waist, g.waist); gl.uniform1f(U.snap, g.snap); gl.uniform1f(U.win, win); gl.uniform1f(U.field, g.field); gl.uniform1f(U.SCALE, scale); gl.viewport(0, 0, cv.width, cv.height); gl.clearColor(0, 0, 0, 0); gl.clear(gl.COLOR_BUFFER_BIT); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); } requestAnimationFrame(frame); } async function send() { try { // a real server request goes here, for example: // const res = await fetch('/api/login', { method: 'POST', body: new FormData(form) }); // if (!res.ok) throw new Error('wrong user or password'); await new Promise(r => setTimeout(r, 1300)); if (pass.value !== DEMO_PASSWORD) throw new Error('wrong password'); const left = .94 - (now() - t0) % .94; // let the light finish its pass setTimeout(() => { go('done'); label.textContent = 'Signed in'; setTimeout(reset, 2600); // on your site, redirect here instead }, left * 1000); } catch (e) { // the metal answers where the pointer was, or in the middle for a keyboard submit submitting = false; wrongAt = now(); go('wrong'); label.textContent = 'Wrong password'; setTimeout(() => { pass.value = ''; label.textContent = 'Sign in'; retry = true; f2.classList.add('warn'); passLabel.textContent = 'Wrong password, try again'; go('opening'); }, RIPPLE * 1000); } } function reset() { user.value = pass.value = ''; label.textContent = 'Sign in'; submitting = false; retry = false; go('idle'); } pass.addEventListener('input', () => { f2.classList.remove('warn'); passLabel.textContent = 'Password'; }); form.addEventListener('pointermove', e => { const r = form.getBoundingClientRect(), k = 540 / r.width; hit = [clamp((e.clientX - r.left) * k, CX - HR + 30, CX + HR - 30), CY]; }); form.addEventListener('pointerleave', () => { hit = [CX, CY]; }); btn.addEventListener('click', () => { if (state === 'idle') { go('opening'); user.tabIndex = pass.tabIndex = 0; } }); user.addEventListener('keydown', e => { if (e.key === 'Enter') { e.preventDefault(); pass.focus(); } }); pass.addEventListener('keydown', e => { if (e.key !== 'Enter') return; e.preventDefault(); if (!user.value || !pass.value) { (user.value ? pass : user).focus(); return; } submitting = true; document.activeElement.blur(); go('closing'); }); form.addEventListener('keydown', e => { if (e.key === 'Escape' && state === 'open') { submitting = false; document.activeElement.blur(); go('closing'); } }); form.addEventListener('submit', e => e.preventDefault()); fit(); requestAnimationFrame(frame); })();
Connect it to your backend
Don't just put your own password in place of the demo one, anyone can read it in the page source. Find a real server request goes here in the script, delete the 1300 ms wait and the DEMO_PASSWORD check, and use the fetch() example above them with your own login address. Throwing an error shows the red ripple, anything else counts as signed in. Then find redirect here instead and send people to their account page. No server of your own? Call the sign in function of a login service such as Firebase Auth or Supabase in the same place.
Good to know
- The ripple is a travelling ring in the shader, ripple() adds it both to the edge of the button and to its surface normals, so the reflections bend with it.
- The rings start where your pointer was on the button, or in the middle when the form was sent from the keyboard.
- The red is one line, col = mix(col, col * RED, ERR.y), plus a red glow on the page behind the metal.
- After a wrong answer the password field comes back empty and focused, and its label says what went wrong until you start typing.
- With reduced motion turned on the rings are skipped, the colour still says what happened.
- Needs WebGL2, which every current browser has.
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.



