rotateY()
Example
.front,
.back {
position: absolute;
inset: 0;
}
.back {
transform: rotateY(180deg);
}.front,
.back {
position: absolute;
inset: 0;
backface-visibility: hidden;
}
.back {
transform: rotateY(180deg);
}backface-visibility: hidden hides each face when it turns away, so only one side shows at a time.
Common mistakes
- The back of the card shows mirrored front text.
- The flip works only with a mouse, never on touch or keyboard.
Key points
- The back face is pre-rotated with
rotateY(180deg)and both faces havebackface-visibility: hidden. - A
perspectiveis set on the container of the flipping element. - The flip also works on keyboard focus, not only on
:hover.
Interview questions
Does rotateY() work without perspective?
It works, but looks flat: the element only gets narrower while turning, with no 3D depth.
Why do my flip card faces flicker?
Usually transform-style: preserve-3d is missing on the rotating parent, so the faces are flattened into one plane.