Aduok Code

A Santa Sack Login, Built from a Hand-Drawn SVG Santa with Hinged Limbs, a Web Animations Timeline Written with async and await, and a Frosted Glass Card That Pops Out of a Gift Sack

Introduction

This is a single HTML file that turns a login page into a tiny Christmas story. On a snowy night, Santa walks in from the left carrying a red gift sack. He stops in the middle of the screen, bends down to set the sack on the snow, and steps back. The sack wiggles, its tie flies off, a beam of light shines out, and a frosted glass login card flips up out of the sack. Santa throws his arms up and jumps.

There are no images, no animation libraries and no canvas. Santa and the sack are inline SVG drawn by hand. The repeating motions, like the leg swing and the sack swing, are CSS keyframes switched on and off with classes. The one-off moves, like walking across the screen and the card popping out, use the Web Animations API, and the whole story is one async function that awaits each step before starting the next.

What you will learn

How to draw a character in SVG so its arms and legs rotate around real joints — how to build a walk cycle from a single class — how to keep two separate elements moving in lockstep — how to write a multi-step animation as readable async code that can be safely restarted — how to make one element appear to grow out of another by measuring them — and how to style a polished dark glass login form with focus states, a loading button and inline errors.

01
Part One
The Night Scene

Step 1 — Sky, Moon, Snow and Ground

The scene is one positioned div that fills the screen. The body gets a vertical gradient from deep navy to a softer blue, which reads as a night sky. A moon is a circle with a wide, faint box-shadow for its glow. The ground is a wide white div at the bottom whose top corners use an elliptical border-radius, so the snow line curves gently like a hill instead of being a flat edge.

CSS
:root {
  --sky-top: #142240;
  --sky-bottom: #3b5b8f;
  --snow: #f7fbff;
  --snow-shade: #d9e6f2;
  --ground: 90px;        /* height of the snow everything stands on */
}

body {
  background: linear-gradient(var(--sky-top), var(--sky-bottom));
}

.scene {
  position: relative;
  height: 100vh;
  min-height: 760px;
  overflow: hidden;
  perspective: 900px;    /* used later by the card's 3D flip */
}

.ground {
  position: absolute;
  left: -10%;
  right: -10%;
  bottom: 0;
  height: calc(var(--ground) + 30px);
  background: linear-gradient(var(--snow), var(--snow-shade));
  border-radius: 50% 50% 0 0 / 40px 40px 0 0;
}

The --ground variable is the most important number in the file. Santa, the sack, the light beam and the login card are all positioned with bottom: calc(var(--ground) + something). Change it once and the whole cast moves up or down together, still standing on the snow.

Snowflakes are generated by JavaScript instead of written by hand. Sixty spans get a random size, left position, opacity, sideways drift and duration. A negative animation-delay starts each flake part way through its fall, so the sky is already full of snow on the first frame instead of every flake starting at the top together.

JavaScript
for (let i = 0; i < 60; i++) {
  const f = document.createElement('span');
  const size = 2 + Math.random() * 5;
  f.className = 'flake';
  f.style.cssText = `
    left:${Math.random() * 100}%;
    width:${size}px; height:${size}px;
    opacity:${.4 + Math.random() * .6};
    --drift:${-40 + Math.random() * 80}px;
    animation-duration:${6 + Math.random() * 8}s;
    animation-delay:${-Math.random() * 14}s;`;
  scene.appendChild(f);
}

/* CSS */
/* @keyframes fall { to { transform: translate(var(--drift), 110vh); } } */
02
Part Two
Drawing Santa with Joints

Step 2 — An SVG Character Built for Animation

Santa is one SVG with a 160 by 228 viewBox, facing right. He is made of simple shapes: a circle for the face, a cloud-shaped path for the beard, a rounded path for the red coat, a black belt with a gold buckle, and a hat whose tip flops backwards with a white pom-pom. What matters for animation is not the shapes but how they are grouped.

