Why does transform change an element visually without moving surrounding content?
Quick answer
For elements laid out with the CSS box model, transform changes how an element is rendered, not the space it occupied in normal flow before the transform. Neighbors therefore keep their layout positions, even if the transformed element now appears to overlap them. A non-none transform also creates a stacking context, so stacking behavior can change. [S1]
The question, the details, the next step.
A practical checklist
Decide whether neighboring content should move with the element.
Distinguish the element’s original layout space from its transformed rendered position.
Check whether the transform causes overlap or changes stacking behavior.
Check whether transformed bounds affect overflow or scrolling.
Use a layout adjustment when you need surrounding content to occupy different positions.
A few more useful answers
Does `transform: translateY(...)` create space where the element is drawn?
Not in normal flow for CSS box-model layout: surrounding content retains the element’s pre-transform space. The rendered bounds may extend the overflow area, however, which can affect scrolling. [S1]
Does a transform create a stacking context even when the element does not move?
A non-none transform creates a stacking context; the relevant distinction is whether the transform value is none, not whether the visual change is noticeable. [S1]
Should I use a transform to add a gap between elements?
Usually choose a layout change if the following content should move to make room. A transform is a visual offset, so it can leave the original space in place and cause overlap.
Sources
References used for this guide.
- [S1] W3C: CSS Transforms Module Level 1, flow and stacking behavior w3.org · Checked
