How to create: Image overlay icon

Learn how to create image overlay icon effect on mouse hover.

Image overlay icon

Hover the mouse over the image to view the overlay effect.

Try It Yourself

How to create overlay image icon

Step 1 - Add HTML:

<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="container">
  <img src="img_avatar.png" alt="Avatar" class="image">
  <div class="overlay">
    <a href="#" class="icon" title="User Profile">
      <i class="fa fa-user"></i>
    </a>
  </div>
</div>

Second Step - Add CSS:

/* Container where the overlay needs to be placed. Adjust the width as needed */
.container {
  position: relative;
  width: 100%;
  max-width: 400px;
}
/* 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;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  width: 100%;
  opacity: 0;
  transition: .3s ease;
  background-color: red;
}
/* The overlay icon fades in when you hover over the container */
.container:hover .overlay {
  opacity: 1;
}
/* Center the icon within the overlay in both vertical and horizontal directions */
.icon {
  color: white;
  font-size: 100px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  text-align: center;
}
/* Change color when mouse is over the icon */
.fa-user:hover {
  color: #eee;
}

Try It Yourself

Related Pages

Tutorial:CSS Image

Tutorial:How to Create an Image Overlay Hover Effect