Also in the lab
CSS art: the raccoon, taken apart
This raccoon is CSS art: no image, just plain boxes cut into shapes and outlined with shadows. Here's how every piece is made, and three tricks you can take to draw your own animal.
It's the mascot, so naturally we took it apart first.
Pull it apart
Slide to separate the pieces. Each group of boxes is labeled with the trick that draws it. Slide back and it snaps together again.
- Ears: two boxes cut with
clip-path. The left one has a torn notch. - Head: one box with a 26-point outline for the cheek ruffs.
- Mask: a single dark band, cut to sweep around both eyes.
- Muzzle and nose: ovals made with
border-radius. - Hoodie and tail: a rounded box, and one repeating gradient for the rings.
How it is drawn
Every part of the raccoon is a plain box. The ears, the head, and the mask are cut out with clip-path. The outline is four hard shadows on a group, so a whole cluster of shapes gets one clean ink line. One variable sets the size, and the whole animal scales with it, so it stays sharp on a phone and on a big monitor.
The eyes blink and the tail swings only if your device has not asked for less motion. With less motion, you get the finished drawing, standing still.
The pulling-apart trick is one more variable: every group has its own direction, and one shared amount from 0 to 1 moves them all at once.
/* Each piece group moves by its own offset, times one shared amount from 0 to 1. */
.piece {
transform: translate(calc(var(--dx) * var(--apart) * 1em),
calc(var(--dy) * var(--apart) * 1em));
}
/* <div class="piece" style="--dx: -22; --dy: -6"> ... the mask ... </div> *//* 1. Outline a whole group of shapes with four hard shadows. */
.outline {
filter: drop-shadow(1.1em 0 0 #140a22) drop-shadow(-1.1em 0 0 #140a22)
drop-shadow(0 1.1em 0 #140a22) drop-shadow(0 -1.1em 0 #140a22);
}
/* 2. Cut a shape out of a plain box with clip-path.
This ear has a torn notch: three extra points on its left edge. */
.ear {
width: 19%; height: 25%; background: #d2cae2;
clip-path: polygon(22% 0, 100% 56%, 62% 100%, 0 100%, 4% 60%, 24% 50%, 8% 42%);
}
/* 3. One size variable scales every part, because 1em is 1% of the width. */
.raccoon { --size: min(80vw, 420px); width: var(--size); font-size: calc(var(--size) / 100); }The fine print, in plain words
Why this is free
We're raccoons who think simple things shouldn't cost a monthly fee. We take techniques apart, explain them in plain words, and give them away. The code on this page is MIT licensed: copy it, change it, and share it.
This is one of twelve experiments so far. Our first browser tool (Bandit Codes) is live now, and the rest sit as ideas in the stash.
Next snack
CSS star rating with no JavaScript
More clip-path, put to work: five radio buttons cut into stars.