CSS propertyTransforms
backface-visibility
Decides whether the back of an element rotated in 3D is visible.
- Initial value
visible- Inherited
- No
- Animatable
- no
- Applies to
- transformable elements
- JavaScript
element.style.backfaceVisibility = "hidden"
Example
#CSS
.card { transform-style: preserve-3d; transition: transform 0.6s; }
.card.flipped { transform: rotateY(180deg); }
.face { backface-visibility: hidden; position: absolute; inset: 0; }
.back { transform: rotateY(180deg); }Example HTML
<style>
.flip { perspective: 700px; width: 180px; height: 110px; margin: 8px auto; }
.flip .card { position: relative; height: 100%; transform-style: preserve-3d; transition: transform .6s; }
.flip .face { position: absolute; inset: 0; backface-visibility: hidden; display: grid; place-items: center; border-radius: 12px; font-weight: 700; }
.flip .front { background: #7c3aed; }
.flip .back { background: #0ea5e9; transform: rotateY(180deg); }
</style>
<div class="flip"><div class="card"><div class="face front">Question</div><div class="face back">Answer</div></div></div>
<script>
const card = document.querySelector('.flip .card')
setInterval(() => {
card.style.transform = card.style.transform ? '' : 'rotateY(180deg)'
}, 1600)
</script>Preview
Definition and usage
#When you rotate an element by more than 90 degrees around the X or Y axis, you see its back, which is a mirror image of the front. The backface-visibility: hidden property hides that back.
This is the basis of the card flip effect: two layers, front and back, stacked on top of each other. The back is pre-rotated by 180 degrees, and both sides have their reverse hidden. After rotating the whole card, you see one side or the other.
The property only works in a 3D context, usually with transform-style: preserve-3d on the parent.
Syntax
#Syntax
backface-visibility: visible | hidden;Values
#Values in practice
#visible
After rotation you see the mirrored text.
.demo { backface-visibility: visible; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- For flip cards you need three things:
perspectiveon the container,preserve-3don the card, andbackface-visibility: hiddenon the faces. - Older Safari versions required the
-webkit-backface-visibilityprefix.
Related entries
#- transform-styleDecides whether an element’s children live in a shared 3D space or are flattened.
- perspectiveAdds depth to the 3D transforms of an element’s children.
- rotateRotates an element by a given angle, independently of the transform property.
- transformMoves, rotates, scales, or skews an element without affecting the page layout.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.