Image Flip with jQuery CSS

by Vincy. Last modified on July 12th, 2022.

In this tutorial, we are going to see how to flip an image using jQuery and CSS. In a previous tutorial, we have seen various jQuery animation to rotate image.

In this example, we are flipping images in a horizontal direction using a 3D transform. We are using the CSS transform property to flip images in X-axis. This CSS property will be set via jQuery.

View Demo

Image Flip HTML and CSS

This code shows HTML markup for the flippable image.


<div id="flip-box">
	<img src="fixed_bg.jpg">
<div id="flip-link" class="demo-submit">
	Flip the Image

and the styles are,

	#flip-box {
		width: 200px;
		height: 150px;
		transition: 0.9s;
		transform-style: preserve-3d;
		position: relative;
		padding: 10px 20px;
		background: #555;
		border: 0;
		color: #FFF;

jQuery Image Flip

This jQuery script shows how to change the image transform property on the click event. By changing transform property the image will flip back and forth. The code is,

<script type="text/javascript">
		if($("#flip-box").css("transform") == 'none') {
			$("#flip-box img").attr("src","fixed_bg1.jpg");
		else {
			$("#flip-box img").attr("src","fixed_bg.jpg");

View DemoDownload

Written by Vincy, a web developer with 15+ years of experience and a Masters degree in Computer Science. She specializes in building modern, lightweight websites using PHP, JavaScript, React, and related technologies. Phppot helps you in mastering web development through over a decade of publishing quality tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *

↑ Back to Top

Share this page