Smooth Image Zoom on Hover with CSS

This simple CSS hover effect will subtly & smoothly scale an image 20% larger on hover.

HTML

<a class="box" href="https://chrisyee.ca/">
    <img src="http://fpoimg.com/500x500?text=Preview" alt="FPO Image">
</a>

CSS

/* Make a square box with overflow hidden */
.box{
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
}

/* Set image to cover entire box */
.box img{
    position: absolute;
    top: 0;
    object-fit: cover;
    object-position: center;
    width: 100%;
    height: 100%;
    z-index: 1;
    transition: transform 8s ease-out;
}

/* Scale image on hover */
.box:hover img{
    transform: scale(1.2);
}

Leave a Reply

Your email address will not be published. Required fields are marked *