Magento catalog image change on hover

Magento catalog image change on hover

October 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento catalog image change on hover

Changing Magento Product Images on Hover

Implementing an image hover effect like Club Monaco’s is a great way to enhance user experience on your Magento store’s catalog pages. This feature allows customers to preview multiple images of a product without having to click through the thumbnails, improving navigation and visual appeal.

Understanding the Requirement

The goal is to replace the main product image with an alternate image when the customer hovers over it. We’ll be using CSS for the hover effect and Magento’s built-in features to manage the multiple images.

Step 1: Prepare Your Product Images

First, ensure your products have more than one image assigned in the Magento admin panel. To do this:

  1. Go to Catalog > Manage Products.
  2. Select the product you want to modify.
  3. In the ‘Media Gallery’ section, click on ‘Upload Files’.
  4. Add and save multiple images for each product.

Step 2: Create a New CSS Class

Next, we need to create a new CSS class that will apply the hover effect to our main image. You can do this in your Magento theme’s custom.css file:

#main-image {
    transition: all .3s ease;
}

#main-image:hover img {
    opacity: 0;
}

This code sets up a smooth transition for the hover effect and reduces the opacity of the main image when hovering.

Step 3: Modify the Product View Template

Now, we need to modify the product view template to include additional image markup that will be used in our hover effect. Open your theme’s catalog/product/view/media.phtml file:

<div class="product-img-box">
    <img id="main-image" src="<?php echo $this->helper('catalog/image')->init($product, 'image'); ?>"
         alt="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>" />
</div>

We’ve added an ID of main-image to our main product image for easy CSS targeting.

Step 4: Include Additional Image Markup

Next, we need to include the markup for the alternate images that will appear on hover. Add this code right after the media.phtml script:

<div id="hover-images">
    <?php foreach ($this->getMediaGalleryImages($product) as $_image): ?>
    <img src="<?php echo $this->helper('catalog/image')->init($_image, 'image') ?>" alt="" />
    <?php endforeach; ?>
</div>

This code generates an unordered list of all the product’s images and sets their src attributes.

Step 5: Style the Hover Effect

Finally, we need to style our hover effect. In your theme’s custom.css file:

#hover-images {
    position: absolute;
    top: 0;
    left: 0;
    display: none;
}

#main-image:hover + #hover-images {
    display: flex;
}

This code positions the alternate images and displays them when the main image is hovered over.

Conclusion

Implementing an image hover effect in Magento requires a combination of CSS styling and minor template modifications. By following this guide, you can add engaging visual features to your store’s catalog pages that enhance user experience and drive sales.

Remember, if you need professional assistance with customizing your Magento store, our expert team at Laravel Company is always ready to help. Contact us today to discuss your e-commerce development needs!

Back to Laravel Company

Catalog Themes Admin Customers

Our network