Fluid Ink Login

A sign in form with living ink behind it. Move the pointer and the ink follows, curls and fades.

Move the pointer over the page. Type any email and password and press Log in.

Download

What you can change

Change a number, save, and reload the page to see the difference.

INKfour colors

The four colors of the ink, each as red, green, blue from 0 to 255.

INK_PUSH5200

How hard the pointer pushes the ink.

INK_SIZE0.3

How wide a stroke is.

INK_FADE0.55

How fast the ink fades, lower stays longer.

INK_TWIST26

How much the ink curls.

Add it to your site

The sign in page of a studio, a portfolio or a product, anywhere the first screen can afford a little motion.

  1. CSS

    Paste into your stylesheet, or inside a <style> tag in <head>.

    /* page shell, only needed while this file is the whole page */
  2. HTML

    Put it where the effect should appear on your page.

    <!-- login start -->
    <main class="ik">
      <section class="ik-door">
        <canvas class="ik-ink" aria-hidden="true"></canvas>
        <div class="ik-gate">
          <h1 class="ik-gate-h ik-code">Log in</h1>
          <form class="ik-form" novalidate data-busy="Logging in" data-label="Logged in" data-done="Welcome back. Change this line or send people to their page.">
            <label class="ik-hide" for="ik-user">Email</label>
            <input class="ik-area" id="ik-user" name="email" type="email" autocomplete="username" placeholder="you@example.com">
            <label class="ik-hide" for="ik-pass">Password</label>
            <input class="ik-area" id="ik-pass" name="password" type="password" autocomplete="current-password" placeholder="Password">
            <button class="ik-btn ik-btn-main" type="submit">Log in</button>
            <p class="ik-note" role="status"></p>
          </form>
        </div>
      </section>
    </main>
    <!-- login end -->
  3. JavaScript

    Paste right before the closing </body> tag, inside <script></script>.

    /* Fluid Ink Login by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
    (() => {
    const root = document.querySelector('.ik');
    if (!root) return;
    
    const INK = [[255, 61, 129], [140, 92, 255], [47, 123, 255], [41, 211, 255]];
    const INK_PUSH = 5200, INK_SIZE = .3, INK_FADE = .55, INK_TWIST = 26, INK_PIXELS = 1.6e6;
    
    const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
    root.classList.add('ik-js');
    const $ = (s, el = root) => el.querySelector(s);
    const $$ = (s, el = root) => [...el.querySelectorAll(s)];
    const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x));
    const wait = ms => new Promise(r => setTimeout(r, ms));
    // one fixed sequence instead of Math.random, so the page behaves the same on every visit
    let seed = 20261008;
    const dice = () => (seed = seed * 16807 % 2147483647) / 2147483647;
    
    /* ink: a small fluid simulation behind the form, it follows the pointer and answers a finger */
    (() => {
      const cv = $('.ik-ink');
      if (!cv || reduce) return;
      const host = cv.parentNode;
      const gl = cv.getContext('webgl2', { alpha: true, premultipliedAlpha: true, antialias: false, depth: false });
      if (!gl || !(gl.getExtension('EXT_color_buffer_float') || gl.getExtension('EXT_color_buffer_half_float'))) return;
      gl.getExtension('OES_texture_float_linear');
    
      const VERT = `#version 300 es
    in vec2 a;
    uniform vec2 px;
    out vec2 uv, l, r, t, b;
    void main() {
    uv = a * .5 + .5;
    l = uv - vec2(px.x, 0.); r = uv + vec2(px.x, 0.);
    t = uv + vec2(0., px.y); b = uv - vec2(0., px.y);
    gl_Position = vec4(a, 0., 1.);
    }`;
      const HEAD = '#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 uv, l, r, t, b;\nout vec4 o;\n';
      const SRC = {
        splat: 'uniform sampler2D src; uniform vec2 at; uniform vec3 add; uniform float ratio, size;\nvoid main() { vec2 p = uv - at; p.x *= ratio; o = vec4(texture(src, uv).xyz + exp(-dot(p, p) / size) * add, 1.); }',
        advect: 'uniform sampler2D vel, src; uniform vec2 px; uniform float dt, fade;\nvoid main() { o = texture(src, uv - dt * texture(vel, uv).xy * px) / (1. + fade * dt); }',
        curl: 'uniform sampler2D vel;\nvoid main() { o = vec4(.5 * (texture(vel, r).y - texture(vel, l).y - texture(vel, t).x + texture(vel, b).x), 0., 0., 1.); }',
        swirl: 'uniform sampler2D vel, curl; uniform float dt, twist;\nvoid main() {\n  vec2 f = .5 * vec2(abs(texture(curl, t).x) - abs(texture(curl, b).x), abs(texture(curl, r).x) - abs(texture(curl, l).x));\n  f = f / (length(f) + 1e-4) * twist * texture(curl, uv).x; f.y = -f.y;\n  o = vec4(clamp(texture(vel, uv).xy + f * dt, -1000., 1000.), 0., 1.);\n}',
        diverge: 'uniform sampler2D vel;\nvoid main() {\n  float L = texture(vel, l).x, R = texture(vel, r).x, T = texture(vel, t).y, B = texture(vel, b).y;\n  vec2 c = texture(vel, uv).xy;\n  if (l.x < 0.) L = -c.x; if (r.x > 1.) R = -c.x; if (t.y > 1.) T = -c.y; if (b.y < 0.) B = -c.y;\n  o = vec4(.5 * (R - L + T - B), 0., 0., 1.);\n}',
        relax: 'uniform sampler2D prs, div;\nvoid main() { o = vec4((texture(prs, l).x + texture(prs, r).x + texture(prs, t).x + texture(prs, b).x - texture(div, uv).x) * .25, 0., 0., 1.); }',
        settle: 'uniform sampler2D prs, vel;\nvoid main() { o = vec4(texture(vel, uv).xy - vec2(texture(prs, r).x - texture(prs, l).x, texture(prs, t).x - texture(prs, b).x), 0., 1.); }',
        scale: 'uniform sampler2D src; uniform float k;\nvoid main() { o = k * texture(src, uv); }',
        // the picture: the dye itself, lit a little from its own slope so it has depth
        show: 'uniform sampler2D src; uniform vec2 px;\nvoid main() {\n  vec3 c = texture(src, uv).rgb;\n  float dx = length(texture(src, r).rgb) - length(texture(src, l).rgb), dy = length(texture(src, t).rgb) - length(texture(src, b).rgb);\n  vec3 n = normalize(vec3(dx, dy, length(px) * 60.));\n  c *= clamp(dot(n, vec3(0., 0., 1.)) + .7, .7, 1.);\n  c = 1. - exp(-c * 1.5);\n  o = vec4(c, max(c.r, max(c.g, c.b)));\n}',
      };
      const shader = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return s; };
      const vs = shader(gl.VERTEX_SHADER, VERT);
      const P = {};
      for (const name in SRC) {
        const p = gl.createProgram();
        gl.attachShader(p, vs); gl.attachShader(p, shader(gl.FRAGMENT_SHADER, HEAD + SRC[name]));
        gl.bindAttribLocation(p, 0, 'a'); gl.linkProgram(p);
        if (!gl.getProgramParameter(p, gl.LINK_STATUS)) return;
        const u = {};
        for (let i = 0; i < gl.getProgramParameter(p, gl.ACTIVE_UNIFORMS); i++) { const n = gl.getActiveUniform(p, i).name; u[n] = gl.getUniformLocation(p, n); }
        P[name] = { p, u };
      }
      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);
    
      // textures: velocity and dye are pairs that swap, the rest are single
      let slot = 0;
      function target(w, h, inner, format, filter) {
        const tex = gl.createTexture(), id = slot++;
        gl.activeTexture(gl.TEXTURE0 + id); gl.bindTexture(gl.TEXTURE_2D, tex);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
        gl.texImage2D(gl.TEXTURE_2D, 0, inner, w, h, 0, format, gl.HALF_FLOAT, null);
        const fbo = gl.createFramebuffer();
        gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
        gl.viewport(0, 0, w, h); gl.clearColor(0, 0, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT);
        return { id, fbo, w, h, px: [1 / w, 1 / h] };
      }
      const pair = (...a) => { const d = { read: target(...a), write: target(...a), swap() { [d.read, d.write] = [d.write, d.read]; } }; return d; };
      let vel, dye, prs, div, curl, ratio = 1;
      function build() {
        const w = host.clientWidth, h = host.clientHeight;
        if (!w || !h) return false;
        ratio = w / h; slot = 0;
        const k = Math.min(devicePixelRatio || 1, 2, Math.sqrt(INK_PIXELS / (w * h)));
        cv.width = Math.round(w * k); cv.height = Math.round(h * k);
        const sh = 128, sw = Math.round(sh * ratio), dh = 512, dw = Math.round(dh * ratio);
        vel = pair(sw, sh, gl.RG16F, gl.RG, gl.LINEAR); dye = pair(dw, dh, gl.RGBA16F, gl.RGBA, gl.LINEAR);
        prs = pair(sw, sh, gl.R16F, gl.RED, gl.NEAREST);
        div = target(sw, sh, gl.R16F, gl.RED, gl.NEAREST); curl = target(sw, sh, gl.R16F, gl.RED, gl.NEAREST);
        return gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE;
      }
      if (!build()) return;
      root.classList.add('ik-wet');
    
      function run(name, to, set) {
        const { p, u } = P[name];
        gl.useProgram(p);
        if (u.px) gl.uniform2f(u.px, ...(to ? to.px : [1 / cv.width, 1 / cv.height]));
        set(u);
        gl.bindFramebuffer(gl.FRAMEBUFFER, to ? to.fbo : null);
        gl.viewport(0, 0, to ? to.w : cv.width, to ? to.h : cv.height);
        gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
      }
      function splat(x, y, dx, dy, color) {
        run('splat', vel.write, u => { gl.uniform1i(u.src, vel.read.id); gl.uniform2f(u.at, x, y); gl.uniform3f(u.add, dx, dy, 0); gl.uniform1f(u.ratio, ratio); gl.uniform1f(u.size, INK_SIZE / 100); }); vel.swap();
        run('splat', dye.write, u => { gl.uniform1i(u.src, dye.read.id); gl.uniform2f(u.at, x, y); gl.uniform3f(u.add, ...color); gl.uniform1f(u.ratio, ratio); gl.uniform1f(u.size, INK_SIZE / 100); }); dye.swap();
      }
      function step(dt) {
        gl.disable(gl.BLEND);
        run('curl', curl, u => gl.uniform1i(u.vel, vel.read.id));
        run('swirl', vel.write, u => { gl.uniform1i(u.vel, vel.read.id); gl.uniform1i(u.curl, curl.id); gl.uniform1f(u.dt, dt); gl.uniform1f(u.twist, INK_TWIST); }); vel.swap();
        run('diverge', div, u => gl.uniform1i(u.vel, vel.read.id));
        run('scale', prs.write, u => { gl.uniform1i(u.src, prs.read.id); gl.uniform1f(u.k, .8); }); prs.swap();
        for (let i = 0; i < 18; i++) { run('relax', prs.write, u => { gl.uniform1i(u.prs, prs.read.id); gl.uniform1i(u.div, div.id); }); prs.swap(); }
        run('settle', vel.write, u => { gl.uniform1i(u.prs, prs.read.id); gl.uniform1i(u.vel, vel.read.id); }); vel.swap();
        run('advect', vel.write, u => { gl.uniform1i(u.vel, vel.read.id); gl.uniform1i(u.src, vel.read.id); gl.uniform1f(u.dt, dt); gl.uniform1f(u.fade, .25); }); vel.swap();
        run('advect', dye.write, u => { gl.uniform1i(u.vel, vel.read.id); gl.uniform1i(u.src, dye.read.id); gl.uniform2f(u.px, ...vel.read.px); gl.uniform1f(u.dt, dt); gl.uniform1f(u.fade, INK_FADE); }); dye.swap();
        gl.clearColor(0, 0, 0, 0);
        run('show', null, u => gl.uniform1i(u.src, dye.read.id));
      }
    
      // colors come from the palette in turn, never at random, so the page looks the same every time
      let turn = 0;
      const ink = (k = 1) => { const c = INK[turn++ % INK.length]; return c.map(v => v / 255 * .2 * k); };
      let shown = true, running = false, last = 0, idle = 0, hue = ink(), hueAt = 0, px = -1, py = -1, born = 0;
      function frame(now) {
        if (!shown || document.hidden) { running = false; return; }
        const t = now / 1000, dt = Math.min(t - last, 1 / 30); last = t;
        // the first second: five drops fall in on their own; later a slow one keeps the ink moving when nobody is here
        while (born < 5 && t - start > born * .12) { const a = born * 2.4; splat(.42 + .13 * born, .3 + .34 * (born % 2), 1100 * Math.cos(a), 800 * Math.sin(a), ink(3)); born++; }
        idle += dt;
        if (idle > 2.5 && Math.floor(t * 2.5) !== Math.floor((t - dt) * 2.5)) splat(.5 + .34 * Math.sin(t * .37), .5 + .3 * Math.sin(t * .53 + 1), 260 * Math.cos(t * .7), 260 * Math.sin(t * .9), ink(1.2));
        step(dt);
        requestAnimationFrame(frame);
      }
      let start = 0;
      const wake = () => { if (running || !shown || document.hidden) return; running = true; requestAnimationFrame(t => { last = t / 1000; if (!start) start = last; frame(t); }); };
    
      host.addEventListener('pointermove', e => {
        const r = cv.getBoundingClientRect(), x = (e.clientX - r.left) / r.width, y = 1 - (e.clientY - r.top) / r.height;
        if (px >= 0) {
          const dx = (x - px) * ratio, dy = y - py, far = Math.hypot(dx, dy);
          if (far > 0) { if (last - hueAt > .6) { hue = ink(); hueAt = last; } splat(x, y, dx * INK_PUSH, dy * INK_PUSH, hue); idle = 0; }
        }
        px = x; py = y;
      });
      host.addEventListener('pointerleave', () => { px = -1; });
      // a finger: a tap lets a drop fall, a move to the side paints, and scrolling the page pushes the ink along
      host.addEventListener('pointerdown', e => {
        if (e.pointerType === 'mouse') return;
        const r = cv.getBoundingClientRect(), x = (e.clientX - r.left) / r.width, y = 1 - (e.clientY - r.top) / r.height;
        hue = ink(); hueAt = last;
        splat(x, y, 0, 0, hue.map(v => v * 5));
        for (let i = 0; i < 4; i++) {
          const a = i * Math.PI / 2 + turn;
          splat(x + .014 * Math.cos(a) / ratio, y + .014 * Math.sin(a), 900 * Math.cos(a), 900 * Math.sin(a), [0, 0, 0]);
        }
        px = x; py = y; idle = 0;
      });
      host.addEventListener('pointercancel', () => { px = -1; });
      let finger = false, top = scrollY;
      addEventListener('pointerdown', e => { finger = e.pointerType !== 'mouse'; }, true);
      addEventListener('scroll', () => {
        const d = clamp((scrollY - top) / innerHeight, -.2, .2);
        top = scrollY;
        if (!finger || !shown || !d) return;
        for (const x of [.22, .5, .78]) splat(x, .5 + .2 * Math.sin(x * 9 + last), 0, d * 9000, hue.map(v => v * Math.min(1, Math.abs(d) * 12)));
        idle = 0;
      }, { passive: true });
      new ResizeObserver(() => { if (cv.width && Math.abs(host.clientWidth / host.clientHeight - ratio) > .01) build(); }).observe(host);
      new IntersectionObserver(([e]) => { shown = e.isIntersecting; wake(); }).observe(cv);
      document.addEventListener('visibilitychange', wake);
      wake();
    })();
    
    /* the title arrives as noise and settles into words, left to right */
    $$('.ik-code').forEach(el => {
      if (reduce) return;
      const text = el.textContent.trim(), glyphs = 'ABCDEFGHKLMNPRSTUVXYZ0123456789#%&+=?';
      el.setAttribute('aria-label', text);
      el.innerHTML = text.split(' ').map(w => `<span class="ik-wd" aria-hidden="true">${[...w].map(c => `<span class="ik-ch">${c}</span>`).join('')}</span>`).join(' ');
      const cells = $$('.ik-ch', el), final = cells.map(c => c.textContent);
      cells.forEach(c => { c.style.width = `${c.getBoundingClientRect().width}px`; });   // each letter keeps its own width, the line never jumps
      const t0 = performance.now();
      requestAnimationFrame(function tick(now) {
        const k = (now - t0) / 36 - 4, flip = Math.floor(now / 50);
        cells.forEach((c, i) => {
          const to = i < k ? final[i] : i < k + 10 ? glyphs[(i * 7 + flip * 13) % glyphs.length] : '';
          if (c.textContent !== to) c.textContent = to;
        });
        if (k < cells.length) requestAnimationFrame(tick);
      });
    });
    
    /* a burst of paper in the colors of the ink, for a form that went through */
    function party(x, y) {
      if (reduce) return;
      const cv = document.createElement('canvas'), c = cv.getContext('2d'), k = Math.min(devicePixelRatio || 1, 2);
      cv.className = 'ik-party'; cv.width = innerWidth * k; cv.height = innerHeight * k;
      root.append(cv);
      const bits = Array.from({ length: 90 }, () => {
        const a = -Math.PI / 2 + (dice() - .5) * 2.2, v = 420 + dice() * 620;
        return { x, y, vx: Math.cos(a) * v, vy: Math.sin(a) * v, w: 6 + dice() * 7, h: 3 + dice() * 5, spin: dice() * 6, turn: (dice() - .5) * 14, color: INK[Math.floor(dice() * INK.length)] };
      });
      let last = performance.now(), age = 0;
      requestAnimationFrame(function fall(now) {
        const dt = Math.min((now - last) / 1000, .05); last = now; age += dt;
        c.setTransform(k, 0, 0, k, 0, 0); c.clearRect(0, 0, innerWidth, innerHeight);
        for (const b of bits) {
          b.vy += 1500 * dt; b.vx *= 1 - 1.4 * dt; b.x += b.vx * dt; b.y += b.vy * dt; b.spin += b.turn * dt;
          c.save(); c.translate(b.x, b.y); c.rotate(b.spin);
          c.globalAlpha = clamp(2.2 - age); c.fillStyle = `rgb(${b.color})`;
          c.fillRect(-b.w / 2, -b.h / 2 * Math.cos(b.spin * 1.7), b.w, b.h * Math.cos(b.spin * 1.7));
          c.restore();
        }
        if (age < 2.2) requestAnimationFrame(fall); else cv.remove();
      });
    }
    
    /* the form: checks the fields, waits for the server, then lets the paper fly */
    $$('.ik-form').forEach(form => {
      const btn = $('.ik-btn', form), note = $('.ik-note', form), fields = $$('.ik-input, .ik-area', form);
      form.addEventListener('submit', async e => {
        e.preventDefault();
        const bad = fields.find(f => !f.value.trim() || f.type === 'email' && !/^\S+@\S+\.\S+$/.test(f.value.trim()));
        fields.forEach(f => f.classList.toggle('ik-area-bad', f === bad));
        form.classList.toggle('ik-form-bad', !!bad);
        if (bad) {
          note.textContent = bad.type === 'email' && bad.value.trim() ? 'That does not look like an email. Try one like name@example.com.' : 'Fill in this field first.';
          bad.focus();
          return;
        }
        btn.disabled = true; btn.textContent = form.dataset.busy || 'Sending';
        // a real server request goes here, for example:
        // await fetch('/api/login', { method: 'POST', body: new FormData(form) });
        await wait(700);
        fields.forEach(f => { f.disabled = true; });
        btn.textContent = form.dataset.label || 'Sent';
        note.textContent = form.dataset.done || 'Thank you. We will write back soon.';
        const r = btn.getBoundingClientRect();
        party(r.left + r.width / 2, r.top + r.height / 2);
      });
      fields.forEach(f => f.addEventListener('input', () => { form.classList.remove('ik-form-bad'); f.classList.remove('ik-area-bad'); note.textContent = ''; }));
    });
    })();

Connect it to your backend

The form sends nothing until you connect it. Search for a real server request goes here, put your fetch() there and remove the timer on the next line.

Good to know

Tilda, Webflow, WordPress

Press Copy all code at the top and paste it into one HTML block.

Tilda

Add block, Other, T123 HTML code. Paste and save. Check the published page, the editor preview does not run scripts.

Webflow

Add panel, Embed. Paste, then Save & Close. Custom code runs on the published site.

WordPress

Add block, Custom HTML. Paste and press Update.

More in Sign in & forms

See all
Copied