Skip to content

Flip Card

The Flip Card component is a purely CSS-based component that creates a card with front and back sides that can be flipped either horizontally or vertically. The flip effect can be triggered on hover or when the card has an “active” class.

This component has no dependencies other than the core Metro UI CSS variables.

<div class="flip-card">
<div class="front">
<!-- Front content goes here -->
</div>
<div class="back">
<!-- Back content goes here -->
</div>
</div>
<div class="flip-card effect-on-hover">
<div class="front">
<h3>Front Side</h3>
<p>This is the front content of the card.</p>
</div>
<div class="back">
<h3>Back Side</h3>
<p>This is the back content of the card.</p>
</div>
</div>
<div class="flip-card flip-horizontal effect-on-active">
<div class="front">
<h3>Front Side</h3>
<p>Click a button to activate the flip.</p>
</div>
<div class="back">
<h3>Back Side</h3>
<p>This is the back content of the card.</p>
</div>
</div>

To trigger the flip effect with JavaScript:

// Select the flip card
const flipCard = document.querySelector('.flip-card.effect-on-active');
// Toggle the active class to flip the card
flipCard.classList.toggle('active');

This component is CSS-only and does not have JavaScript plugin parameters.

This component is CSS-only and does not have JavaScript API methods.

This component is CSS-only and does not have JavaScript events.

VariableDefault (Light)Dark ModeDescription
@defaultAnimationSpeed.3sSameThe duration of the flip animation
@defaultPerspective600pxSameThe perspective value for the 3D effect
:root {
--defaultAnimationSpeed: 0.5s; /* Slower animation */
--defaultPerspective: 1000px; /* More dramatic perspective */
}
  • .flip-card - The main container class for the flip card component
  • .front - The front side of the card
  • .back - The back side of the card
  • .flip-horizontal - Makes the card flip horizontally (by default, the card flips vertically)
  • .effect-on-hover - Triggers the flip effect when the user hovers over the card
  • .effect-on-active - Triggers the flip effect when the card has the active class
  • The flip card requires a defined width and height to work properly
  • Both the front and back sides are absolutely positioned within the container
  • The component uses CSS 3D transforms for the flip effect
  • The flip effect is triggered either on hover or by adding/removing the active class