CSS Properties
CSS backface-visibility Property
Photo Credit to CodeToFun
🙋 Introduction
The backface-visibility
property in CSS is used to define whether the back face of an element is visible when it is not facing the screen.
This property is particularly useful when working with 3D transforms, where elements can be rotated, potentially showing their back side. By controlling the visibility of the back face, you can create cleaner, more intentional animations and designs.
💡 Syntax
The syntax for the backface-visibility
property is simple:
element {
backface-visibility: value;
}
🎛️ Default Value
The default value of the backface-visibility
property is visible, meaning that the back face of the element will be visible when rotated.
🏠 Property Values
Value | Description |
---|---|
visible | The back face of the element is visible when not facing the screen. This is the default value. |
hidden | The back face of the element is not visible when not facing the screen. |
📄 Example
In this example, we'll create a card that flips on hover. The backface-visibility
property is used to hide the back face of the card during the flip.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS backface-visibility Example</title>
<style>
.card {
width: 200px;
height: 300px;
perspective: 1000px;
}
.card-inner {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
transition: transform 0.6s;
}
.card:hover .card-inner {
transform: rotateY(180deg);
}
.card-front, .card-back {
width: 100%;
height: 100%;
position: absolute;
backface-visibility: hidden;
}
.card-back {
transform: rotateY(180deg);
}
</style>
</head>
<body>
<div class="card">
<div class="card-inner">
<div class="card-front">
<h2>Front</h2>
</div>
<div class="card-back">
<h2>Back</h2>
</div>
</div>
</div>
</body>
</html>
In this example, when the card is hovered over, it flips to reveal the back side. The backface-visibility: hidden; ensures that the content on the back side of the card is not visible until the card completes the flip.
🖥️ Browser Compatibility
The backface-visibility
property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. As always, it is advisable to test your website across different browsers to ensure consistent behavior.
🎉 Conclusion
The backface-visibility
property is an essential tool for creating smooth and visually appealing 3D transformations.
By controlling the visibility of the back face of an element, you can enhance the user experience and maintain the integrity of your design during animations and transitions. Experiment with this property to add depth and sophistication to your web projects.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS backface-visibility Property), please comment here. I will help you immediately.