CSS 3D Cube Generator
Design custom 3D cubes with pure CSS. Adjust perspective, colors, and dimensions, then copy the clean, GPU-accelerated code. No JavaScript required for the result.
About
Creating 3D objects in a 2D browser environment relies on the transform-style: preserve-3d property and rigorous understanding of the Cartesian coordinate system. This tool automates the calculation of translation matrices.
To form a perfect cube, each of the 6 faces is rotated along the x or y axis and then translated outward by exactly half the cube's width (wรท2). This translation, often called the apothem in geometry, prevents the faces from intersecting at the center.
The visual perspective is controlled by the perspective property. A lower value (e.g., 400px) creates a dramatic, fisheye distortion, while a higher value (e.g., 2000px) approximates an orthographic projection.
Formulas
The transform logic for any given face i:
Ti = rotate(ฮธ) โ translateZ(size2)
Where the perspective projection P is applied to the parent container:
P = 10000100001-1/d0001
Reference Data
| Face | Rotation Axis | Rotation Angle | Translation (Z) |
|---|---|---|---|
| Front | None | 0ยฐ | +size/2 |
| Back | Y-Axis | 180ยฐ | +size/2 |
| Right | Y-Axis | 90ยฐ | +size/2 |
| Left | Y-Axis | -90ยฐ | +size/2 |
| Top | X-Axis | 90ยฐ | +size/2 |
| Bottom | X-Axis | -90ยฐ | +size/2 |