Skip to content
Tutorials

Build a CSS cube from plain divs

The smallest isometric cube you can make, one face at a time.

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.

What you need

A code editor, a modern browser and about twenty minutes. No libraries or build step.

Why the order of rotations matters

Performance is rarely a problem for one hero cube, but a scene with fifty transformed blocks is a different story. Each block may become its own compositing layer, and every layer costs memory. Open the Layers panel before you ship and count them. If the number surprises you, flatten the static parts into a single SVG.

  1. Draw the floor

    Create a wrapper with transform: rotateX(60deg) rotateZ(-45deg). This tilts the whole scene into isometric space.

  2. Place a cube

    Add a square child and give it three faces with pseudo-elements. Each face gets one of the three shading colours.

  3. Lift it on hover

    Translate the cube along its Z axis on hover and deepen the floor shadow at the same time.

The code

Readers often ask whether isometric art is still a trend or already a cliché. Our answer is that the style is a tool, like a chart type. It is excellent for explaining structure and relationships, and it is a poor choice for emotion or narrative. Used for the right job, it never really goes out of date.

cube.cssCSS
.scene {	--unit: 2rem;	transform: rotateX(60deg) rotateZ(-45deg);	transform-style: preserve-3d;} .cube {	width: calc(var(--unit) * 3);	aspect-ratio: 1;	background: var(--face-top);}

<div class="scene" aria-hidden="true">	<div class="cube"></div></div>

Colours used

Lessons from the workshop

Browser support for 3D transforms is excellent today, with a few sharp edges. The main one is that certain properties, such as overflow hidden or some filters, quietly flatten a preserve-3d context. If a face disappears or a block turns flat, look for one of those on an ancestor before you start rewriting your transforms.

What you built

  • A cube with three shaded faces
  • A floor grid from gradients
  • A hover state that lifts the block
Share

Written by

Mara Lindqvist

Mara draws isometric city blocks in CSS and edits the Isometric Basics column. She once rebuilt a subway map using nothing but borders.

All 13 posts by Mara Lindqvist

12 comments

  1. Bea Kowalski

    Tiny typo in the second code block: the unit is missing on the translate value.

    Reply to Bea Kowalski
  2. Gus Lindgren

    Works nicely in Firefox. Safari needed the prefixed transform-style for us.

    Reply to Gus Lindgren
  3. June Park

    I tried this on an old iPad and one of the faces flickers on hover. Any idea why?

    Reply to June Park
    1. Mara LindqvistAuthor

      Thanks! A follow-up is already in the drafts.

      Reply to Mara Lindqvist
    2. Quinn Adler

      Agreed, this is the part most tutorials skip.

      Reply to Quinn Adler
  4. Farah Aziz

    Has anyone tried this with container queries? Feels like a good fit.

    Reply to Farah Aziz
    1. Mara LindqvistAuthor

      Same here. Adding will-change on the wrapper fixed it for me.

      Reply to Mara Lindqvist
      1. Tess Walsh

        Yes, container queries work well; we will cover them soon.

        Reply to Tess Walsh
  5. Kofi Mensah

    Love the palette. Could you share the exact lightness values?

    Reply to Kofi Mensah
  6. Nina Ahlberg

    Thanks for covering reduced motion. It is so often an afterthought.

    Reply to Nina Ahlberg
  7. Pia Jensen

    Our designer drew the scene in Figma and I rebuilt it with your approach in an afternoon.

    Reply to Pia Jensen
  8. Chen Wei

    Great write-up. Would love a follow-up on doing the same thing with SVG.

    Reply to Chen Wei

Leave a comment

Your email address won’t be published. Required fields are marked.