Each arm and each leg is its own g element, so it can rotate as one piece. The order in the SVG is also the depth order: the back arm and back leg are drawn first so the body covers them, and the front arm is drawn last so it sits on top of the coat and can hold the sack.

HTML
<svg class="santa" viewBox="0 0 160 228">
  <!-- drawn first = furthest back -->
  <g class="arm arm-back">
    <path d="M62 112 Q48 135 52 156" stroke="#a61e1e" stroke-width="18"
          stroke-linecap="round" fill="none" />
    <circle cx="52" cy="158" r="10" fill="#fff" />      <!-- cuff -->
    <circle cx="52" cy="165" r="9"  fill="#2b2b2b" />   <!-- mitten -->
  </g>

  <g class="leg leg-back">  ...pants + boot...  </g>
  <g class="leg leg-front"> ...pants + boot...  </g>

  <!-- body, belt, head, beard, hat -->
  ...

  <!-- drawn last = in front, this hand holds the sack -->
  <g class="arm arm-front">
    <path d="M104 112 Q122 132 126 150" stroke="#d32f2f" stroke-width="18"
          stroke-linecap="round" fill="none" />
    <circle cx="126" cy="153" r="10" fill="#fff" />
    <circle cx="127" cy="161" r="9"  fill="#2b2b2b" />
  </g>
</svg>

Each arm is a single curved path with a thick round-capped stroke. That is much easier to rotate than a filled shape: the sleeve stays the same thickness at every angle, and the round cap hides the joint at the shoulder.

Rotating around the shoulder, not the corner

By default a CSS transform on an SVG group rotates around the top-left of the whole SVG, which would swing an arm across the screen. The fix is transform-box: view-box, which makes transform-origin use the SVG's own coordinates. Then you can put the origin exactly on the shoulder or hip, using the same numbers you drew with.

CSS
.santa .leg,
.santa .arm {
  transform-box: view-box;
  transition: transform .4s ease;
}

.santa .leg-back  { transform-origin: 70px 172px; }   /* hip */
.santa .leg-front { transform-origin: 92px 172px; }   /* hip */
.santa .arm-back  { transform-origin: 62px 112px; }   /* shoulder */
.santa .arm-front { transform-origin: 104px 112px; }  /* shoulder */
Use the path start as the joint

Both arm paths start at their shoulder point (M62 112 and M104 112). Using that exact point as the transform-origin means the arm always stays attached to the body, whatever angle it rotates to. Draw each limb starting from its joint and the origin values write themselves.

03
Part Three
A Walk Cycle from Two Classes

Step 3 — Walking, Bending and Cheering as Poses

Every pose Santa has is a class on his wrapper. The JavaScript never touches an arm or a leg directly. It only adds and removes walking, bend and cheer, and the CSS decides what each one means.

Walking is one keyframe, stride, that swings from -20 to 20 degrees. The front leg plays it with alternate and the back leg plays it with alternate-reverse, so when one leg is forward the other is back. The back arm swings with the front leg, the way arms move opposite to legs. The whole SVG also bobs up 4 pixels at twice the speed, once for each step.

CSS
.walking .santa     { animation: bob .225s ease-in-out infinite alternate; }
.walking .leg-front { animation: stride .45s ease-in-out infinite alternate; }
.walking .leg-back  { animation: stride .45s ease-in-out infinite alternate-reverse; }
.walking .arm-back  { animation: stride .45s ease-in-out infinite alternate; }

@keyframes bob    { to { transform: translateY(-4px); } }
@keyframes stride {
  from { transform: rotate(-20deg); }
  to   { transform: rotate(20deg); }
}

The front arm is left out of the walk on purpose. It is carrying the sack, so it stays still while everything else moves. That one missing line makes him look like he is holding something heavy.

The other two poses are plain transforms. Bend leans the whole SVG forward 9 degrees from his feet. Cheer rotates both arms up over his head, stretches the mouth open with scaleY, and plays a jump keyframe three times. Because the limbs have a transition, removing cheer lets the arms float back down instead of snapping.

