Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS backface-visibility Property

Posted in CSS Tutorial
Updated on Oct 01, 2024
By Mari Selvan
👁️ 15 - Views
⏳ 4 mins
💬 1 Comment
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:

Syntax
Copied
Copy To Clipboard
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

ValueDescription
visibleThe back face of the element is visible when not facing the screen. This is the default value.
hiddenThe 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.

index.html
Copied
Copy To Clipboard
<!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:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

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

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy