Let’s create a Animated Login Form using HTML, CSS, and JavaScript – a soft pastel sign up card with Mochi, a cute clay cat whose eyes follow your text as you type, who gives a thumbs up for a valid email, reacts to how strong your password is, and covers its eyes with its paws when you show the password.
- HTML: Create the two-part card: a mascot side with Mochi drawn in SVG (ears, eyes, collar, paws, yarn ball and cushion) plus a speech bubble, and a form side with the email and password fields, a 4-part strength meter, a rules checklist and the Create account button.
- CSS: Style the soft clay look with pastel colours, rounded cards and inner shadows, and animate Mochi with breathing, blinking, ear twitches, a head tilt, paws that slide up to cover the eyes, and moods like a worried frown or happy sparkles. The layout also adapts for small screens.
- JavaScript: Make Mochi’s pupils follow the text caret or the mouse, measure password strength with an entropy score, update the meter, checklist and Mochi’s mood live, and handle show or hide password, the Caps Lock warning, the strong password generator and the demo submit.
This project teaches how to build an animated login form using HTML, CSS, and JavaScript by combining an SVG mascot, caret tracking with a hidden canvas, CSS class based moods and animations, and a simple password strength score.
HTML :
HTML: Builds the card with Mochi the cat drawn in SVG (head, eyes, collar, bell, paws and thumbs up), the speech bubble, and the form with email and password fields, the show or hide button, the Generate button, the 4-part strength meter, the rules checklist and the Create account button.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Animated Login Form | Coding Stella</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@500;600;700;800;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="blob blob-1"></div>
<div class="blob blob-2"></div>
<main class="card" id="card">
<!-- Mascot side -->
<section class="stage" id="stage">
<span class="stage-chip"><i></i>Meet Mochi</span>
<svg class="deco deco-1" viewBox="0 0 24 24"><ellipse cx="12" cy="15.5" rx="5" ry="4.2"/><circle cx="6" cy="10" r="2.2"/><circle cx="10" cy="6.5" r="2.2"/><circle cx="14" cy="6.5" r="2.2"/><circle cx="18" cy="10" r="2.2"/></svg>
<svg class="deco deco-2" viewBox="0 0 24 24"><ellipse cx="12" cy="15.5" rx="5" ry="4.2"/><circle cx="6" cy="10" r="2.2"/><circle cx="10" cy="6.5" r="2.2"/><circle cx="14" cy="6.5" r="2.2"/><circle cx="18" cy="10" r="2.2"/></svg>
<svg class="deco deco-3" viewBox="0 0 24 24"><ellipse cx="12" cy="15.5" rx="5" ry="4.2"/><circle cx="6" cy="10" r="2.2"/><circle cx="10" cy="6.5" r="2.2"/><circle cx="14" cy="6.5" r="2.2"/><circle cx="18" cy="10" r="2.2"/></svg>
<svg class="buddy" id="buddy" viewBox="0 0 240 240" aria-hidden="true">
<defs>
<radialGradient id="fur" cx=".35" cy=".28" r=".85">
<stop offset="0" stop-color="#ffdcb8"/>
<stop offset=".55" stop-color="#ffb985"/>
<stop offset="1" stop-color="#ef9461"/>
</radialGradient>
<radialGradient id="cream" cx=".4" cy=".3" r=".8">
<stop offset="0" stop-color="#fffdf9"/>
<stop offset="1" stop-color="#ffe6d2"/>
</radialGradient>
<radialGradient id="pink" cx=".4" cy=".3" r=".8">
<stop offset="0" stop-color="#ffd3dc"/>
<stop offset="1" stop-color="#ff9fb3"/>
</radialGradient>
<radialGradient id="gold" cx=".35" cy=".3" r=".8">
<stop offset="0" stop-color="#fff4c2"/>
<stop offset="1" stop-color="#f3b42c"/>
</radialGradient>
<radialGradient id="iris" cx=".5" cy=".78" r=".8">
<stop offset="0" stop-color="#d98a45"/>
<stop offset=".45" stop-color="#5a3024"/>
<stop offset="1" stop-color="#26150f"/>
</radialGradient>
<radialGradient id="yarn" cx=".35" cy=".3" r=".8">
<stop offset="0" stop-color="#d4f5e5"/>
<stop offset="1" stop-color="#7fd3aa"/>
</radialGradient>
<linearGradient id="cushion" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stop-color="#ffd0c6"/>
<stop offset="1" stop-color="#ffa597"/>
</linearGradient>
<filter id="clay" x="-20%" y="-20%" width="140%" height="150%">
<feDropShadow dx="0" dy="5" stdDeviation="4" flood-color="#c4683a" flood-opacity=".22"/>
</filter>
<filter id="soft" x="-50%" y="-50%" width="200%" height="200%">
<feGaussianBlur stdDeviation="5"/>
</filter>
</defs>
<ellipse class="shadow" cx="120" cy="238" rx="96" ry="7"/>
<path class="sparkle s1" d="M24 58 l3 9 9 3 -9 3 -3 9 -3 -9 -9 -3 9 -3z"/>
<path class="sparkle s2" d="M214 36 l2.5 7.5 7.5 2.5 -7.5 2.5 -2.5 7.5 -2.5 -7.5 -7.5 -2.5 7.5 -2.5z"/>
<path class="sparkle s3" d="M222 110 l3 9 9 3 -9 3 -3 9 -3 -9 -9 -3 9 -3z"/>
<path class="sparkle s4" d="M14 132 l2.5 7.5 7.5 2.5 -7.5 2.5 -2.5 7.5 -2.5 -7.5 -7.5 -2.5 7.5 -2.5z"/>
<!-- Cushion + yarn ball -->
<ellipse cx="120" cy="222" rx="92" ry="16" fill="url(#cushion)" filter="url(#clay)"/>
<ellipse cx="112" cy="214" rx="66" ry="5" fill="#fff" opacity=".45" filter="url(#soft)"/>
<g class="yarn">
<path class="yarn-thread" d="M44 222 C62 240 90 238 102 230"/>
<circle cx="32" cy="208" r="18" fill="url(#yarn)" filter="url(#clay)"/>
<path class="yarn-line" d="M17 202 q15 -10 30 4 M15 211 q17 -8 34 6 M21 221 q12 -6 22 2"/>
</g>
<g class="float">
<path class="tail" d="M168 206 C200 208 214 182 206 156 C202 142 212 130 222 132"/>
<ellipse cx="120" cy="194" rx="60" ry="34" fill="url(#fur)" filter="url(#clay)"/>
<ellipse cx="120" cy="198" rx="32" ry="22" fill="url(#cream)"/>
<!-- Head: .head tilts, .head-inner nods -->
<g class="head">
<g class="head-inner">
<g class="ear ear-l">
<path d="M50 100 C44 66 50 40 60 32 C74 36 96 54 106 68Z" fill="url(#fur)" filter="url(#clay)"/>
<path d="M60 84 C58 64 62 50 66 46 C74 50 86 60 92 68Z" fill="url(#pink)"/>
</g>
<g class="ear ear-r">
<path d="M190 100 C196 66 190 40 180 32 C166 36 144 54 134 68Z" fill="url(#fur)" filter="url(#clay)"/>
<path d="M180 84 C182 64 178 50 174 46 C166 50 154 60 148 68Z" fill="url(#pink)"/>
</g>
<ellipse cx="120" cy="120" rx="80" ry="64" fill="url(#fur)" filter="url(#clay)"/>
<ellipse cx="88" cy="82" rx="30" ry="14" fill="#fff" opacity=".45" filter="url(#soft)"/>
<path class="stripe" d="M110 58 q2 10 0 16 M120 56 q2 12 0 20 M130 58 q2 10 0 16"/>
<ellipse cx="106" cy="146" rx="18" ry="13" fill="url(#cream)"/>
<ellipse cx="134" cy="146" rx="18" ry="13" fill="url(#cream)"/>
<g class="whiskers">
<path class="whisker" d="M78 142 L52 136 M78 150 L54 154"/>
<path class="whisker" d="M162 142 L188 136 M162 150 L186 154"/>
</g>
<ellipse class="cheek" cx="72" cy="132" rx="12" ry="7"/>
<ellipse class="cheek" cx="168" cy="132" rx="12" ry="7"/>
<path class="brow brow-l" d="M82 92 Q92 88 102 92"/>
<path class="brow brow-r" d="M138 92 Q148 88 158 92"/>
<!-- Eyes: .white is the hit-area, .pupil moves, glints stay still -->
<g class="eye eye-l" transform="translate(92 116)">
<g class="lid">
<circle class="white" r="15"/>
<ellipse class="eyeball" rx="13" ry="15" fill="url(#iris)"/>
<g class="pupil"><ellipse class="core" rx="7" ry="9"/></g>
<ellipse class="eye-rim" rx="13" ry="15"/>
<circle class="glint" cx="4.5" cy="-6" r="4.2"/>
<circle class="glint" cx="-4.5" cy="5.5" r="2"/>
<circle class="glint glint-star" cx="-3" cy="-8" r="1.4"/>
<path class="lash" d="M-11 -8 l-6 -4 M-13 -3 l-6 -1"/>
</g>
<path class="happy-eye" d="M-11 4 Q0 -11 11 4"/>
</g>
<g class="eye eye-r" transform="translate(148 116)">
<g class="lid">
<circle class="white" r="15"/>
<ellipse class="eyeball" rx="13" ry="15" fill="url(#iris)"/>
<g class="pupil"><ellipse class="core" rx="7" ry="9"/></g>
<ellipse class="eye-rim" rx="13" ry="15"/>
<circle class="glint" cx="4.5" cy="-6" r="4.2"/>
<circle class="glint" cx="-4.5" cy="5.5" r="2"/>
<circle class="glint glint-star" cx="-3" cy="-8" r="1.4"/>
<path class="lash" d="M11 -8 l6 -4 M13 -3 l6 -1"/>
</g>
<path class="happy-eye" d="M-11 4 Q0 -11 11 4"/>
</g>
<path d="M113 136 Q120 132 127 136 Q124 143 120 144 Q116 143 113 136Z" fill="url(#pink)"/>
<path class="mouth" id="mouth" d="M110 152 Q120 156 130 152 Q120 156 110 152Z"/>
<path class="sweat" d="M190 96 C184 106 184 112 190 114 C196 112 196 106 190 96Z"/>
</g>
</g>
<path class="collar" d="M80 176 Q120 198 160 176"/>
<g class="bell">
<circle cx="120" cy="195" r="8" fill="url(#gold)" filter="url(#clay)"/>
<path class="bell-slit" d="M115 197 h10"/>
<circle cx="120" cy="199.5" r="1.6" fill="#c98a1a"/>
</g>
<g class="paw paw-l">
<ellipse cx="94" cy="214" rx="22" ry="16" fill="url(#cream)" filter="url(#clay)"/>
<path class="toe" d="M87 220 v-6 M94 221 v-7 M101 220 v-6"/>
</g>
<g class="paw paw-r">
<ellipse cx="146" cy="214" rx="22" ry="16" fill="url(#cream)" filter="url(#clay)"/>
<path class="toe" d="M139 220 v-6 M146 221 v-7 M153 220 v-6"/>
</g>
<!-- Thumbs up (outer g positions it, inner g animates) -->
<g transform="translate(184 140)">
<g class="thumb">
<rect x="5" y="0" width="12" height="26" rx="6" fill="url(#cream)" filter="url(#clay)"/>
<rect x="0" y="16" width="32" height="27" rx="12" fill="url(#cream)" filter="url(#clay)"/>
<path class="toe" d="M17 24 h10 M17 32 h10"/>
</g>
</g>
</g>
</svg>
<p class="speech" id="speech">Hi, I'm Mochi! Let's make a strong password.</p>
</section>
<!-- Form side -->
<section class="panel">
<header>
<span class="badge">Secure sign up</span>
<h1>Create your account</h1>
<p class="sub">Pick a password that even Mochi can't guess.</p>
</header>
<form id="form" novalidate>
<div class="field">
<label for="email">Email</label>
<div class="input-wrap" id="emailWrap">
<svg class="ico" viewBox="0 0 24 24"><rect x="3" y="5" width="18" height="14" rx="3"/><path d="m4 7 8 6 8-6"/></svg>
<input id="email" type="email" placeholder="you@example.com" autocomplete="email" spellcheck="false">
<svg class="ico valid" viewBox="0 0 24 24"><path d="m5 12 5 5 9-10"/></svg>
</div>
</div>
<div class="field">
<div class="field-head">
<label for="password">Password</label>
<button type="button" class="link-btn" id="generate">
<svg viewBox="0 0 24 24"><path d="M12 3v3M12 18v3M3 12h3M18 12h3M5.6 5.6l2.1 2.1M16.3 16.3l2.1 2.1M5.6 18.4l2.1-2.1M16.3 7.7l2.1-2.1"/></svg>
Generate
</button>
</div>
<div class="input-wrap" id="pwWrap">
<svg class="ico" viewBox="0 0 24 24"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg>
<input id="password" type="password" placeholder="Enter a password" autocomplete="new-password" spellcheck="false">
<span class="caps" aria-live="polite">
<svg viewBox="0 0 24 24"><path d="M12 4 4 12h4v4h8v-4h4L12 4ZM8 20h8"/></svg>Caps
</span>
<button type="button" class="toggle" id="toggle" aria-label="Show password" aria-pressed="false">
<svg class="i-on" viewBox="0 0 24 24"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/></svg>
<svg class="i-off" viewBox="0 0 24 24"><path d="M3 3l18 18"/><path d="M10.6 5.1A10.4 10.4 0 0 1 12 5c6.5 0 10 7 10 7a17.6 17.6 0 0 1-3.2 4.1M6.6 6.6C3.9 8.4 2 12 2 12s3.5 7 10 7c1.9 0 3.6-.6 5-1.4"/><path d="M9.9 9.9a3 3 0 0 0 4.2 4.2"/></svg>
</button>
</div>
</div>
<div class="meter">
<div class="meter-track">
<span class="seg"><i></i></span><span class="seg"><i></i></span><span class="seg"><i></i></span><span class="seg"><i></i></span>
</div>
<div class="meter-info">
<span class="meter-label" id="label">Start typing</span>
<span class="meter-crack" id="crack"></span>
</div>
</div>
<ul class="rules" id="rules">
<li data-rule="length"><span class="tick"><svg viewBox="0 0 24 24"><path d="m5 12 5 5 9-10"/></svg></span>8+ characters</li>
<li data-rule="lower"><span class="tick"><svg viewBox="0 0 24 24"><path d="m5 12 5 5 9-10"/></svg></span>Lowercase letter</li>
<li data-rule="upper"><span class="tick"><svg viewBox="0 0 24 24"><path d="m5 12 5 5 9-10"/></svg></span>Uppercase letter</li>
<li data-rule="number"><span class="tick"><svg viewBox="0 0 24 24"><path d="m5 12 5 5 9-10"/></svg></span>Number</li>
<li data-rule="symbol"><span class="tick"><svg viewBox="0 0 24 24"><path d="m5 12 5 5 9-10"/></svg></span>Symbol (!@#$)</li>
<li data-rule="common"><span class="tick"><svg viewBox="0 0 24 24"><path d="m5 12 5 5 9-10"/></svg></span>No common pattern</li>
</ul>
<button type="submit" class="submit" id="submit" disabled>
<span class="submit-text">Create account</span>
<span class="spinner"></span>
</button>
<p class="signin">Already have an account? <a href="#">Sign in</a></p>
</form>
</section>
</main>
<div class="toast" id="toast" role="status" aria-live="polite">
<svg viewBox="0 0 24 24"><path d="m5 12 5 5 9-10"/></svg>
<span id="toastText"></span>
</div>
<script src="script.js"></script>
</body>
</html>
CSS :
CSS: Gives the page its pastel clay style and brings Mochi to life with breathing, blinking, ear twitches, head tilts, mood changes, paws that cover the eyes, the segmented meter colours, the checklist ticks and the responsive layout.
/* Animated Login Form — Coding Stella */
:root {
--card: #fffaf6;
--text: #4a3430;
--muted: #a08a84;
--mint: #dff5ec;
--coral: #ff8f6b;
--coral-2: #ff7a63;
--green: #5fcf96;
--field: #fdf1eb;
--meter: #eadbd3; /* updated from JS by strength */
/* clay look: raised (out) and pressed (in) */
--clay-out:
0 24px 50px -18px rgba(196, 120, 90, 0.35),
0 6px 14px -6px rgba(196, 120, 90, 0.2),
inset 0 2px 0 rgba(255, 255, 255, 0.9),
inset 0 -6px 14px rgba(230, 180, 160, 0.25);
--clay-in:
inset 4px 4px 10px rgba(214, 170, 150, 0.35),
inset -4px -4px 10px rgba(255, 255, 255, 0.95);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
min-height: 100vh;
display: grid;
place-items: center;
padding: 24px 16px;
overflow-x: hidden;
font-family: "Nunito", system-ui, sans-serif;
color: var(--text);
background: linear-gradient(135deg, #ffe6da 0%, #fff4ea 45%, #e0f5ec 100%);
-webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; }
.blob {
position: fixed;
z-index: -1;
border-radius: 50%;
filter: blur(60px);
opacity: 0.7;
}
.blob-1 { width: 420px; height: 420px; top: -120px; left: -100px; background: #ffd1c1; }
.blob-2 { width: 460px; height: 460px; bottom: -160px; right: -120px; background: #c9efdd; }
/* ---------- Card ---------- */
.card {
width: min(880px, 100%);
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
padding: 12px;
border-radius: 34px;
background: var(--card);
box-shadow: var(--clay-out);
}
/* ---------- Stage ---------- */
.stage {
position: relative;
overflow: hidden;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 16px;
padding: 52px 24px 28px;
border-radius: 26px;
background: linear-gradient(160deg, #e6f8f0, #d2f0e3);
box-shadow:
inset 0 3px 0 rgba(255, 255, 255, 0.8),
inset 0 -10px 24px rgba(120, 190, 160, 0.18);
}
.stage-chip {
position: absolute;
top: 16px;
left: 16px;
display: inline-flex;
align-items: center;
gap: 8px;
padding: 6px 12px;
border-radius: 99px;
font-size: 12px;
font-weight: 800;
background: #fff;
box-shadow: 0 6px 14px -6px rgba(80, 150, 120, 0.4), inset 0 -2px 0 rgba(0, 0, 0, 0.04);
}
.stage-chip i {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--meter);
box-shadow: inset 0 -2px 2px rgba(0, 0, 0, 0.12), inset 0 2px 2px rgba(255, 255, 255, 0.6);
transition: background 0.4s;
}
.deco {
position: absolute;
width: 26px;
height: 26px;
fill: #fff;
opacity: 0.75;
filter: drop-shadow(0 4px 6px rgba(80, 150, 120, 0.25));
animation: drift 6s ease-in-out infinite;
}
.deco-1 { top: 22%; right: 14%; rotate: 18deg; }
.deco-2 { bottom: 26%; left: 10%; width: 20px; height: 20px; rotate: -20deg; animation-delay: -2s; }
.deco-3 { top: 14%; left: 42%; width: 16px; height: 16px; rotate: 8deg; opacity: 0.55; animation-delay: -4s; }
@keyframes drift { 50% { transform: translateY(-10px); } }
.speech {
position: relative;
max-width: 260px;
min-height: 44px;
display: grid;
place-items: center;
padding: 10px 16px;
border-radius: 18px;
font-size: 13.5px;
font-weight: 800;
line-height: 1.4;
text-align: center;
background: #fff;
box-shadow: 0 14px 26px -12px rgba(80, 150, 120, 0.45), inset 0 -3px 0 rgba(0, 0, 0, 0.04);
}
.speech::before {
content: "";
position: absolute;
top: -7px;
left: 50%;
width: 16px;
height: 16px;
translate: -50% 0;
rotate: 45deg;
border-radius: 4px;
background: #fff;
}
.speech.pop { animation: pop 0.4s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes pop { from { transform: scale(0.88); } }
/* ---------- Mochi ---------- */
.buddy {
width: min(240px, 80%);
height: auto;
overflow: visible;
}
/* SVG parts animate around their own box */
.float, .head, .ear, .bell, .yarn, .tail, .thumb,
.whiskers path, .brow, .lid, .core, .sparkle {
transform-box: fill-box;
}
.float {
transform-origin: 50% 100%;
animation: breathe 3.4s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: scale(1.012, 1.03); } }
.shadow { fill: #7fbfa3; opacity: 0.35; filter: blur(3px); }
.tail {
fill: none;
stroke: #f2a06c;
stroke-width: 16;
stroke-linecap: round;
transform-origin: 0% 100%;
animation: tail 2.6s ease-in-out infinite;
}
@keyframes tail { 50% { transform: rotate(-8deg); } }
.stripe { fill: none; stroke: #e98b55; stroke-width: 5; stroke-linecap: round; opacity: 0.7; }
.whisker { fill: none; stroke: #d69a7a; stroke-width: 2.5; stroke-linecap: round; }
.toe { fill: none; stroke: #e2b8a2; stroke-width: 2.5; stroke-linecap: round; }
.cheek { fill: #ff8fa6; opacity: 0.45; filter: blur(1.5px); transition: opacity 0.4s; }
.mouth { fill: #7a3f3f; stroke: #7a3f3f; stroke-width: 3; stroke-linejoin: round; }
.sweat { fill: #9fdcff; opacity: 0; transition: opacity 0.3s; }
.brow {
fill: none;
stroke: #8a5440;
stroke-width: 3.5;
stroke-linecap: round;
transform-origin: center;
transition: transform 0.4s cubic-bezier(0.3, 1.4, 0.5, 1);
}
/* head tilt (outer) + nod (inner) */
.head {
transform-origin: 50% 96%;
transition: transform 0.55s cubic-bezier(0.34, 1.5, 0.5, 1);
}
.buddy.tilt .head { transform: rotate(-7deg); }
.buddy.thumbs-up .head { transform: rotate(6deg); }
.buddy.nod .head-inner { animation: nod 0.26s ease; }
@keyframes nod { 50% { transform: translateY(3px); } }
.whiskers path { transform-origin: 100% 50%; }
.whiskers path + path { transform-origin: 0% 50%; }
.buddy.nod .whiskers path { animation: whisk 0.26s ease; }
@keyframes whisk { 50% { transform: rotate(-6deg); } }
.ear { transform-origin: 50% 100%; }
.buddy.twitch .ear-r { animation: twitch-r 0.45s ease; }
.buddy.twitch-l .ear-l { animation: twitch-l 0.45s ease; }
@keyframes twitch-r { 30% { transform: rotate(12deg); } 60% { transform: rotate(-4deg); } }
@keyframes twitch-l { 30% { transform: rotate(-12deg); } 60% { transform: rotate(4deg); } }
/* eyes */
.white { fill: transparent; }
.eyeball { filter: drop-shadow(0 2px 1.5px rgba(120, 50, 20, 0.25)); }
.eye-rim { fill: none; stroke: #2a1611; stroke-width: 1.6; opacity: 0.6; }
.glint { fill: #fff; }
.glint-star { opacity: 0; transition: opacity 0.3s; }
.lash { fill: none; stroke: #3d2219; stroke-width: 2.4; stroke-linecap: round; }
.core {
fill: #0e0807;
transform-origin: center;
transition: transform 0.45s cubic-bezier(0.34, 1.5, 0.5, 1);
}
.lid {
transform-origin: center;
transition: transform 0.09s ease, opacity 0.15s;
}
.buddy.blink .lid,
.buddy.wink .eye-l .lid { transform: scaleY(0.1); }
.happy-eye {
fill: none;
stroke: #3d2a2a;
stroke-width: 4;
stroke-linecap: round;
opacity: 0;
transition: opacity 0.15s;
}
.buddy.happy .lid { opacity: 0; }
.buddy.happy .happy-eye { opacity: 1; }
/* collar, bell, yarn */
.collar {
fill: none;
stroke: #ff8f8f;
stroke-width: 9;
stroke-linecap: round;
filter: drop-shadow(0 2px 2px rgba(200, 90, 80, 0.25));
}
.bell { transform-origin: 50% 0%; }
.bell-slit { stroke: #c98a1a; stroke-width: 1.8; stroke-linecap: round; }
.buddy.jingle .bell { animation: jingle 0.6s ease; }
@keyframes jingle {
20% { transform: rotate(18deg); }
45% { transform: rotate(-14deg); }
70% { transform: rotate(8deg); }
}
.yarn { transform-origin: 50% 100%; animation: wobble 4s ease-in-out infinite; }
@keyframes wobble { 50% { transform: rotate(-4deg); } }
.yarn-line, .yarn-thread { fill: none; stroke: #56b98a; stroke-width: 2; stroke-linecap: round; opacity: 0.8; }
.yarn-thread { stroke: #7fd3aa; stroke-width: 2.5; }
/* paws cover the eyes when the password is shown */
.paw { transition: transform 0.55s cubic-bezier(0.34, 1.45, 0.5, 1), opacity 0.25s; }
.buddy.covered .paw-l { transform: translate(-2px, -100px); }
.buddy.covered .paw-r { transform: translate(2px, -100px); }
.buddy.covered.peek .paw-r { transform: translate(2px, -68px); }
.buddy.thumbs-up .paw-r { opacity: 0; }
.thumb {
opacity: 0;
transform-origin: 50% 100%;
transform: translate(-10px, 30px) rotate(-30deg) scale(0.3);
transition: transform 0.5s cubic-bezier(0.34, 1.6, 0.5, 1), opacity 0.25s;
}
.buddy.thumbs-up .thumb {
opacity: 1;
transform: none;
animation: thumb-wiggle 1.4s ease-in-out 0.5s infinite;
}
@keyframes thumb-wiggle { 50% { transform: rotate(-8deg); } }
.sparkle {
fill: #ffc94d;
opacity: 0;
filter: drop-shadow(0 2px 3px rgba(230, 160, 40, 0.45));
transform-origin: center;
transform: scale(0.3);
transition: opacity 0.4s, transform 0.4s;
}
/* moods (set from password strength) */
.mood-weak .brow-l { transform: rotate(-18deg) translateY(1px); }
.mood-weak .brow-r { transform: rotate(18deg) translateY(1px); }
.mood-weak .sweat { opacity: 1; animation: drip 1.6s ease-in infinite; }
.mood-weak .core { transform: scale(0.72); }
.mood-fair .brow-l { transform: rotate(-7deg); }
.mood-fair .brow-r { transform: rotate(7deg); }
.mood-good .brow { transform: translateY(-2px); }
.mood-good .core { transform: scale(1.12); }
.mood-strong .brow { transform: translateY(-4px); }
.mood-strong .core { transform: scale(1.3); }
.mood-strong .cheek { opacity: 0.8; }
.mood-strong .tail { animation-duration: 0.8s; }
.mood-strong .sparkle { opacity: 1; animation: twinkle 1.6s ease-in-out infinite; }
.mood-strong .s2 { animation-delay: 0.3s; }
.mood-strong .s3 { animation-delay: 0.6s; }
.mood-strong .s4 { animation-delay: 0.9s; }
.buddy.thumbs-up .core { transform: scale(1.2); }
.mood-strong .glint-star,
.buddy.thumbs-up .glint-star { opacity: 1; }
@keyframes drip {
80% { opacity: 1; }
100% { transform: translateY(10px); opacity: 0; }
}
@keyframes twinkle {
0%, 100% { transform: scale(1); }
50% { transform: scale(0.55) rotate(45deg); }
}
.buddy.celebrate .float { animation: jump 0.7s cubic-bezier(0.3, 1.5, 0.5, 1) 2; }
@keyframes jump { 40% { transform: translateY(-24px); } }
/* ---------- Form panel ---------- */
.panel { padding: 30px 28px 22px; }
.badge {
display: inline-block;
padding: 5px 12px;
border-radius: 99px;
font-size: 11px;
font-weight: 800;
color: #e46d4e;
background: #ffece4;
box-shadow: inset 0 -2px 0 rgba(228, 109, 78, 0.12);
}
h1 {
margin-top: 10px;
font-size: 28px;
font-weight: 900;
line-height: 1.1;
letter-spacing: -0.02em;
}
.sub { margin-top: 4px; font-size: 14px; font-weight: 600; color: var(--muted); }
form { display: grid; gap: 13px; margin-top: 20px; }
.field label {
display: block;
margin-bottom: 6px;
padding-left: 4px;
font-size: 13px;
font-weight: 800;
transition: color 0.25s;
}
.field:focus-within label { color: var(--coral-2); }
.field-head { display: flex; align-items: center; justify-content: space-between; }
.link-btn {
display: inline-flex;
align-items: center;
gap: 6px;
margin-bottom: 6px;
padding: 4px 10px;
border: 0;
border-radius: 99px;
font-size: 12px;
font-weight: 800;
color: #2f8f68;
background: var(--mint);
box-shadow: 0 4px 10px -4px rgba(47, 143, 104, 0.45), inset 0 -2px 0 rgba(47, 143, 104, 0.15), inset 0 2px 0 #fff;
transition: transform 0.2s;
}
.link-btn:hover { transform: translateY(-1px); }
.link-btn:active { transform: translateY(1px) scale(0.97); }
.link-btn:disabled { opacity: 0.6; cursor: wait; }
.link-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.input-wrap {
display: flex;
align-items: center;
gap: 10px;
height: 48px;
padding: 0 8px 0 15px;
border-radius: 16px;
background: var(--field);
box-shadow: var(--clay-in);
transition: box-shadow 0.25s;
}
.input-wrap:focus-within { box-shadow: var(--clay-in), 0 0 0 3px rgba(255, 143, 107, 0.35); }
.ico {
flex: none;
width: 18px;
height: 18px;
fill: none;
stroke: #c49a8c;
stroke-width: 2.2;
stroke-linecap: round;
stroke-linejoin: round;
}
.ico.valid {
margin-right: 8px;
stroke: var(--green);
stroke-width: 3;
opacity: 0;
transform: scale(0.5);
transition: 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.input-wrap.is-valid .ico.valid { opacity: 1; transform: scale(1); }
input {
flex: 1;
min-width: 0;
height: 100%;
border: 0;
outline: 0;
background: transparent;
font: inherit;
font-size: 15px;
font-weight: 700;
color: var(--text);
caret-color: var(--coral);
}
input::placeholder { color: #ccb3aa; font-weight: 600; }
.caps {
display: none;
flex: none;
align-items: center;
gap: 4px;
padding: 4px 9px;
border-radius: 99px;
font-size: 11.5px;
font-weight: 900;
color: #c2562f;
background: #ffe6da;
animation: pop 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.caps svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linejoin: round; }
.input-wrap.caps-on .caps { display: inline-flex; }
.toggle {
flex: none;
display: grid;
place-items: center;
width: 34px;
height: 34px;
border: 0;
border-radius: 11px;
color: #b48c7e;
background: #fff;
box-shadow: 0 4px 10px -4px rgba(196, 120, 90, 0.4), inset 0 -2px 0 rgba(0, 0, 0, 0.04);
transition: transform 0.2s, color 0.2s;
}
.toggle:hover { color: var(--coral-2); }
.toggle:active { transform: scale(0.94); }
.toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.toggle .i-off,
.toggle[aria-pressed="true"] .i-on { display: none; }
.toggle[aria-pressed="true"] .i-off { display: block; }
/* ---------- Strength meter ---------- */
.meter-track { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.seg {
height: 10px;
padding: 2px;
border-radius: 99px;
background: var(--field);
box-shadow: inset 2px 2px 5px rgba(214, 170, 150, 0.4), inset -2px -2px 5px #fff;
}
.seg i {
display: block;
width: 0;
height: 100%;
border-radius: 99px;
background: var(--meter);
box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5), inset 0 -1px 2px rgba(0, 0, 0, 0.1);
transition: width 0.3s ease, background 0.4s;
}
.seg:nth-child(2) i { transition-delay: 0.05s; }
.seg:nth-child(3) i { transition-delay: 0.1s; }
.seg:nth-child(4) i { transition-delay: 0.15s; }
.meter-info {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 8px;
padding: 0 4px;
font-size: 12.5px;
}
.meter-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 900; }
.meter-label::before {
content: "";
width: 11px;
height: 11px;
border-radius: 50%;
background: var(--meter);
box-shadow: inset 0 -2px 2px rgba(0, 0, 0, 0.12), inset 0 2px 2px rgba(255, 255, 255, 0.6);
transition: background 0.4s;
}
.meter-crack { font-weight: 700; color: var(--muted); text-align: right; }
/* ---------- Rules checklist ---------- */
.rules {
list-style: none;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px 12px;
padding: 0 4px;
}
.rules li {
display: flex;
align-items: center;
gap: 9px;
font-size: 12.5px;
font-weight: 700;
color: var(--muted);
transition: color 0.3s;
}
.tick {
flex: none;
display: grid;
place-items: center;
width: 18px;
height: 18px;
border-radius: 50%;
background: var(--field);
box-shadow: inset 2px 2px 4px rgba(214, 170, 150, 0.45), inset -2px -2px 4px #fff;
transition: background 0.25s, box-shadow 0.25s, transform 0.35s cubic-bezier(0.3, 1.8, 0.5, 1);
}
.tick svg {
width: 12px;
height: 12px;
fill: none;
stroke: #fff;
stroke-width: 3.6;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 24;
stroke-dashoffset: 24; /* drawn in when the rule passes */
transition: stroke-dashoffset 0.35s ease 0.05s;
}
.rules li.ok { color: var(--text); }
.rules li.ok .tick {
background: var(--green);
transform: scale(1.1);
box-shadow:
inset 0 2px 0 rgba(255, 255, 255, 0.5),
inset 0 -2px 3px rgba(0, 0, 0, 0.12),
0 3px 8px -2px rgba(95, 207, 150, 0.8);
}
.rules li.ok .tick svg { stroke-dashoffset: 0; }
/* ---------- Submit ---------- */
.submit {
position: relative;
height: 50px;
margin-top: 2px;
border: 0;
border-radius: 16px;
font-size: 15px;
font-weight: 900;
color: #fff;
background: linear-gradient(180deg, #ffa182, var(--coral-2));
box-shadow:
0 14px 24px -10px rgba(255, 122, 99, 0.7),
inset 0 3px 0 rgba(255, 255, 255, 0.4),
inset 0 -5px 0 rgba(200, 70, 50, 0.2);
transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
}
.submit:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.04); }
.submit:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.submit:disabled {
cursor: not-allowed;
color: #c9b2a9;
background: #f6ebe5;
box-shadow: var(--clay-in);
}
.submit.loading {
color: #fff;
cursor: wait;
background: linear-gradient(180deg, #ffa182, var(--coral-2));
box-shadow: 0 14px 24px -10px rgba(255, 122, 99, 0.7), inset 0 3px 0 rgba(255, 255, 255, 0.4);
}
.submit.loading .submit-text { opacity: 0; }
.spinner {
position: absolute;
inset: 50% auto auto 50%;
width: 22px;
height: 22px;
margin: -11px 0 0 -11px;
border-radius: 50%;
border: 3px solid rgba(255, 255, 255, 0.4);
border-top-color: #fff;
opacity: 0;
}
.submit.loading .spinner { opacity: 1; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.signin { margin-top: -2px; text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); }
.signin a {
color: var(--coral-2);
font-weight: 900;
text-decoration: none;
background: linear-gradient(currentColor, currentColor) 0 100% / 0 2px no-repeat;
transition: background-size 0.3s;
}
.signin a:hover { background-size: 100% 2px; }
/* ---------- Toast ---------- */
.toast {
position: fixed;
left: 50%;
bottom: 28px;
display: flex;
align-items: center;
gap: 10px;
padding: 12px 20px 12px 12px;
border-radius: 99px;
font-size: 14.5px;
font-weight: 800;
background: #fff;
box-shadow: 0 18px 40px -14px rgba(196, 120, 90, 0.5), inset 0 -3px 0 rgba(0, 0, 0, 0.04);
opacity: 0;
transform: translate(-50%, 200%);
transition: transform 0.45s cubic-bezier(0.3, 1.4, 0.5, 1), opacity 0.25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast svg {
width: 26px;
height: 26px;
padding: 5px;
border-radius: 50%;
background: var(--green);
fill: none;
stroke: #fff;
stroke-width: 3.4;
stroke-linecap: round;
stroke-linejoin: round;
box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45), inset 0 -2px 3px rgba(0, 0, 0, 0.12);
}
/* ---------- Responsive ---------- */
@media (max-width: 860px) {
.card { grid-template-columns: 1fr; }
.buddy { width: 200px; }
.panel { padding: 24px 14px 18px; }
}
@media (max-width: 420px) {
.card { padding: 10px; }
.rules { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
}
}
JavaScript:
JavaScript: Moves Mochi’s pupils toward the text caret, scores the password and updates the meter, label, crack time, checklist and Mochi’s mood, and handles the email reactions, show or hide password, Caps Lock warning, password generator and demo submit.
// Animated Login Form — Coding Stella
const $ = (sel) => document.querySelector(sel);
const card = $("#card");
const stage = $("#stage");
const buddy = $("#buddy");
const mouth = $("#mouth");
const speech = $("#speech");
const form = $("#form");
const email = $("#email");
const emailWrap = $("#emailWrap");
const pw = $("#password");
const pwWrap = $("#pwWrap");
const toggle = $("#toggle");
const genBtn = $("#generate");
const segs = document.querySelectorAll(".seg i");
const label = $("#label");
const crack = $("#crack");
const ruleItems = document.querySelectorAll("#rules li");
const submit = $("#submit");
const toast = $("#toast");
const toastText = $("#toastText");
const LABELS = ["Start typing", "Weak", "Fair", "Good", "Strong"];
const COLORS = [null, "#ff7a7a", "#ffb35c", "#ffd34d", "#5fcf96"];
const MOODS = ["mood-empty", "mood-weak", "mood-fair", "mood-good", "mood-strong"];
const MOUTHS = [
{ curve: 3, open: 1 }, // empty
{ curve: -6, open: 1 }, // weak: frown
{ curve: 0, open: 1 }, // fair
{ curve: 6, open: 1 }, // good
{ curve: 11, open: 0.1 }, // strong: open grin
];
const eyes = [...buddy.querySelectorAll(".eye")].map((eye) => ({
white: eye.querySelector(".white"),
pupil: eye.querySelector(".pupil"),
x: 0, y: 0, tx: 0, ty: 0,
}));
let focused = null;
let current = analyze("");
let lastScore = 0;
let wasValid = false;
let capsOn = false;
/* ---------- Eye tracking ---------- */
function lookAt(px, py) {
eyes.forEach((eye) => {
const r = eye.white.getBoundingClientRect();
const dx = px - (r.left + r.width / 2);
const dy = py - (r.top + r.height / 2);
const dist = Math.hypot(dx, dy) || 1;
const reach = 4 * Math.min(1, dist / (r.width * 4));
eye.tx = (dx / dist) * reach;
eye.ty = (dy / dist) * reach;
});
}
// Measure the text before the caret to find where it sits on screen
const measure = document.createElement("canvas").getContext("2d");
function caretPoint(input) {
const cs = getComputedStyle(input);
measure.font = `${cs.fontWeight} ${cs.fontSize} ${cs.fontFamily}`;
let text = input.value.slice(0, input.selectionEnd ?? input.value.length);
if (input.type === "password") text = "•".repeat(text.length);
const box = input.getBoundingClientRect();
const width = measure.measureText(text).width - input.scrollLeft;
return { x: box.left + Math.max(0, Math.min(width, box.width)), y: box.top + box.height / 2 };
}
function trackCaret() {
if (!focused) return;
const p = caretPoint(focused);
lookAt(p.x, p.y);
}
// Ease pupils and mouth toward their targets every frame
const face = { curve: 3, open: 1 };
function tick() {
eyes.forEach((eye) => {
eye.x += (eye.tx - eye.x) * 0.2;
eye.y += (eye.ty - eye.y) * 0.2;
eye.pupil.setAttribute("transform", `translate(${eye.x.toFixed(2)} ${eye.y.toFixed(2)})`);
});
const goal = MOUTHS[current.score];
face.curve += (goal.curve - face.curve) * 0.15;
face.open += (goal.open - face.open) * 0.15;
const top = (152 + face.curve).toFixed(2);
const bottom = (152 + face.curve * face.open).toFixed(2);
mouth.setAttribute("d", `M110 152 Q120 ${top} 130 152 Q120 ${bottom} 110 152Z`);
requestAnimationFrame(tick);
}
requestAnimationFrame(tick);
// Re-trigger a one-shot animation class on Mochi
const pulseTimers = {};
function pulse(cls, ms) {
buddy.classList.remove(cls);
void buddy.getBoundingClientRect(); // force reflow so the animation restarts
buddy.classList.add(cls);
clearTimeout(pulseTimers[cls]);
pulseTimers[cls] = setTimeout(() => buddy.classList.remove(cls), ms);
}
function loop(fn, min, spread) {
setTimeout(() => { fn(); loop(fn, min, spread); }, min + Math.random() * spread);
}
loop(() => pulse("blink", 140), 2200, 3200);
loop(() => pulse(Math.random() < 0.5 ? "twitch" : "twitch-l", 460), 3500, 4500);
/* ---------- Password strength ---------- */
const COMMON = [
"password", "passw0rd", "123456", "12345678", "123123", "654321", "111111",
"000000", "qwerty", "qwertyuiop", "asdf", "zxcv", "1q2w3e", "letmein", "admin",
"welcome", "iloveyou", "monkey", "dragon", "abc123", "football", "baseball",
"sunshine", "princess", "login", "master", "hello", "freedom", "whatever",
"trustno1", "shadow", "superman", "batman", "secret",
];
const LEET = { 0: "o", 1: "i", 3: "e", 4: "a", 5: "s", 7: "t", "@": "a", $: "s", "!": "i" };
// Catches common words, including leetspeak like "P@ssw0rd"
function isCommon(value) {
const lower = value.toLowerCase();
const plain = lower.replace(/[013457@$!]/g, (ch) => LEET[ch]).replace(/[^a-z]/g, "");
return COMMON.some((word) =>
word.length >= value.length * 0.5 && (lower.includes(word) || (plain && plain.includes(word)))
);
}
// abc, 123, cba ...
function hasSequence(value) {
for (let i = 0; i < value.length - 2; i++) {
const a = value.charCodeAt(i), b = value.charCodeAt(i + 1), c = value.charCodeAt(i + 2);
if ((b - a === 1 && c - b === 1) || (a - b === 1 && b - c === 1)) return true;
}
return false;
}
// Assumes an attacker making 10 billion guesses per second
function crackTime(entropy) {
const seconds = Math.pow(2, entropy - 1) / 1e10;
if (seconds < 1) return "instantly";
if (seconds >= 3153600000) return "centuries";
const units = [["year", 31536000], ["month", 2592000], ["day", 86400], ["hour", 3600], ["minute", 60], ["second", 1]];
for (const [name, size] of units) {
if (seconds >= size) {
const n = Math.round(seconds / size);
return `${n} ${name}${n > 1 ? "s" : ""}`;
}
}
}
function analyze(value) {
const rules = {
length: value.length >= 8,
lower: /[a-z]/.test(value),
upper: /[A-Z]/.test(value),
number: /\d/.test(value),
symbol: /[^A-Za-z0-9]/.test(value),
common: value.length > 0 && !isCommon(value),
};
if (!value) return { rules, score: 0, percent: 0, crack: "" };
const pool = (rules.lower ? 26 : 0) + (rules.upper ? 26 : 0) + (rules.number ? 10 : 0) + (rules.symbol ? 33 : 0);
let entropy = value.length * Math.log2(pool);
if (/(.)\1{2,}/.test(value)) entropy *= 0.6; // repeats like "aaa"
if (hasSequence(value)) entropy *= 0.65;
if (!rules.common) entropy = Math.min(entropy, 18);
let score = entropy < 28 ? 1 : entropy < 45 ? 2 : entropy < 65 ? 3 : 4;
let percent = Math.max(8, Math.min(100, (entropy / 80) * 100));
if (!rules.length) {
score = Math.min(score, 2);
percent = Math.min(percent, 50);
}
if (!rules.common) score = 1;
return { rules, score, percent, crack: crackTime(entropy) };
}
/* ---------- UI ---------- */
const emailOk = () => /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email.value.trim());
function say(text) {
if (speech.textContent === text) return;
speech.textContent = text;
speech.classList.remove("pop");
void speech.offsetWidth;
speech.classList.add("pop");
}
function updateSpeech() {
if (buddy.classList.contains("covered")) {
return say(buddy.classList.contains("peek") ? "Okay… just a tiny peek!" : "I'm not looking, promise!");
}
if (capsOn && focused === pw) return say("Psst… Caps Lock is on!");
if (focused === email) {
if (!email.value) return say("Nice to meet you! What's your email?");
return say(emailOk() ? "Purr-fect! That email looks good." : "Hmm, I'm reading along…");
}
if (focused === pw || pw.value) {
const lines = [
"Now the secret part. Make it strong!",
current.rules.common ? "Way too easy. Even I could guess that!" : "Everyone uses that one. Be original!",
"Getting there! Mix in more variety.",
"Nice! A little longer makes it great.",
"Rock solid! Nobody's cracking that.",
];
return say(lines[current.score]);
}
say("Hi, I'm Mochi! Let's make a strong password.");
}
function update() {
current = analyze(pw.value);
const hasValue = pw.value.length > 0;
const valid = emailOk();
const onEmail = focused === email;
// Meter, label, checklist
if (current.score) card.style.setProperty("--meter", COLORS[current.score]);
else card.style.removeProperty("--meter");
segs.forEach((seg, i) => {
const part = Math.max(0, Math.min(1, (current.percent - i * 25) / 25));
seg.style.width = `${part * 100}%`;
});
label.textContent = LABELS[current.score];
crack.textContent = hasValue ? `Crack time: ${current.crack}` : "";
ruleItems.forEach((li) => li.classList.toggle("ok", current.rules[li.dataset.rule]));
// Mochi's mood
buddy.classList.remove(...MOODS);
buddy.classList.add(MOODS[current.score]);
if (current.score === 4 && lastScore < 4) pulse("happy", 1300);
lastScore = current.score;
// Paws cover the eyes only while the password is visible, never on the email
buddy.classList.toggle("covered", pw.type === "text" && !onEmail);
if (!buddy.classList.contains("covered")) buddy.classList.remove("peek");
// Email: tilt while typing, wink + thumbs up once valid
emailWrap.classList.toggle("is-valid", valid);
buddy.classList.toggle("tilt", onEmail && email.value.length > 0 && !valid);
buddy.classList.toggle("thumbs-up", onEmail && valid);
if (valid && !wasValid) {
pulse("wink", 450);
pulse("jingle", 600);
}
wasValid = valid;
if (!submit.classList.contains("loading")) submit.disabled = !(valid && current.score >= 3);
updateSpeech();
}
/* ---------- Events ---------- */
[email, pw].forEach((input) => {
input.addEventListener("focus", () => {
focused = input;
trackCaret();
update();
});
input.addEventListener("input", () => {
update();
pulse("nod", 260);
});
["input", "click", "keyup", "select"].forEach((evt) =>
input.addEventListener(evt, () => requestAnimationFrame(trackCaret))
);
input.addEventListener("blur", () => {
focused = null;
eyes.forEach((eye) => { eye.tx = 0; eye.ty = 2; });
update();
});
});
document.addEventListener("selectionchange", () => requestAnimationFrame(trackCaret));
window.addEventListener("resize", trackCaret);
// Follow the mouse when nobody is typing
document.addEventListener("pointermove", (e) => {
if (!focused) lookAt(e.clientX, e.clientY);
});
// Caps Lock warning
function checkCaps(e) {
if (typeof e.getModifierState !== "function") return;
const on = e.getModifierState("CapsLock");
if (on === capsOn) return;
capsOn = on;
pwWrap.classList.toggle("caps-on", on);
if (on) {
pulse("twitch", 460);
pulse("twitch-l", 460);
}
updateSpeech();
}
pw.addEventListener("keydown", checkCaps);
pw.addEventListener("keyup", checkCaps);
pw.addEventListener("blur", () => {
capsOn = false;
pwWrap.classList.remove("caps-on");
});
// Show / hide password
toggle.addEventListener("pointerdown", (e) => e.preventDefault()); // keep focus in the input
toggle.addEventListener("click", () => {
const show = pw.type === "password";
const pos = pw.selectionEnd;
pw.type = show ? "text" : "password";
toggle.setAttribute("aria-pressed", String(show));
toggle.setAttribute("aria-label", show ? "Hide password" : "Show password");
pw.focus();
try { pw.setSelectionRange(pos, pos); } catch (_) {}
update();
});
// Hovering Mochi while covered → a cheeky peek
stage.addEventListener("pointerenter", () => {
if (!buddy.classList.contains("covered")) return;
buddy.classList.add("peek");
updateSpeech();
});
stage.addEventListener("pointerleave", () => {
buddy.classList.remove("peek");
updateSpeech();
});
// Generate a strong password and "type" it in
function randomInt(max) {
const arr = new Uint32Array(1);
crypto.getRandomValues(arr);
return arr[0] % max;
}
function generatePassword(length = 16) {
const sets = ["abcdefghijkmnpqrstuvwxyz", "ABCDEFGHJKLMNPQRSTUVWXYZ", "23456789", "!@#$%^&*?-_+="];
const all = sets.join("");
const chars = sets.map((set) => set[randomInt(set.length)]); // one from each set
while (chars.length < length) chars.push(all[randomInt(all.length)]);
for (let i = chars.length - 1; i > 0; i--) {
const j = randomInt(i + 1);
[chars[i], chars[j]] = [chars[j], chars[i]];
}
return chars.join("");
}
let typing = null;
genBtn.addEventListener("click", () => {
clearInterval(typing);
const next = generatePassword();
let i = 0;
pw.value = "";
pw.focus();
genBtn.disabled = true;
typing = setInterval(() => {
pw.value += next[i++];
pw.setSelectionRange(pw.value.length, pw.value.length);
pulse("nod", 260);
update();
trackCaret();
if (i >= next.length) {
clearInterval(typing);
genBtn.disabled = false;
navigator.clipboard?.writeText(next).then(
() => showToast("Strong password generated & copied"),
() => showToast("Strong password generated")
);
}
}, 45);
});
let toastTimer;
function showToast(message) {
toastText.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2600);
}
// Demo submit (no real request)
form.addEventListener("submit", (e) => {
e.preventDefault();
if (submit.disabled) return;
submit.classList.add("loading");
submit.disabled = true;
setTimeout(() => {
submit.classList.remove("loading");
pulse("celebrate", 1500);
pulse("happy", 1500);
pulse("jingle", 600);
say("You're all set! Welcome aboard.");
showToast("Account created successfully");
submit.disabled = false;
}, 1400);
});
update();
This project demonstrates how HTML, CSS, and JavaScript can work together to turn a plain login form into a friendly, interactive experience. Mochi reacts to every key you press, so users get instant and fun feedback on their email and password strength, and you learn SVG drawing, CSS animation and live form logic in one small project.
If your project has problems, don’t worry. Just click to download the source code and face your coding challenges with excitement. Have fun coding!
