Add A Hover Effect To Product Images On my SHOPIFY Collection Pages

Topic summary

Issue: A user wants to add a hover effect to product images on Shopify collection and product pages.

Solution Provided:

The process involves two main steps:

  1. Add CSS code: Navigate to Online Store > Themes > Edit code, then paste specific CSS code (available on GitHub) at the bottom of theme.css.liquid or styles.css.liquid.

  2. Edit product image code: Locate the product image file in the Snippets directory (typically product-grid-item.liquid, product-card.liquid, product-card-grid.liquid, or product-loop.liquid). Find the <img tag and wrap it with specific HTML div tags to enable the hover effect.

Hover Effect Options:

  • Show alternate product image on hover
  • Display custom text (e.g., product title and price)
  • Combine both image and text

Note: The detailed code examples in the response appear reversed/mirrored, making them difficult to read directly.

Open Question: One user asks what to do if none of the specified snippet files exist in their theme’s Snippets directory—this remains unanswered.

Summarized with AI on November 10. AI used: claude-sonnet-4-5-20250929.

How to add a hover effect to the product image on my shopify collection or product page.

MY theme name: shella theme

You can add a hover effect to your product images on the home page and on collection pages. When a customer moves the cursor over a product image, the image will change to show either an alternate product image, custom text, or a combination of the two:

Adepsstudio_0-1664208848255.gif

Add CSS to your stylesheet

To add a hover effect, you will need to add some CSS code to your theme’s stylesheet:

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. In the Assets directory, click theme.css.liquid. If your theme doesn’t have a theme.css.liquid file, then click styles.css.liquid, or another file with a .css.liquid file extension.
  4. At the very bottom of the file, paste this code hosted on GitHub.
  5. Click Save.

Edit the code for your product images

To edit the code for your product images:

  1. In the Snippets directory, click product-grid-item.liquid.
    If your theme doesn’t have a product-grid-item.liquid file, then look for one of the following:

    • product-card.liquid
    • product-card-grid.liquid
    • product-loop.liquid
  2. Find the HTML img tag for your product images by searching for <img. The code for the tag varies theme to theme, but always starts with <img, and ends with either > or />. It might look similar to this:

    <img src="{{ featured.featured_image.src | img_url: '450x450' }}" alt="{{ featured.featured_image.alt | escape }}">
    
  3. On a new line above the img tag, paste the following code:

    <div class="reveal">
    

    On a new line below the img tag, paste the following code:

    </div>
    

    The result should look like this:

    <div class="reveal">
    <img src="{{ featured.featured_image.src | img_url: '450x450' }}" alt="{{ featured.featured_image.alt | escape }}">
    </div>
    
  4. On a new line below the img tag and above the closing tag, add the code that changes what is shown on hover. The code that you add will vary depending on whether you want to show an alternate product image, custom text, or a combination of the two. Follow the steps for the customization of your choice.

Show an alternate product image on hover

  1. On a new line below the img tag and above the closing tag, paste the following code:

    <img class="hidden" src="{{ product.images.last | img_url: '450x450' }}" alt="{{ product.images.last.alt | escape }}" />
    

    Your code should look like this:

    <div class="reveal">
      <img src="{{ featured.featured_image.src | img_url: '450x450' }}" alt="{{ featured.featured_image.alt | escape }}"><!-- this is your original image tag -->
      <img class="hidden" src="{{ product.images.last | img_url: '450x450' }}" alt="{{ product.images.last.alt | escape }}" />
    </div>
    
  2. Click Save.

Show custom text on hover

  1. On a new line below the img tag and above the closing tag, paste the following code:

    <div class="hidden">
      <div class="caption">
        <div class="centered">
        YOUR TEXT
        </div><!-- end of .centered -->
      </div><!-- end of .caption -->
    </div><!-- end of .hidden -->
    

    Replace YOUR TEXT with the text of your choice. You can use HTML and Liquid tags, for example:

    <div class="hidden">
      <div class="caption">
        <div class="centered">
          <p>{{ product.title }}</p>
          <p>{{ product.price | money }}</p>
        </div><!-- end of .centered -->
      </div><!-- end of .caption -->
    </div><!-- end of .hidden -->
    

    The example code above shows the title and the price of a product when you hover over the image.

    Your code should look like this:

    <div class="reveal">
      <img src="{{ featured.featured_image.src | img_url: '450x450' }}" alt="{{ featured.featured_image.alt | escape }}"><!-- this is your original image tag -->
      <div class="hidden">
        <div class="caption">
          <div class="centered">
            YOUR TEXT
          </div><!-- end of .centered -->
        </div><!-- end of .caption -->
      </div><!-- end of .hidden -->
    </div><!-- end of .reveal -->.
    
  2. Click Save.

Show an alternate product image with custom text on hover

  1. On a new line below the img tag and above the closing tag, paste the following code:

      <div class="hidden">
        <img src="{{ product.images.last | img_url: '450x450' }}" alt="{{ product.images.last.alt | escape }}" />
        <div class="caption">
          <div class="centered">
            YOUR TEXT
          </div><!-- end of .centered -->
        </div><!-- end of .caption -->
      </div><!-- end of .hidden -->
    

    Your code should look like this:

    <div class="reveal">
      <img src="{{ featured.featured_image.src | img_url: '450x450' }}" alt="{{ featured.featured_image.alt | escape }}"><!-- this is your original image tag -->
      <div class="hidden">
        <img src="{{ product.images.last | img_url: '450x450' }}" alt="{{ product.images.last.alt | escape }}" />
        <div class="caption">
          <div class="centered">
            YOUR TEXT
          </div><!-- end of .centered -->
        </div><!-- end of .caption -->
      </div><!-- end of .hidden -->
    </div><!-- end of .reveal -->
    
  2. Click Save.

In the section "Edit the code for your product images", what do you do if you don’t have any files in the Snippets directory, for product-grid-item.liquid, product-card.liquid, product-card-grid.liquid, or product-loop.liquid?