CSS
.santa { transform-origin: 50% 100%; }   /* lean from the feet */

.bend .santa     { transform: rotate(9deg); }
.bend .arm-front { transform: rotate(-10deg); }

.cheer .arm-front { transform: rotate(-140deg); }
.cheer .arm-back  { transform: rotate(160deg); }
.cheer .mouth     { transform: scaleY(2.6); }
.cheer .santa     { animation: jump .6s ease-in-out 3; }

@keyframes jump {
  0%, 100% { transform: translateY(0); }
  45%      { transform: translateY(-34px) rotate(-3deg); }
}

The script decides when. The stylesheet decides how. Santa never knows which one is talking.

04
Part Four
The Gift Sack

Step 4 — Swing, Squish and Burst Open

The sack is a second, separate SVG: a rounded red body with a lighter highlight and a gold star, a glowing ellipse at the opening that starts invisible, and a sack-top group with the gathered neck, the gold rope and a bow. It has three moods, again as classes.

CSS
/* 1. carried: hangs from the top and swings */
.sack { transform-origin: 50% 8%; }
.carried .sack { animation: swing .45s ease-in-out infinite alternate; }
@keyframes swing {
  from { transform: translateY(-16px) rotate(-7deg); }
  to   { transform: translateY(-16px) rotate(7deg); }
}

/* 2. wobble: squashes from the bottom like something inside is moving */
.sack-all { transform-box: fill-box; transform-origin: 50% 100%; }
.wobble .sack-all { animation: squish .5s ease-in-out 2; }
@keyframes squish {
  30% { transform: scale(1.12, .88); }
  60% { transform: scale(.94, 1.08); }
}

/* 3. open: the tie flies off and the glow appears */
.open .sack-top  { transform: translate(26px, -60px) rotate(50deg); opacity: 0; }
.open .sack-glow { opacity: 1; }

The swing rotates from 8% down, which is the neck of the sack, right where Santa's mitten is. The squish uses transform-box: fill-box with the origin at the bottom centre, so the sack squashes into the snow rather than shrinking towards the middle. When the class is removed after carrying, the -16px lift goes away with a springy cubic-bezier, so the sack drops and lands with a small bounce.

When it opens, a burst() function adds sixteen star-shaped spans made with a clip-path polygon. Each one flies out at a random upward angle and distance with element.animate(), and removes itself when its animation finishes. A trapezoid beam of light, also cut with clip-path, scales up from the sack opening and fades out.

JavaScript
function burst() {
  for (let i = 0; i < 16; i++) {
    const s = document.createElement('span');
    s.className = 'spark';
    scene.appendChild(s);
    const a = Math.PI + Math.random() * Math.PI;   // anywhere in the upper half
    const d = 80 + Math.random() * 120;
    s.animate([
      { transform: 'translate(-50%, 0) scale(.4) rotate(0)', opacity: 1 },
      { transform: `translate(calc(-50% + ${Math.cos(a) * d}px), ${Math.sin(a) * d}px) scale(1.4) rotate(180deg)`, opacity: 0 }
    ], { duration: 900 + Math.random() * 400, easing: 'cubic-bezier(.2,.8,.3,1)' })
      .finished.then(() => s.remove());
  }
}
05
Part Five
The Story as an async Timeline

Step 5 — Five Steps, One Function, Read Top to Bottom

A sequence like this is often built with a pile of animation-delay values that all have to be kept in sync by hand. Change the walk from 3.2 to 4 seconds and every later delay is wrong. Here, each step waits for the one before it to actually finish. element.animate() returns an Animation whose finished property is a promise, so the story is written with await.

JavaScript
const wait = ms => new Promise(r => setTimeout(r, ms));

