How to flip an image with CSS

Updated · Web

Add transform: scaleX(-1); to the image to mirror it horizontally, or transform: scaleY(-1); to flip it vertically. The file itself is not changed; only how the browser draws it.

Quick answer

  1. Horizontal mirror: img { transform: scaleX(-1); }
  2. Vertical flip: img { transform: scaleY(-1); }
  3. Both at once: transform: scale(-1, -1);
The letters CSS next to the same letters with CSS scaleX(-1) applied.
CSS transform: scaleX(-1) mirrors in the browser without rewriting the image file. Download still needs a canvas or editor.
On this page
  1. The basic rule
  2. Combining with other transforms
  3. Transform origin and layout
  4. Flipping a background image
  5. Right-to-left layouts
  6. Animating a flip
  7. When to flip the file instead
  8. Questions
  9. Sources

The basic rule

.mirror {
  transform: scaleX(-1);
}

scaleX(-1) scales the element by −1 along the horizontal axis, which mirrors it around its centre. It works on <img>, <video>, <canvas>, inline SVG and any other element. Every current browser supports it without prefixes.

DeclarationResult
scaleX(-1)Mirror left–right
scaleY(-1)Flip top–bottom
scale(-1, -1)Both; looks like a 180° rotation
rotateY(180deg)Mirror left–right via a 3D turn; useful for card-flip animations
rotate(180deg)Upside down, not mirrored

The live demo below applies these to an image so you can compare them.

Combining with other transforms

transform takes a list, and a new transform declaration replaces the old one rather than adding to it. If the image is already rotated or scaled, include everything in one declaration:

.photo {
  transform: rotate(5deg) scaleX(-1);
}

Order matters: transforms apply from right to left. Alternatively, use the individual scale property, which combines with transform: scale: -1 1;.

Transform origin and layout

The flip happens around the element's centre by default (transform-origin: 50% 50%), so the image stays in place. Transforms never affect layout: the element keeps its original box, and neighbouring elements do not move.

If you change transform-origin to an edge, the image swings across that edge and may overlap other content or be clipped by overflow: hidden on a parent.

Flipping a background image

There is no background-transform. Flipping the element itself would also mirror any text inside it. Put the background on a pseudo-element and flip only that:

.hero {
  position: relative;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url(photo.jpg) center / cover;
  transform: scaleX(-1);
  z-index: -1;
}

Right-to-left layouts

Directional icons such as arrows should point the other way on Arabic or Hebrew pages. Flip them only in RTL context:

[dir="rtl"] .icon-arrow {
  transform: scaleX(-1);
}

Do not mirror photos, logos or icons that have no direction (such as a search magnifier or a checkmark).

Animating a flip

Add a transition to animate between the normal and flipped state:

.card {
  transition: transform 300ms ease;
}
.card.is-flipped {
  transform: rotateY(180deg);
}
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
}

rotateY gives a 3D turn when a parent has perspective set; scaleX animates as a squeeze through zero width.

When to flip the file instead

CSS only changes the display. If someone downloads the image, uses it in an email, or prints it from another program, they get the original. In those cases flip the file itself, for example with the mirror tool, and use the flipped file in your page.

Live CSS transform

This is a real CSS transform on an image in this page — not a screenshot. Toggle the buttons and watch the letters reverse.

The letters CSS, transformed live
img { transform: scaleX(-1); }
Letter R mirrored left to right across a dashed vertical axis.
A horizontal flip swaps pixels across a vertical axis. The letter R becomes its mirror, not a rotation.

Questions

Does scaleX(-1) change the image file?

No. It only changes how the browser displays the image. Saving the image gives the original file.

Can I flip an image with Tailwind CSS?

Yes. Tailwind's -scale-x-100 class sets a horizontal scale of -1, and -scale-y-100 flips vertically.

Does a flipped image affect accessibility?

Not by itself. Keep the alt text describing what the image shows; mention the mirroring only if it matters to the content.

Sources

All guides