How to create Image Folding Effect using HTML and CSS?

In today's digital age, creating visually appealing and interactive user interfaces has become a crucial aspect of web design. One of the popular effects used in modern websites is the Image Folding Effect. This effect provides a unique and engaging way to showcase images on your website. The art of Image Folding Effect can be created through the application of HTML and CSS, which are the fundamental components of contemporary digital structures. In this piece, we shall direct you through the progression of concocting an Image Folding Outcome, bit by bit, employing HTML and CSS. By the end of this article, you will have a solid understanding of how to implement this effect and make your website stand out.

Transform Property

The transform property in CSS is utilized to apply alterations to the shape, position, or size of an HTML element. It permits software engineers to alter the arrangement, revolution, contort, size, and other optical features of an element. The metamorphoses are accomplished through the assistance of 2D and 3D metamorphosis operations, like transfer, revolve, slant, and magnitude. The transform attribute functions seamlessly with all recent web browsers and can be employed to generate dynamic and animated visual components that elicit user engagement and interaction. The transmuted constituents maintain their indigenous size, contour, and location, and other proximate constituents adapt to the transmuted constituents. 'Tis a magnificent means to handle elements on a web page sans affecting the layout of the other elements on the page.


transform: [function] [value];

function can be any of the following &miinus;

  • translate() − moves an element along the x and y axis.

  • rotate() − rotates an element around its origin.

  • scale() − increases or decreases the size of an element.

  • skew() − distorts an element along the x or y axis.

  • matrix() − combines multiple transforms into a single transformation.

value is contingent on the specific function you are utilizing. As an illustration, should you choose to apply the translate() function, the value can be articulated as translate(x, y), where the numerical values of x and y indicate the quantity of pixels that are desired to displace the element along the horizontal and vertical axis.

:Nth-child Selector

The CSS selector known as :nth-child is employed to pick elements founded on their ordinal location within a progenitor element. It endows you with the capability to pinpoint a particular juvenile component enshrined within an ascendant constituent, and affix stylistic attributes to that nascent component. The :nth-child identifier employs an algorithm to ascertain which progeny components ought to be chosen. As an illustration, you have the capacity to utilize :nth-child(2) to cherry-pick the ensuing progeny element of a maternal element, or :nth-child(even) to cherry-pick all successors occupying an even slot.



Where a and b are integers, and n is a positive integer (starting from 1).


To create an image fold effect to the image, we will first need to divide the image into different parts. We will use <li> elements to store the different parts of the image. Now to select the different parts, in turn the <li> tags, we will use the above discussed :nth-child selector. Finally, we will transform each of the images in a way to create the paper folding effect.

The following code is essentially an HTML and CSS program that allows for the creation of a visually appealing and interactive image folding effect. It functions through a variety of declarations and directives that, when executed, are capable of rendering an image that appears to be folding in a visually engaging and dynamic fashion. The HTML code starts with a doctype declaration, followed by the opening of a HTML document, with a header that contains the title of the effect, and the declaration of a style tag. The body tag then follows, which contains a heading and an unordered list of child elements. The list is then styled with CSS to create the effect, which involves a container that encompasses four child elements, each with a folding effect.

The CSS code entails a set of instructions that are used to style the unordered list, specifying details such as the margins, padding, and position of the container. In addition, it applies a gradient of colors, which serves as the background image of the folding effect. It then specifies the dimensions of the container, its positioning, and its display properties. The styling also involves the specification of transitions and box-shadows, which contribute to the overall effect of the animation.

Furthermore, it applies the skewY() transformation property to alternate child elements of the container when the user hovers over it, creating a dynamic effect that simulates the appearance of an image being folded in half. The use of the nth-child() property helps to select the alternate child elements to apply the skewY() transformation. In conclusion, the nth-child() attribute is additionally employed to designate the backdrop stance of every progeny component, thus guaranteeing the accurate disposition of every fragment of the depiction during its folding.


The following is the complete code which we are going to look at in this example −

<!DOCTYPE html>
   <title>How to create Image Folding Effect using HTML and CSS?</title>
      body {
         margin: 0;
         padding: 0;
      .container {
         margin: 10;
         padding: 0;
         position: absolute;
         top: 50%;
         left: 50%;
         transform: translate(-50%,-50%);
         width: 480px;
         height: 270px;
         display: flex;
      .fold {
         list-style: none;
         width: 25%;
         background-image: linear-gradient(yellow,orange,red);;
         background-size: cover;
         height: 100%;
         transition: 0.5s;
      .container:hover .fold:nth-child(odd) {
         transform: skewY(15deg);
         box-shadow: inset 20px 0 50px rgba(0,0,0, .5);
      .container:hover .fold:nth-child(even) {
         transform: skewY(-15deg);
         box-shadow: inset 20px 0 50px rgba(0,0,0, .5);
      .container .fold:nth-child(1) {
         background-position: 0;
      .container .fold:nth-child(2) {
         background-position: -120px;
      .container .fold:nth-child(3) {
         background-position: -240px;
      .container .fold:nth-child(4) {
         background-position: -360px;
   <h4>How to create Image Folding Effect using HTML and CSS?</h4>
   <ul class="container">
      <li class="fold"></li>
      <li class="fold"></li>
      <li class="fold"></li>
      <li class="fold"></li>


To culminate, the Folded Image Impression constitutes an uncomplicated yet potent utensil for incorporating interactivity and ocular appeal to your website. By adhering to the prescribed procedures enunciated within this exposition, one may effortlessly engender this impression employing HTML and CSS. Whether you're a neophyte or a proficient programmer, this article has equipped you with the erudition and materials necessary to actualize the Image Folding Effect on your website. With a little creativity and experimentation, you can customize the effect to meet your specific design needs and enhance the user experience for your visitors. So, go ahead and start creating your own Image Folding Effect today!

Updated on: 13-Apr-2023


Kickstart Your Career

Get certified by completing the course

Get Started