Create a 404 page with CSS3 animations

Share this article

When I was asked to build a new 404 page for netmagazine.com, my first thought was to create a CSS animation of some sort. I wanted the design to blend seamlessly with the visual style already established for the site, so I started by designing a page with 404 set in Clarendon, which can be found in the navigation and headlines. My next step was to knock out the text with a newsstand style layout of some recent .net magazine covers. To wrap things up, I added the standard-issue 404 page copy and wound up with this:

Not too shabby. As a bit of progressive enhancement, I decided to pan the magazine covers from right to left with CSS animation during the markup process. Remember, CSS animations are currently supported by WebKit browsers only. Here’s the short HTML snippet for the animated element:

The “box” class gets some specified dimensions and a semi-transparent .png image background for the 404 text. Ideally, we’d do this with selectable text, but fallbacks for non-compliant browsers are unsightly. To learn more about that, check out this example: trentwalton.com/bgclip/.

Now, to add the magazine covers by targeting that “cover_pan” classed div, we use the same basic idea. You’ve got some properties that help layout dimensions and nestle the magazine cover.jpg behind the 404.png.

Notice the second half of the properties declared here. We’ve given the animation a name (pan), set its timing at 40 seconds, and set it to play on a continuous loop with an infinite iteration count. Finally, we set a steady, even pace by indicating a linear timing function. If we used something like easeout or ease-in for timing, it’d hit users with a jolt each time it loops.