About this snippet

Add an engaging image hover zoom effect to your website with pure CSS. This simple snippet uses CSS transforms to smoothly magnify images when users hover over them.

Size
907 bytes
Uses
HTML, CSS
Loads
placehold.co
Views
433
<div class="image-zoom-container">
  <img src="https://placehold.co/400x300/3498db/ffffff?text=Hover+Me" alt="Zoomable Image">
</div>
body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f0f0f0;
  margin: 0;
}
.image-zoom-container {
  width: 400px; /* Set container width */
  height: 300px; /* Set container height */
  overflow: hidden; /* This is crucial to hide the parts of the image that zoom out */
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.image-zoom-container img {
  width: 100%;
  height: 100%;
  object-fit: cover; /* Ensures the image covers the container, might crop */
  transition: transform 0.5s ease; /* Smooth transition for the zoom effect */
  display: block; /* Remove extra space below image */
}

.image-zoom-container:hover img {
  transform: scale(1.2); /* Zoom factor - adjust as needed */
}
Esc
↑↓ moveEnter select

Start from a template

Open an .html file, or HTML, CSS, JS, Markdown, Less or TypeScript files. You can also drop them here. Styles and scripts go into their panes.

Share

Source

Keyboard shortcuts

Save