async function play() {
  // ...setup shown below

  // 1. Santa walks in carrying the sack
  santaPos.classList.add('walking');
  sackPos.classList.add('carried');
  const walk = { duration: 3200, easing: 'linear', fill: 'forwards' };
  santaPos.animate([{ transform: `translateX(${start}px)` }, { transform: 'translateX(0)' }], walk);
  await sackPos.animate([{ transform: `translateX(${start}px)` }, { transform: 'translateX(0)' }], walk).finished;

  // 2. Bends and sets the sack down
  santaPos.classList.replace('walking', 'bend');
  sackPos.classList.remove('carried');
  await wait(500);

  // 3. Steps back while the sack wiggles
  santaPos.classList.replace('bend', 'walking');
  sackPos.classList.add('wobble');
  await santaPos.animate(
    [{ transform: 'translateX(0)' }, { transform: `translateX(${-step}px)` }],
    { duration: 1100, easing: 'ease-out', fill: 'forwards' }
  ).finished;
  santaPos.classList.remove('walking');

  // 4. Sack bursts open and the login card pops out
  sackPos.classList.add('open');
  burst();
  popCard();

  // 5. Santa cheers
  await wait(350);
  santaPos.classList.add('cheer');
}

Two elements, one walk

Santa and the sack are separate elements, because the sack has to stay behind when he walks away. To make them travel together, both get the exact same keyframes, duration and linear easing, started on the same line. They stay locked together the whole way. The sack is placed so its centre sits under Santa's front mitten, which is 127 pixels from his left edge, and both end at the centre of the screen.

CSS
.santa-pos { left: calc(50% - 127px); bottom: calc(var(--ground) - 4px); z-index: 3; }
.sack-pos  { left: calc(50% - 38px);  bottom: calc(var(--ground) - 4px); z-index: 2; }

The sack also sits one layer behind Santa, so his black mitten is drawn over the neck of the sack and it looks gripped rather than glued on. Notice too that the moving is done on wrapper divs, .santa-pos and .sack-pos, while the swing, bob and jump run on the SVGs inside them. A Web Animation on transform would override a CSS animation on transform on the same element, so the two kinds of motion live on two levels.

Making it safe to replay

There is a Replay button, and someone will click it in the middle of the story. Without care, the old run would keep going and its later steps would add classes on top of the new run. Each run takes a number from a counter, and after every await it checks that it is still the newest run. If not, it quietly stops.

JavaScript
let runId = 0;

async function play() {
  const id = ++runId;
  const alive = () => id === runId;
  reset();   // cancel every running animation and remove every class

  const w     = scene.clientWidth;
  const start = -(w / 2 + 220);   // fully off the left edge
  const step  = Math.max(40, Math.min(230, w / 2 - 127 * s - 20));

  await sackPos.animate(/* ... */).finished;
  if (!alive()) return;
  // ...every later step does the same check
}

function reset() {
  [santaPos, sackPos, beam, card].forEach(el => el.getAnimations().forEach(a => a.cancel()));
  santaPos.className = 'santa-pos';
  sackPos.className  = 'sack-pos';
  card.classList.remove('shown');
}
Why the step back is calculated

Santa has to step back far enough to clear the login card, but not so far he walks off the screen. step is worked out from the screen width: up to 230 pixels on a desktop, as little as 40 on a narrow phone. The start position is also based on width, so he always begins just out of view whatever the screen size.

06
Part Six
The Card Pops Out

Step 6 — Growing One Element Out of Another

The login card is positioned in its final place from the start, centred and floating above the sack, but hidden with visibility: hidden and opacity 0. To make it look like it comes out of the sack, the first keyframe has to put it at the sack's opening, tiny. Instead of guessing that distance, the script measures it.

JavaScript
card.classList.add('shown');
const rise = sackPos.getBoundingClientRect().top + 10 - card.getBoundingClientRect().bottom;

card.animate([
  { transform: `translateX(-50%) translateY(${rise}px) scale(.05) rotateX(70deg)`, opacity: 0 },
  { transform: 'translateX(-50%) translateY(-24px) scale(1.04) rotateX(-8deg)', opacity: 1, offset: .65 },
  { transform: 'translateX(-50%) translateY(0) scale(1) rotateX(0)', opacity: 1 }
], { duration: 1000, easing: 'cubic-bezier(.2,.9,.3,1)', fill: 'forwards' });

