Languages
[Edit]
EN

CSS - flip image both vertically and horizontally

0 points
Created by:
sienko
743

In this article, we would like to show you how to flip image both vertically and horizontally using CSS.

Quick solution:

.flipped {
    transform: scale(-1, -1);
}

or:

.flipped {
    transform: rotateX(180deg) rotateY(180deg);
}

 

Practical examples

1. Using scale(-1, -1)

In this example, we use transform CSS property with scale() function set to (-1, -1)  to flip the image vertically and horizontally.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    .flipped {
        transform: scale(-1, -1);
    }

  </style>
</head>
<body>
  <div>Original image:</div>
  <img src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
  <br>
  <div>transformed image</div>
  <img class="flipped" src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
</body>
</html>

2. Using rotateX(180deg) rotateY(180deg)

In this solution, we rotate the image by an angle of 180 degrees using rotateX() and rotateY() functions.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    .flipped {
        transform: rotateX(180deg) rotateY(180deg);
    }

  </style>
</head>
<body>
  <div>Original image:</div>
  <img src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
  <br>
  <div>transformed image</div>
  <img class="flipped" src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
</body>
</html>

See also

  1. CSS - flip image vertically

  2. CSS - flip image horizontally

References

  1. transform - CSS: Cascading Style Sheets | MDN
  2. scaleX() - CSS: Cascading Style Sheets | MDN
  3. scaleY() - CSS: Cascading Style Sheets | MDN
  4. rotateX() - CSS: Cascading Style Sheets | MDN
  5. rotateY() - CSS: Cascading Style Sheets | MDN

Alternative titles

  1. CSS - rotate image 180 degrees both x and y-axis
  2. CSS - get vertical and horizontal mirror image (x and y-axis reflection)
  3. CSS - flip image vertically and horizontally at once
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join