backface-visibility

Draft

Definition

The backface-visibility property is an essential component of 3D transformations in CSS3. As its name implies, it controls whether the back face of an element is visible when turned towards the user.

In a 3D space, an element has a front face and a back face. When you rotate an element, say, a card, you may want to hide the back of the card when it’s facing the user. This is where backface-visibility comes into play.

This property accepts two values:

  1. visible: The back face of the element is visible when facing the user.
  2. hidden: The back face of the element is not visible (or transparent) when facing the user.

Let’s visualize this with an example:

.flip-card {
  width: 300px;
  height: 200px;
  perspective: 1000px;
}

.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.8s;
  transform-style: preserve-3d;
}

.flip-card:hover .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-card-front,
.flip-card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
}

.flip-card-back {
  transform: rotateY(180deg);
}

In this example, a ‘flip card’ is set up to rotate around its Y-axis when hovered over. The backface-visibility is set to hidden, meaning when the card is rotated, the back of the card is invisible when it’s facing the user. This creates a neat flip effect where the front and back of the card are never visible at the same time.

The backface-visibility property is a fun tool to play with, and it can add engaging interactive elements to a web page. However, 3D transformations should be used judiciously as they can be processor-intensive, especially on mobile devices or lower-end computers. As always, the key is to find the right balance between form and function.