rise is the gap between the bottom of the card and the top of the sack, in pixels. Moving the card down by that much, with transform-origin at its bottom centre and scale(.05), puts a tiny card right in the sack's mouth. The animation then grows it to full size in its real place. Because it is measured on every run, it still lines up after the screen is resized or the card is moved higher on phones.

The flip comes from rotateX. The card starts tipped back 70 degrees, lying almost flat like a lid, swings past upright to -8 degrees with a small overshoot in scale, and settles. The perspective: 900px on the scene is what makes rotateX look like real depth instead of a squash.

07
Part Seven
The Frosted Glass Card

Step 7 — A Login Card That Belongs in the Scene

A bright, flat card would fight with the night sky. Instead the card is dark navy glass: a semi-transparent background with backdrop-filter blur, so the sky and snowflakes show softly through it. A one-pixel light border and an inset top highlight give the glass an edge, and a large soft shadow lifts it off the scene. Gold is the only accent colour, which ties the card to the buckle, the star on the sack and the moonlight.

CSS
:root {
  --glass: rgba(14, 24, 48, .72);
  --glass-line: rgba(255, 255, 255, .12);
  --field: rgba(255, 255, 255, .06);
  --field-line: rgba(255, 255, 255, .14);
  --text: #f3f6ff;
  --muted: #a3b0cc;
  --gold: #f0c96a;
  --gold-2: #d89a35;
  --red: #d6403a;
}

.card {
  width: min(380px, calc(100vw - 32px));
  padding: 30px 28px 24px;
  color: var(--text);
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: 24px;
  backdrop-filter: blur(18px) saturate(140%);
  box-shadow:
    0 40px 80px -24px rgba(4, 10, 24, .75),
    inset 0 1px 0 rgba(255, 255, 255, .08);
  overflow: hidden;
}

/* a thin gift ribbon along the top edge */
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--red), var(--gold) 50%, var(--red));
}

The header pairs a gold rounded square holding a gift icon with "Welcome back" and a one-line subtitle. Below it the form follows patterns people already know from real products: the label above each field, Forgot password? on the same line as the Password label, an icon inside each input, an eye button to show the password, Keep me signed in, one main button, then social sign-in and a sign-up link.

CSS
.input input {
  height: 48px;
  padding: 0 44px;              /* room for the icon and the eye button */
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--field-line);
  border-radius: 12px;
  transition: border-color .2s, background .2s, box-shadow .2s;
}

.input input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(240, 201, 106, .16);
}

/* the icon turns gold with its field */
.input:focus-within svg.icon { stroke: var(--gold); }

.submit {
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--gold), var(--gold-2));
  color: #251a05;
  font-weight: 700;
  box-shadow:
    0 10px 24px -10px rgba(240, 180, 80, .7),
    inset 0 1px 0 rgba(255, 255, 255, .45);
}

The checkbox is a real input with appearance: none, so it keeps keyboard and screen reader support. Its tick is an ::after box with only a left and bottom border, rotated -45 degrees, and scaled from 0 to 1 when checked. The password eye is a real button with aria-pressed, and CSS shows either the open eye or the crossed-out eye based on that attribute.

Check backdrop-filter contrast

Glass looks great but the text sits on whatever is behind it. Keep the glass dark enough (here 72% opacity) that white text stays readable even when a bright snowflake or the moon passes behind the card. The blur alone is not enough to guarantee contrast.

08
Part Eight
Validation, Loading and Success

Step 8 — Make Every State Feel Finished

The form uses novalidate so the browser's own popups do not appear, and checks the fields itself on submit. A wrong field gets an invalid class, which turns its border soft red and shows a small error line with an icon under it. The card shakes, and focus jumps to the first field that needs fixing. Typing in a field clears its error straight away.

