Free visual CSS tool

CSS 3D Cube Generator

Build a real rotating cube from six positioned faces. Color and label each side, drag to spin it yourself, then copy the exact HTML and CSS needed to reproduce it.

Ready-to-use HTML + CSS

A real cube, not a flat illusion

Every face of this cube is an actual positioned element in 3D space, built with the same transform techniques you can copy straight into your project.

Six independent faces

Color and label the front, back, left, right, top and bottom faces individually.

Drag to spin it

Click and drag the cube to rotate it manually; auto-rotate pauses while you drag.

Export ready code

Copy the full HTML and CSS, including transforms and an optional spin animation.

How to use the 3D cube generator

Style it, spin it, then take the code with you.

  1. Size and speedAdjust the cube size and, if auto-rotate is on, how fast it spins.
  2. Style every facePick a color and label for each of the six faces in the panel.
  3. Drag and copyDrag the cube to check angles, then copy the HTML and CSS.

About building 3D cubes with CSS

A CSS cube works by treating six flat rectangles as the faces of a box floating in 3D space. Each face starts perfectly overlapping in the center of its parent. To turn that stack into a cube, every face is first rotated with rotateX or rotateY so it points in the direction it should face, and then pushed outward along the new z-axis with translateZ by exactly half the cube's width, since a face needs to sit on the surface of the box, not its center. The parent container needs transform-style: preserve-3d so children keep their own 3D positions instead of being flattened, and an ancestor needs a perspective value so the browser has a vanishing point to render the depth against. Rotating the whole cube afterward, whether by dragging or by an animation, simply rotates that entire coordinate system at once.

Why translateZ by half the size

Each face is a flat square at the center of the cube by default. Moving it half the cube's size along the z-axis places it exactly on the surface, matching the other faces.

Rotation order matters

Rotating before translating points a face in the right direction first; translating before rotating would move it along the wrong axis entirely.

preserve-3d on every level

Both the cube and any wrapping rotation layer need transform-style: preserve-3d, or the browser will flatten the children back into 2D.

Backface visibility

By default the inside faces of the cube remain visible when rotated away, which is usually fine for a solid-looking cube like this one.

CSS 3D cube generator FAQ

How is a 3D cube built with pure CSS?

Six divs are each rotated to face outward and then pushed away from the center with translateZ by half the cube's size, inside a parent with perspective and transform-style: preserve-3d.

Can I drag to rotate the cube myself?

Yes. Click and drag anywhere on the cube to spin it manually. Auto-rotate automatically pauses while you drag and resumes from that angle afterward.

Why does each face need a different transform?

Every face starts stacked flat in the center. Rotating a face with rotateX or rotateY before pushing it out with translateZ is what points it in the correct direction, such as up, down, left or right.

Does the exported code include the drag interaction?

The copied code reproduces the visual cube and an optional auto-rotate keyframe animation. The click-and-drag behavior in this playground is a JavaScript convenience for previewing angles.

Is this tool free and private?

Yes. It is completely free, requires no account, and the cube is rendered locally in your browser with no data sent anywhere.

Try other CSS 3D tools

Keep building depth and motion with these free online CSS tools.