How to Zoom an Image on Hover with CSS

Apply transform: scale(1.4) to the image when its frame is hovered to make it 1.4 times as wide and tall. Use transition to smooth the change and overflow: hidden on the frame to clip the parts that extend past it.

Scale the image inside its frame

The outer .zoom-frame receives the hover and the inner img gets the transform. The frame keeps its size as the pointer enters or leaves. transition: transform 200ms ease animates only the transform. See the CSS transform rendering specification.

.zoom-frame {
  display: block;
  overflow: hidden;
}
.zoom-frame img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform 200ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .zoom-frame:hover img { transform: scale(1.4); }
}
.zoom-frame:focus-visible {
  outline: 3px solid #005d8c;
  outline-offset: 4px;
}
.zoom-frame:focus-visible img { transform: scale(1.4); }

@media (prefers-reduced-motion: reduce) {
  .zoom-frame img { transition: none; }
  .zoom-frame:hover img,
  .zoom-frame:focus-visible img { transform: none; }
}

Run the complete example in a browser

Save the full code in UTF-8 as hover-image-zoom.html and open it in a browser. It loads the mountain image used in the example over the internet. If you swap in your own photo, update src, the link’s href, the actual width and height, the alt text, and the link’s accessible name.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Image zoom on hover</title>
  <style>
    body { margin: 0; color: #183341; font: 1rem/1.6 system-ui, sans-serif; }
    main { width: min(400px, calc(100% - 2rem)); margin: 2rem auto; overflow-wrap: anywhere; }
    h1 { font-size: 1.4rem; }
    .zoom-frame {
      display: block;
      overflow: hidden;
    }
    .zoom-frame img {
      display: block;
      width: 100%;
      height: auto;
      transition: transform 200ms ease;
    }
    @media (hover: hover) and (pointer: fine) {
      .zoom-frame:hover img { transform: scale(1.4); }
    }
    .zoom-frame:focus-visible {
      outline: 3px solid #005d8c;
      outline-offset: 4px;
    }
    .zoom-frame:focus-visible img { transform: scale(1.4); }

    @media (prefers-reduced-motion: reduce) {
      .zoom-frame img { transition: none; }
      .zoom-frame:hover img,
      .zoom-frame:focus-visible img { transform: none; }
    }
  </style>
</head>
<body>
  <main>
    <h1>Image zoom on hover</h1>
    <a class="zoom-frame" href="https://www.codingfactory.net/wp-content/uploads/css-image-center-ko-20261027-v1.webp" aria-label="Open the full-size mountain image">
      <img src="https://www.codingfactory.net/wp-content/uploads/css-image-center-ko-20261027-v1.webp" width="1600" height="900"
           alt="Framed picture of mountains, a lake, and the sun">
    </a>
    <p>Hover or press Tab to zoom. Open the link to view the full-size image.</p>
  </main>
</body>
</html>

Move the pointer over the frame to zoom around the image center. Move it away to return to normal. Try 1.15 in place of 1.4 and compare how much the edges crop. Change both occurrences to keep mouse and keyboard zoom at the same scale.

Control what extends past the frame

In developer tools, temporarily disable overflow: hidden on the frame and compare on a wide screen. The picture can extend past its frame, while the paragraph below stays in its original position. The transform does not reflow the page. Re-enable clipping after the comparison.

A 400px image scales to 560px at 1.4. Scaling from the center extends it 80px beyond each horizontal edge. The frame clips those 80px on each side when overflow is hidden.

Support keyboard, touch, and reduced motion

The hover media feature enables the mouse effect when the primary pointing device can hover accurately. Press Tab to reach the link. Its :focus-visible rule draws an outline and enables the same zoom. See the focus-visible selector specification. On touch, tap the link to open the full image.

If the reduced-motion preference is set to reduce, the demo turns off scaling and animation while keeping the keyboard outline and link. Keep essential information available without hovering.

Diagnose a zoom that does not work

  • If the image is missing, check its URL and request in the Network panel. A replacement file path should resolve from the HTML file.
  • If the frame expands or surrounding content shifts, look for a rule that changes width or height. Apply scale() to the inner image.
  • If the mouse effect alone fails, check the device’s hover capabilities. If keyboard focus also fails to zoom, check the system’s reduced-motion setting and the computed transform.

The CSS transforms and transitions guide covers transform and transition timing in more detail.