A sixty-day run of hand-coded CSS animations leaves a lot of scuff marks—and a few transferable rules. This series was built around strict constraints: every animation hand-coded in CSS, every movement triggered by the user rather than autoplaying, and JavaScript kept out of the animation layer entirely (it appeared once, to start audio on the final piece). The project's main finding is less about any single property and more about consistency: pick one unit strategy and hold to it, all the way through.

Scope and stamina

The series was originally planned to run eighty days. With fewer than twenty animations ready as day one approached and roughly three days going into each piece, the plan dropped to sixty. That still turned out to be a lot of animation to produce against limited time, ideas, and drawing ability.

Cutting to thirty days was tempting, but the longer run forced a deeper look at how CSS animation—and CSS in general—actually behaves. The later pieces, made once the obvious approaches were exhausted, are also the strongest. The run stretched to sixty-two days because it started June 1 and had to include a final animation on August 1; starting two days later felt wrong.

Responsiveness breaks timing

Making an animation land on a target is hard; keeping it aligned across screen sizes is harder. Duration is fixed in the animation property and does not respond to screen size, and the timing function fixes velocity the same way. Only distance can flex. So if distance changes with the viewport, the timing will match at exactly one width and height and drift everywhere else. In a tank-fires-on-zombies piece, the timing was close at both wide and narrow sizes, but the tank still sat in a different position relative to the falling zombies at each.

Showing the same brown take, side by side, where the tank on the left is further along than the tank on the right.

The alternative is to commit to fixed units and use a large number—2000, 5000 pixels or more—so the animation crosses the screen at nearly every size short of the largest monitors.

Going fully responsive with viewport units

If the animation has to be responsive, put everything in viewport units. Mixing pixel dimensions with viewport-based position and movement produces unpredictable results. And don't combine vw and vh: use whichever matches the dominant orientation, because mixing them makes the animation "wonky"—the technical term.

A good negative example is a piece where a super zombie flies upward as the "camera" follows, smashes a ledge, and falls while the camera keeps moving. It mixes pixel, vw, and vh units, and on a tall enough screen the intended story stops reading.

Two animation frames, side by side where the left shows the flying green zombie hitting a building ceiling and the right shows the zombie leaving the frame after impact.

The same constraint applies to entrances from off-screen: if a ninja zombie has to drop in from the top at most aspect ratios, the vw height for the element must be set high enough to keep it out of view beforehand.

Inside SVG, switch back to pixels

SVG elements are a self-contained proportional universe. The SVG "pixel" stays proportional within the SVG to every other child element; viewport units do not. Transforms within an SVG element should therefore use pixel units, while everything else uses viewport units.

Scaling SVGs cleanly

Scaling an SVG at runtime degrades it: scaling a zombie illustration up to five times its size leaves fuzzy edges. Work around it from the other direction. Set the image's dimensions to the size it will have at the end of the animation, then use a scale transform to shrink it to its starting size.

/* Original code resulting in fuzzy edges */
.zombie {
  transform: scale(1);
  width: 15vw;
}

.toggle-checkbox:checked ~ .zombie {
  animation: 5s ease-in-out 0s reverseshrinkydink forwards;
}

@keyframes reverseshrinkydink {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(5);
  }
}
/* Revised code */
.zombie {
  transform: scale(0.2);
  width: 75vw;
}

.toggle-checkbox:checked ~ .zombie {
  animation: 5s ease-in-out 0s reverseshrinkydink forwards;
}

@keyframes reverseshrinkydink {
  0% {
    transform: scale(0.2);
  }
  100% {
    transform: scale(1);
  }
}

Instead of growing a scale from 1 to 5, animate from 0.2 to 1. Rendering always happens at 1, so edges stay crisp.

The same animation frame of a scientist holding a coffee mug standing to the left of a growing zombie where the frame on the left shows the zombie with blurry edges and the frame on the right is clear.

Transforms follow their own axes

An element's axes rotate with the element, not the page. Rotate 90 degrees before a translateX and that translate now runs vertically. In an animation where zombies flip via a 180-degree rotation, positive Y values move them up and negative ones move them down—the reverse of the usual behavior. Any rotation can change how later transforms in the chain behave.

Showing the main character facing us in the foreground with 7 ninja characters hanging upside down from the ceiling against a light pink background.

Split complex motion across nested elements

