CSSeasyCSS

Image Hover Zoom Effect

Smooth zoom effect on image hover within a container.

01

The problem

You want images to smoothly zoom in when hovered, commonly used in galleries and cards.

02

The solution

CSS
.image-zoom-container {
  overflow: hidden;
  border-radius: 12px;
  position: relative;
}

.image-zoom-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.image-zoom-container:hover img {
  transform: scale(1.1);
}

/* With overlay text */
.image-zoom-overlay {
  overflow: hidden;
  border-radius: 12px;
  position: relative;
}

.image-zoom-overlay img {
  width: 100%;
  transition: transform 0.5s ease;
}

.image-zoom-overlay .overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.8),
    transparent
  );
  display: flex;
  align-items: flex-end;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-zoom-overlay:hover img {
  transform: scale(1.1);
}

.image-zoom-overlay:hover .overlay {
  opacity: 1;
}

03

See it live

Isolated previewSandboxed
04

Put it to work

Example
<div class="image-zoom-container">
  <img src="photo.jpg" alt="Gallery image">
</div>

<div class="image-zoom-overlay">
  <img src="photo.jpg" alt="Gallery image">
  <div class="overlay">
    <h3>Image Title</h3>
  </div>
</div>

Worth knowing

The container overflow: hidden prevents the zoomed image from breaking the layout.