The CSS backface-visibility property controls whether the **back side** of an element is visible when it is rotated in 3D space using transforms such as rotateY() or rotateX(). It is especially useful for **3D flip cards, rotating elements, and animation effects**.
Note
β Useful for hiding mirrored text during flips
β Default value: visible
π¦ Syntax
backface-visibility syntax
backface-visibility: visible | hidden;
/* Examples */
backface-visibility: hidden;
backface-visibility: visible;| Value | Meaning |
|---|---|
| visible | Backside is shown when the element rotates |
| hidden | Backside is invisible when rotated |
π¨ 1. Basic Example
Basic
.box {
width: 200px;
height: 200px;
background: orange;
transform: rotateY(180deg);
backface-visibility: hidden;
}When the element rotates 180Β°, you won't see the backside.
π¨ 2. 3D Flip Card Example
backface-visibility is essential for creating flip-card effects without showing reversed mirrored content.
Flip card
.scene {
width: 200px;
height: 300px;
perspective: 800px;
}
.card {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
transition: rotate 0.6s;
}
.card:hover {
rotate: 180deg;
}
.card .front,
.card .back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
/* Back side */
.card .back {
rotate: 180deg;
}The backside stays hidden when flipped, showing clean UI transitions.
π¨ 3. Showing Backface (Default Behavior)
visible backface
.text {
transform: rotateY(180deg);
backface-visibility: visible;
}The text becomes mirrored and visible when rotated.
π¨ 4. Flip on X-axis
Rotate X
.flip {
transform: rotateX(180deg);
backface-visibility: hidden;
}Works with rotateX, rotateY, but not 2D transforms.
π¨ 5. Animation Example
Animation
.logo {
animation: spin 2s infinite linear;
backface-visibility: hidden;
}
@keyframes spin {
to { rotate: 1turn; }
}Useful for preventing flickering or mirrored backside during spinning animations.
π When to Use backface-visibility
- β Flip card animations
- β Rotating UI components
- β Removing mirrored backward text
- β Preventing flicker in spinning objects
π When NOT to Use backface-visibility
- β When not using 3D transforms (rotateX/rotateY/translateZ)
- β Expecting it to hide rotated 2D elements
π§ͺ Real-World Use Cases
1οΈβ£ Credit Card Flip
credit card
.credit-card {
transform-style: preserve-3d;
transition: rotate 0.8s;
}
.credit-card .front,
.credit-card .back {
backface-visibility: hidden;
}
.credit-card:hover {
rotate: 180deg;
}2οΈβ£ Rotating Badge
badge
.badge {
animation: turn 1.5s linear infinite;
backface-visibility: hidden;
}
@keyframes turn {
to { rotateY: 360deg; }
}β οΈ Common Mistakes
- β Forgetting transform-style: preserve-3d for nested 3D elements
- β Expecting backface-visibility to hide 2D rotated content
- β Not placing backface-visibility on BOTH sides of a flip card
- β Using opacity: 0 instead β leads to click issues
Note
π₯ Summary
backface-visibility is crucial for polished 3D animations and UI flips. It prevents reversed text or unwanted backside content from showing when an element rotates in 3D.
- hidden β backside invisible (recommended)
- visible β backside shown (mirrored)