How to create: Image overlay zoom

Learn how to create an image overlay zoom effect on hover.

Full-screen image overlay zoom

Hover over the image to view the zoom effect.

Avatar
Hello World

Try it yourself

How to create an overlay zoom effect

Step 1 - Add HTML:

<div class="container">
  <img src="img_avatar.png" alt="Avatar" class="image">
  <div class="overlay">
    <div class="text">Hello World</div>
  </div>
</div>

Step 2 - Add CSS:

/* The container that needs to place the overlay. Adjust the width as needed */
.container {
  position: relative;
  width: 50%;
}
/* Make the image responsive */
.image {
  width: 100%;
  height: auto;
}
/* Overlay effect (full height and full width) - located at the top of the container and above the image */
.overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #008CBA;
  overflow: hidden;
  width: 100%;
  height: 100%;
  transform: scale(0);
  transition: .3s ease;
}
/* The overlay text will 'scale' when the mouse is hovered over the container */
.container:hover .overlay {
  transform: scale(1);
}
/* Some text inside the overlay, vertically and horizontally centered */
.text {
  color: white;
  font-size: 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

Try it yourself

Related pages

Tutorial:CSS Image

Tutorial:How to Create Image Overlay Hover Effect