CSS backface-visibility Property
The backface-visibility property determines whether the back-facing side of an element is visible when it is rotated in three-dimensional space.
It is commonly used with CSS 3D transforms to create flipping cards, rotating panels, and other interactive effects. Setting backface-visibility: hidden prevents an element's reverse side from being displayed when it faces away from the viewer.
backface-visibility Syntax
selector {
backface-visibility: hidden;
}
The property accepts two keywords: visible and hidden.
.default-face {
backface-visibility: visible;
}
.hidden-face {
backface-visibility: hidden;
}
It also accepts CSS-wide values such as inherit, initial, revert, revert-layer, and unset.
Property Values
| Value | Description |
|---|---|
visible |
Displays the back-facing side of the element when it faces away from the viewer. This is the initial value. |
hidden |
Hides the element when its back-facing side is directed toward the viewer. |
The property applies to transformable elements, is not inherited, and has an initial value of visible.
Its computed value is the specified keyword. The property is not animatable, so it cannot transition gradually between visible and hidden.
The property affects the element's visual rendering, not whether the element exists in the document or participates in layout.
How backface-visibility Works
In a 3D transformation, an element has a front-facing side and a back-facing side. When the element rotates, its back can become directed toward the viewer.
By default, the browser displays both sides. When the back is visible, the element's content may appear reversed, as though viewed from behind.
.rotated-box {
transform: rotateY(180deg);
backface-visibility: visible;
}
With visible, the rotated element can still be seen from the back.
.rotated-box {
transform: rotateY(180deg);
backface-visibility: hidden;
}
With hidden, the same element is not painted while its back faces the viewer.
The property is especially useful when two separate elements represent the front and back of a rotating card.
Although the examples use rotateY(), the property also works with rotations around the X axis and other 3D transformations that turn an element's back toward the viewer.
visible vs. hidden
The difference between the two values becomes apparent when an element rotates far enough for its reverse side to face the viewer.
Using visible
.card {
transform: rotateY(180deg);
backface-visibility: visible;
}
The card remains visible from behind. Text and other content may appear mirrored.
Using hidden
.card {
transform: rotateY(180deg);
backface-visibility: hidden;
}
The card disappears visually when its back faces the viewer.
This does not hide a separate back panel. To create a two-sided card, the front and back are usually separate elements with their own transforms and backface-visibility: hidden declarations.
When the card rotates, one face becomes hidden while the other turns toward the viewer.
Using 3D Transforms
The backface-visibility property is used with three-dimensional transformations, particularly rotateX() and rotateY().
Horizontal Flip
.horizontal-flip {
transform: rotateY(180deg);
backface-visibility: hidden;
}
The element rotates around its vertical Y axis, producing a horizontal flipping effect.
Vertical Flip
.vertical-flip {
transform: rotateX(180deg);
backface-visibility: hidden;
}
The element rotates around its horizontal X axis, producing a vertical flipping effect.
Combining Rotations
.combined-rotation {
transform: rotateX(30deg) rotateY(180deg);
backface-visibility: hidden;
}
Multiple transforms can be combined, and their order affects the resulting orientation.
A two-dimensional rotation using rotate() turns an element within its own plane. It does not, by itself, expose the back-facing side in the same way as a 3D rotation.
Creating Flip Cards
A common application is a card with separate front and back faces. The faces are positioned on top of each other inside a rotating container.
<div class="flip-scene">
<div class="flip-card">
<div class="flip-face flip-front">Front</div>
<div class="flip-face flip-back">Back</div>
</div>
</div>
.flip-scene {
width: 240px;
height: 150px;
perspective: 800px;
}
.flip-card {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 0.6s ease;
}
.flip-scene:hover .flip-card {
transform: rotateY(180deg);
}
.flip-face {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
border-radius: 8px;
backface-visibility: hidden;
}
.flip-front {
background-color: #1769aa;
color: #fff;
}
.flip-back {
background-color: #e8f2fb;
color: #174c78;
transform: rotateY(180deg);
}
The front face initially points toward the viewer. The back face is rotated 180 degrees and remains hidden because its reverse side faces the viewer.
When the card container rotates 180 degrees, the front becomes hidden and the back faces forward.
Hover-based interactions should also provide a keyboard-accessible way to reveal the reverse side. The interactive example below uses a native button for that purpose.
Perspective and transform-style
The perspective and transform-style properties often work alongside backface-visibility to create realistic 3D effects.
Using perspective
.scene {
perspective: 800px;
}
The perspective property controls the viewing distance for transformed descendants. Smaller positive values generally produce a stronger perspective effect.
Perspective is not required for backface-visibility to work, but it helps make rotations appear three-dimensional.
Using transform-style
.card {
transform-style: preserve-3d;
}
The preserve-3d value allows an element's transformed descendants to remain positioned in three-dimensional space rather than being flattened into the parent's plane.
This is important for a flip card containing separate front and back faces.
Combining the Properties
.scene {
perspective: 800px;
}
.card {
transform-style: preserve-3d;
transform: rotateY(180deg);
}
.card-face {
backface-visibility: hidden;
}
In this arrangement, the scene establishes perspective, the card preserves the 3D positioning of its faces, and each face hides its reverse side.
Some properties, including certain overflow, opacity, and filtering values, can force descendants to be flattened even when transform-style: preserve-3d is specified. Apply those effects to an appropriate wrapper when necessary.
backface-visibility Example
The following example demonstrates an interactive 3D flip card. Select the button to rotate the card and reveal its reverse side.
Both faces use backface-visibility: hidden, preventing mirrored content from appearing during the rotation.
<div class="backface-demo">
<button class="flip-toggle" type="button" aria-pressed="false">Flip Card</button>
<div class="backface-scene">
<div class="backface-card">
<div class="backface-face backface-front">Front Side</div>
<div class="backface-face backface-back">Back Side</div>
</div>
</div>
</div>
.backface-demo {
display: flex;
flex-direction: column;
align-items: center;
gap: 15px;
padding: 20px;
}
.flip-toggle {
padding: 8px 18px;
border: 1px solid #1769aa;
background-color: #1769aa;
color: #fff;
cursor: pointer;
}
.flip-toggle:focus-visible {
outline: 2px solid #222;
outline-offset: 3px;
}
.backface-scene {
width: 220px;
height: 140px;
perspective: 800px;
}
.backface-card {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 0.6s ease;
}
.backface-demo.is-flipped .backface-card {
transform: rotateY(180deg);
}
.backface-face {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
border-radius: 8px;
font-size: 20px;
font-weight: bold;
backface-visibility: hidden;
}
.backface-front {
background-color: #1769aa;
color: #fff;
}
.backface-back {
background-color: #e8f2fb;
color: #174c78;
transform: rotateY(180deg);
}
@media (prefers-reduced-motion: reduce) {
.backface-card {
transition: none;
}
}
document.querySelectorAll(".backface-demo").forEach(function(demo) {
const button = demo.querySelector(".flip-toggle");
button.addEventListener("click", function() {
const flipped = demo.classList.toggle("is-flipped");
button.setAttribute("aria-pressed", String(flipped));
});
});
The button toggles a class on the demonstration container. That class rotates the card while the individual faces retain their own backface visibility settings.
Initially, the blue front face is visible. Selecting the button rotates the card 180 degrees and reveals the lighter back face.
Select the button again to return to the front. The button also works with keyboard activation using Enter or Space.
When reduced motion is requested, the card changes sides without an animated transition.
Accessibility Considerations
Although backface-visibility: hidden removes an element from visual rendering when its back faces the viewer, it does not automatically remove the element from the accessibility tree or keyboard navigation.
This is particularly important when a flip card contains buttons, links, or form controls on both faces.
Keep Hidden Controls Out of Keyboard Navigation
If one face contains interactive elements, ensure those elements cannot receive keyboard focus while that face is visually hidden.
Depending on the interaction, JavaScript can update the inert attribute or manage focusability when the card changes sides.
Provide an Accessible Trigger
Use a native button to activate the flip rather than relying exclusively on hover.
A toggle button can use aria-pressed to communicate its current state, as shown in the example.
Respect Reduced Motion
@media (prefers-reduced-motion: reduce) {
.flip-card {
transition: none;
}
}
This removes the animated transition while allowing the card to change sides.
For interfaces containing essential information, consider providing a nonanimated way to access both faces, such as an expandable section or separate content panels.
Important Considerations
Keep the following points in mind when using backface-visibility:
- Default value: The initial value is
visible, so an element's back-facing side can be displayed. - Hidden backfaces: Use
hiddento prevent an element from being painted when its reverse side faces the viewer. - 3D transformations: The property is primarily useful with transformations such as
rotateX()androtateY(). - Separate faces: A two-sided flip card usually uses two elements, each with its own backface visibility setting.
- Perspective: Use
perspectivewhen a realistic 3D viewing effect is needed. - 3D preservation: Use
transform-style: preserve-3dwhen child elements must remain in a shared 3D space. - Layout: Hiding a backface does not remove the element from document layout.
- Animation: The property itself is not animatable, but it can control visibility during an animated transform.
- Keyboard access: Visually hidden faces may still contain focusable elements, so manage interactive content appropriately.
- Reduced motion: Provide a reduced-motion alternative for animated flipping effects.
Use backface-visibility to control which surfaces are displayed during 3D transformations, especially when creating interfaces with distinct front and back faces.
Browser Support
The backface-visibility property has Baseline Widely available status and is supported in modern versions of Chrome, Edge, Firefox, Safari, and other major browsers.
Older WebKit-based browsers may require the -webkit-backface-visibility prefix.
.card-face {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
For older browser compatibility, place the prefixed declaration before the standard property.
Complex 3D transformations can still have browser-specific rendering differences, so test complete effects rather than checking the property in isolation.
Visit Can I Use? to check compatibility with CSS 3D transforms, including backface visibility.
Specifications
The backface-visibility property is defined in the CSS Transforms Module Level 2 specification.
