CSS Animation Example: 3D Card Flip

The "3D Card Flip" is a highly engaging interaction perfect for displaying secondary information, such as product details behind an image or a bio behind a profile picture.

Front View

Hover or click to flip

Back View

Hidden Details!

This effect relies on three core CSS properties working in harmony:

  1. perspective: Applied to the outermost container, this defines the depth of the 3D space. Without it, the rotation looks completely flat.
  2. transform-style: preserve-3d: Applied to the inner container that holds the front and back faces, allowing its children to exist in standard 3D space rather than being flattened.
  3. backface-visibility: hidden: Applied to both the front and back face elements. The back face is pre-rotated 180deg. When the inner container rotates, the front face turns away (becoming invisible), and the back face rotates into view (becoming visible).

Here is the complete code to create the 3D Card Flip animation.

View Output

Accessibility Considerations

Large elements flipping in 3D space can induce dizziness or nausea for some users. prefers-reduced-motion is a CSS media feature used to detect if a user has enabled a setting on their device to minimize the amount of non-essential animation or motion. We can use it to completely bypass the smooth 3D flip animation, causing the card to simply snap instantly to its back face when hovered or focused.

Additionally, notice that we've added tabindex="0" to the outer container. Since a <div> isn't natively focusable via keyboard navigation, adding tabindex="0" allows users navigating with the "Tab" key to access and trigger the flip effect.

Here's what we used in our example:


@media (prefers-reduced-motion: reduce) {
    .flip-card-inner {
        /* Remove the transition duration, causing an instant state swap */
        transition: none; 
    }
}