Flip Image on hover using CSS 3.0

In this post we will take a look on flipping images using CSS3.0. Let us assume that we have a div with two images as following,

<div id="flipimagediv">
 <img id="backImage" src="images/srt.jpg" />
 <img id="frontImage" src="images/msdhoni.jpg" />

Now we want to flip these two images on mouse hover. We will achieve that using CSS3.0. To start with let us set container div style. In container we are setting width, height and display.

#flipimagediv {
display: inline-block;
width: auto;
height: auto;
position: relative;

After setting container div styles let us go ahead and set image styles. In image style we are setting usual properties like height and width. We are setting

  • transition-property
  • transition-duration
  • transition-timing-function

#flipimagediv img {
width: 400px;
height: 300px;
position: absolute;
transition-property: opacity;
transition-duration: 3s;
transition-timing-function: linear;

Last we need to change opacity of images on hover. We can do that  as following.

#flipimagediv #frontImage, #flipimagediv:hover #backImage {
opacity: 1;
#flipimagediv:hover #frontImage, #flipimagediv #backImage {
opacity: 0;

In this way we can flip images on hover using CSS 3.0. I hope you find this post useful. Thanks for reading.

Published by

Dhananjay Kumar

Dhananjay Kumar is Developer Evangelist for Infragistics. He is a 8 times Microsoft MVP and well respected Developer Advocate in India.He is the author of 900+ Blog Posts, and can often be found speaking around India at conferences and hosting free workshops for programmers across the country. So far, he has hosted 60 free workshops on various topics like JavaScript, Angular, WCF, ASP.NET MVC, C#, Azure etc. Follow him on twitter @debug_mode for all the updates about his blog posts and workshops. You can send him email at debugmode [at] outlook [dot] com

One thought on “Flip Image on hover using CSS 3.0”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s