Multi-directional animation gets easier when you distribute the work. Wrap the element in parent elements and animate each one separately rather than stacking transforms on a single node. In a piece with three simultaneous motions—a zomb-o-naut bobbing up and down, crossing the screen, and rotating—two wrapper elements held the first two, each with its own animation. Performing the rotation on the innermost element keeps the parent's and grandparent's axes intact, sidestepping the axis problem above.

SVG transforms and CSS transforms share a slot

Many paths and groups arrive with transforms already in the SVG markup, put there by an optimization pass or by the illustration tool. Strip one and the element resets—often jumping to a strange location or size relative to the rest of the drawing. Because SVG transforms and CSS transforms are the same, a CSS transform on that element replaces the SVG transform rather than compounding with it, so the CSS animation starts from that odd position or scale.

The fix is to copy the SVG transform into the CSS, rewritten in CSS syntax, as the starting position, then modify it inside the keyframes. In an Office Space homage, the element for Undead Lumbergh's right upper arm (#arm2) carried a transform in the original SVG:

<path id="arm2" fill="#91c1a3" fill-rule="nonzero" d="M0 171h9v9H0z" transform="translate(0 -343) scale(4 3.55)"/>
A side by side comparison of a zombie dressed in a blue button-up shirt and black suspenders while holding a coffee cup. On the left, the arm holding the coffee mugs the the correct position but the right shows the arm detached from the body.

Moving it into CSS:

<path id="arm2" fill="#91c1a3" fill-rule="nonzero" d="M0 171h9v9H0z"/>
#arm2 {
  transform: translate(0, -343px) scale(4, 3.55);
}

allowed animating it without resetting its location and scale:

.toggle-checkbox:checked ~ .z #arm2 { 
  animation: 6s ease-in-out 0.15s arm2move forwards;
}

@keyframes arm2move {
  0%, 100% {
    transform: translate(0, -343px) scale(4, 3.55);
  }
  40%, 60% {
    transform: translate(0, -403px) scale(4, 3.55);
  }
  50% {
    transform: translate(0, -408px) scale(4, 3.55);
  }
} 

This becomes much harder when the generating tool "simplifies" the transform into a matrix. Copying the matrix into CSS is workable, but reshaping it into the scale, rotate, or translate you actually want is difficult. The matrix can be rebuilt from translation, rotation, and scaling, but on a complex path the odds of doing so quickly are low. The easiest route is to wrap the element in a <g> tag, give it a class or ID for CSS access, and transform the group—separating the transforms as with the nested elements above.

transform-origin for natural rotation

By default transforms pivot at the upper-left corner of the SVG element, which looks wrong for joints, mouths, and scaling. Set transform-origin to the actual pivot. An arm swing reads more naturally rotating from the center of the shoulder; the same property helped with scaling and with rotating a dinosaur's jaw.

Four sequential frames of an animation showing a caveman character facing left, holding a large wooden club, and raising it up from the bottom to behind his head.

Responsive sprite animation

Sprite animation—swapping through incremental frames fast enough to simulate motion—was a recurring technique. The setup: one wide image file as a background-image on an element the size of a single frame, with overflow hidden. Use background-size to set the background image to the width of the sheet, then walk the frames with background-position and the step() timing function.

Sprites can be fully responsive. Put an SVG in the background and size the element and its background position with viewport units; because everything shares one unit, the frames stay in sync as the screen changes. This ran against the earlier assumption that sprites had to be roughly fixed-size with a little responsive give.

The trouble with percentage background-size

The obvious formula—100% * (number of steps + 1) for background-size—works in most cases but fails on long sheets: frame tracking drifts and slivers of the wrong frame show. The shift grows with the frame count, likely from rounding errors compounding across the sheet's length. In the project's longest sprite animation, a dinosaur opens its mouth to reveal a zombie Viking singing—an animation that tracked fine in Chrome but broke in Safari at certain sizes, with part of a nose from a neighboring frame appearing on the right and its counterpart missing on the left.

A large green dinosaur behind a crowd of people, all facing and looking forward.
The dinosaur on the left is missing part of his left cheek and growing a new one next to his right cheek.

Diagnosing this was painful because it only misbehaved on Safari at particular viewport sizes. Switching to a single unit—vw for background-size, frame width, and background-position—resolved it. Consistent units, again.

Build in front of an audience

A crowd of 32 pixel-art characters from the previous demos facing the screen.

Much of the project was head-against-wall work. Bringing others in—for advice, for spotting blind spots, for feedback, for help with the work, or just for encouragement—is the better path through a deliberately oversized scope.