How TO – Flip an Image


Previous


Next

Learn how to flip an image (add a mirror effect) with CSS.





Flip an Image

Move your mouse over the image.

Paris

How To Flip an Image

Example

<!DOCTYPE html>
<html>
<head>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<style>
img:hover {
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
}
</style>
</head>
<body>

<h2>Flip an Image</h2>
<p>Move your mouse over the image.</p>

<img src=”img_paris.jpg” alt=”Paris” width=”400″ height=”300″>

</body>
</html>

Note: This example does not work on tablets or mobile phones.

3D Flip Image with Text





Image Flip with Text

Hover over the image below:

Paris

Paris

What an amazing city


Step 1) Add HTML:

 

Example

<div class=”flip-box”>
  <div class=”flip-box-inner”>
    <div class=”flip-box-front”>
      <img src=”img_paris.jpg” alt=”Paris” style=”width:300px;height:200px”>
    </div>
    <div class=”flip-box-back”>
      <h2>Paris</h2>
      <p>What an amazing city</p>
    </div>
  </div>
</div>

Step 2) Add CSS:

Example

<!DOCTYPE html>
<html>
<head>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}

.flip-box {
background-color: transparent;
width: 300px;
height: 200px;
border: 1px solid #f1f1f1;
perspective: 1000px;
}

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

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

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

.flip-box-front {
background-color: #bbb;
color: black;
}

.flip-box-back {
background-color: #555;
color: white;
transform: rotateY(180deg);
}
</style>
</head>
<body>

<h1>Image Flip with Text</h1>
<h3>Hover over the image below:</h3>

<div>
<div>
<div>
<img src=”img_paris.jpg” alt=”Paris” style=”width:300px;height:200px”>
</div>
<div>
<h2>Paris</h2>
<p>What an amazing city</p>
</div>
</div>
</div>

</body>
</html>


Previous


Next

Scroll to Top