Rethinking the building block
Most 3D CSS constructions come down to one primitive: the cuboid. More elaborate shapes are possible but demand extra handling, and curves in particular are difficult. A cuboid itself is a wrapping element with six transformed children, one per face, and it relies on transform-style: preserve-3d being applied along the way. Applying that property everywhere is good practice rather than an afterthought — nested cuboids are common in complex scenes, and tracking down a missing transform-style across browsers is a painful way to spend an afternoon.
The technique is easiest to plan if you imagine an entire composition as cuboids assembled like LEGO pieces. A 3D book, for instance, reduces to four: one per cover, one for the spine, one for the pages. Everything else is handled with background-image.
Establishing a plane
Building the whole creation inside a scene plane makes rotation and movement far simpler. The approach: rotate the scene on the X and Y axes first, then flatten it with rotateX(90deg), and add new cuboids inside that plane element. All cuboids get position: absolute. Because constructing them consumes a lot of repeated markup, a Pug mixin handles cuboid generation; the CSS side is driven by custom properties that act as dimensions and coordinates:
--width— cuboid width on the plane--height— cuboid height on the plane--depth— cuboid depth on the plane--x— X position on the plane--y— Y position on the plane
Sizing mostly uses vmin to stay responsive, though scoped creations may warrant their own responsive unit. Once the plane is laid flat, a cuboid can be reasoned about in terms of height, width and depth.
Inspecting a scene at runtime
Changing custom properties through dat.GUI — a lightweight JavaScript controller library — makes 3D CSS far easier to debug. Only a small amount of code is needed to expose CSS variables in a panel and tweak them while the page runs. A particularly useful habit is wiring the plane's X and Y rotation into the panel, so geometry can be checked from angles that aren't visible at first. This panel exists only for debugging; the workflow is largely about rotating the plane constantly while a scene is built up. The controller code grows repetitive quickly, so functions that accept a configuration and generate the controllers are worth exploring.
Centring and dividing the scene
By default each cuboid sits half under and half above its plane, and that is deliberately so: the containing element becomes the cuboid's centre, which simplifies animation, especially rotation around the Z-axis. Rotating a flip around an offset centre is why that choice matters.
In busier compositions, sub-planes are the answer to keeping track of everything. In a recreation of a personal workspace, the chair has its own sub-plane, so it can be moved and rotated without disturbing the rest of the scene — even spinning its top while the feet stay put.
Getting the visuals right
Aesthetics depend on the piece, but a few techniques pay off consistently. Building the shapes ugly first and then converting the colours into CSS variables is a workable order. Using three shades for any given material lets the faces of a cuboid read as distinct surfaces, as in a toaster where three shades cover its sides. Class names defined in the Pug mixin let colour be assigned per side.
Extra elements are awkward to fit through the mixin, but every cuboid face provides two pseudo-elements for detail work — the toaster slot and its handle slot are examples. background-image is the other workhorse: layering backgrounds creates shading, while actual images supply texture, such as the repeating floor and rug in the workspace scene. Handling textures in a pseudo-element is preferable because they can then be transformed, for instance tiling an image at an angle; working directly with a cuboid side has produced flickering in some cases.
Textures complicate shading, since faces still need to be distinguishable. The filter property helps there: a brightness() filter applied per face lightens or darkens it. In a CSS flipping table, all surfaces share a texture image and rely on brightness filters to separate the sides.
Faking what CSS can't do
Some apparent 3D — the kind the Zdog library is built on — is an eye trick. A bundle of balloons illustrates the technique: the strings use correct perspective and carry their own rotations and tilts, while the balloons themselves are flat and maintain a counter-rotation against the plane, preserving the illusion. Switching off that countering in the demo breaks it.
The same trick solves organic shapes. A house plant was suggested for the workspace scene, and rather than modelling leaves in three dimensions, a stock plant image can be cut out with a tool like remove.bg and many copies positioned at the same spot, each rotated by a set amount. The stacked copies read as a three-dimensional plant.
Difficult geometry
Awkward shapes rarely have a generic solution, but a couple of examples indicate the range of approaches. A LEGO interface panel starts as a cuboid: clip the top face, make the end face transparent, and rotate a pseudo-element to bridge the join, then use that pseudo-element's background layers for detail. Exact angles and heights can be derived with trigonometry. (The studs are out of scope.)
Curves are outside CSS's comfort zone, leaving a trade-off between two options. Polygon approximations accept faceting, or pile up enough elements for a near-curve that may cost performance. The rotation trick borrowed from the plant sacrifices the ability to style any "sides", since there are none. Either way, it is a case-by-case judgement.
Z-fighting
Elements sharing a plane can overlap or flicker, and there is no blanket fix — it is handled per case. Ordering items in the DOM is the first strategy, but not always enough, because placing things too precisely causes the trouble. A wall canvas with a pseudo-element shadow pressed exactly against the wall makes the shadow and wall compete for the front position. Translating one by a slight amount resolves it. Enabling and disabling an offset in that demo while resizing shows the flicker vanish: the offset sets --x to a fraction of 1vmin, named --cm — a responsive unit scoped to that creation.



