Shadows on the floor sell the idea that a block has weight. A blurred ellipse, skewed to match the grid and placed slightly offset from the light, is usually enough. Real shadows would change with the height of the block, and adding that detail makes towers and stairs look much more convincing.
A code editor, a modern browser and about twenty minutes. No libraries or build step.
Putting it together
Design tokens keep the whole team in step. We name colours by their role, such as face-top, face-left and face-right, rather than by hue. When we switched the site to a violet accent for a campaign, only the token values changed. Every illustration, button and chart followed without anyone opening a single component.
Draw the floor
Create a wrapper with
transform: rotateX(60deg) rotateZ(-45deg). This tilts the whole scene into isometric space.Place a cube
Add a square child and give it three faces with pseudo-elements. Each face gets one of the three shading colours.
Lift it on hover
Translate the cube along its Z axis on hover and deepen the floor shadow at the same time.
The code
We prototype every scene on paper first. A sheet of triangle-grid paper, a soft pencil and ten minutes are enough to find out whether a composition works. It is far cheaper to erase a pencil line than to rewrite a dozen nested transforms, and the sketch doubles as documentation when someone asks why a block sits where it does.
const sorted = tiles.toSorted((a, b) => (a.x + a.y) - (b.x + b.y));for (const tile of sorted) { scene.append(tile.element);}
<div class="scene" aria-hidden="true"> <div class="cube"></div></div>
.cube { position: relative; width: 6rem; aspect-ratio: 1; background: var(--face-top);}
Colours used
Start with the floor
SVG is often the better choice for complex scenes. CSS cubes are fun to build and easy to animate, but a city block made of hundreds of divs is hard to change and heavy to render. We draw the static parts in SVG, keep the interactive blocks in CSS, and layer the two together.
What you built
- A cube with three shaded faces
- A floor grid from gradients
- A hover state that lifts the block
Nina Ahlberg
I teach an intro CSS class and I am going to use this as the final project.
Chen Wei
Works nicely in Firefox. Safari needed the prefixed transform-style for us.
Omar Haddad
The templates are in the downloads section of the reference post.
June Park
Yes, container queries work well; we will cover them soon.
Bea Kowalski
Any plans for a video version of this one?
Alex Moreau
The tip about naming faces instead of colours saved our design system a lot of pain.
Soren Dahl
This finally made the order of rotations click for me. I had them the wrong way round for weeks.
Farah Aziz
Has anyone tried this with container queries? Feels like a good fit.
Eli Novak
The paper cube exercise sounds fun. Are the templates available somewhere?
Mara LindqvistAuthor
Glad it helped. The values are in the colour ratios reference.
Quinn Adler
Fixed now, thanks for spotting it.
Mateo Rossi
Is there a way to do the shadow without a pseudo-element? Our CMS strips empty spans.