JavaScript
card.addEventListener('submit', async e => {
  e.preventDefault();
  if (submit.disabled) return;

  const emailOk = /^\S+@\S+\.\S+$/.test(email.value.trim());
  const pwOk    = pw.value.length >= 6;
  setError('email', emailOk ? '' : 'Enter a valid email address.');
  setError('pw',    pwOk    ? '' : 'Password must be at least 6 characters.');

  if (!emailOk || !pwOk) {
    card.classList.remove('shake');
    void card.offsetWidth;          // restart the animation
    card.classList.add('shake');
    (emailOk ? pw : email).focus();
    return;
  }

  // pretend to send a request
  submit.disabled = true;
  submit.classList.add('loading');
  submitText.textContent = 'Signing in…';
  await wait(1200);

  submit.classList.remove('loading');
  submitText.textContent = 'Sign in';
  submit.disabled = false;
  toast.classList.add('show');      // "Signed in. Merry Christmas!"
  burst();
  santaPos.classList.add('cheer');
});

The shake uses the translate property instead of transform. The card's transform is already owned by its pop-out animation, which is held with fill: forwards, so a shake on transform would be overridden. translate is a separate property that adds on top, so both work at once.

While the fake request runs, the button is disabled, shows a spinning ring and changes its text, so a double click cannot send it twice. On success a green status message appears at the top of the card, sparkles burst from the sack again, and Santa cheers. Swap the wait(1200) for a real fetch call to use it for real.

09
Part Nine
Phones and Reduced Motion

Step 9 — A Smaller Santa and a Higher Card

On a phone the card is almost as wide as the screen, so it would hide Santa completely. Under 600 pixels wide, a --s variable shrinks Santa and the sack to 70%, and on tall phones the card is lifted higher so there is room for Santa below it. The scale uses the separate scale property, so it does not clash with the walking transform.

CSS
:root { --s: 1; --card-lift: 96px; }

@media (max-width: 600px) {
  :root { --s: .7; }
}
@media (max-width: 600px) and (min-height: 760px) {
  :root { --card-lift: 170px; }
}

.santa-pos { scale: var(--s); transform-origin: 127px 100%; }  /* shrink around the hand */
.sack-pos  { scale: var(--s); transform-origin: 50% 100%; }
.card      { bottom: calc(var(--ground) + var(--card-lift)); }

Santa shrinks around the point where his mitten is, at the bottom, and the sack shrinks around its bottom centre. Both points stay where they were, so the sack is still in his hand and both are still standing on the snow. The script reads --s back with getComputedStyle so it can work out a step-back distance that fits the smaller Santa.

For people who have asked their device for less motion, play() checks prefers-reduced-motion at the start. If it is set, it skips the whole story: Santa is placed in his final spot, the sack is already open, and the card is simply shown. The page works the same, it just does not move.

Tuning Reference

ValueExampleEffect
--ground90pxHeight of the snow; everything in the scene stands on it
walk duration3200msHow long Santa takes to cross to the middle
stride±20deg over .45sLeg and arm swing; bigger angles look like running
step40–230pxHow far Santa steps back to clear the card
.bend rotate9degHow far he leans to set the sack down
swing±7degHow much the sack sways while carried
burst count16Number of gold sparkles when the sack opens
rotateX start70degHow flat the card lies before it flips up
--glassrgba(14, 24, 48, .72)Card darkness; lower alpha shows more sky
--s1 / .7Size of Santa and the sack; .7 on phones
--card-lift96px / 170pxGap between the snow and the bottom of the card

Full Source Code

The whole project is a single self-contained HTML file with its markup, styles and script together and no build step. The only external request is the Google Fonts stylesheet for Plus Jakarta Sans, and the page falls back to the system font if it does not load. It needs a browser that supports the Web Animations API, backdrop-filter and the individual scale and translate properties, which means any current Chrome, Edge, Safari or Firefox.

HTML — santa-sack-login.html (complete)
// Full source available in the Aduok GitHub repository
// https://github.com/aduok/aduok-code-snippets/blob/main/blog/santa-sack-login.html
Want to try it yourself?Open the live santa-sack-login.html file