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:
To add a hover effect, you will need to add some CSS code to your theme's stylesheet:
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.
To edit the code for your product images:
product-grid-item.liquid
.product-grid-item.liquid
file, then look for one of the following:<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 }}">
img
tag, paste the following code:<div class="reveal">
img
tag, paste the following code:</div>
<div class="reveal"> <img src="{{ featured.featured_image.src | img_url: '450x450' }}" alt="{{ featured.featured_image.alt | escape }}"> </div>
img
tag and above the closing </div>
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.
img
tag and above the closing </div>
tag, paste the following code:<img class="hidden" src="{{ product.images.last | img_url: '450x450' }}" alt="{{ product.images.last.alt | escape }}" />
<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>
img
tag and above the closing </div>
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 -->.
img
tag and above the closing </div>
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 -->
<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 -->
Click here to view a demo store that has product images with a hover effect.
TyW | Online Community Manager @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Hi TyW,
Thanks for the code. I'm fairly new to shopify and looking to apply the hover effect on my debut theme store.
It seems that the images have been doubled.
May I ask for advise on this and whether there is any solution for it? The images on the first row does not have the hover effect, while the second row does.
Looking forward to your reply.
Thanks in advance!
Hi Tyw
Thanks for the tutorial.
Do you think a similar approach could be applied to add a text box hover on a non-product image?
Would you be so kind to provide a way forward that I can try to add a box hover with text over regular images on my homepage? Or even pointing me in the right direction would be great too!
I am using Brooklyn.
Thanks
Josè Luis
Hi TyW,
Thanks for your detail introduction on code.
I have followed them in my Minimal Theme and seccessed to set up hover effect on my product collection page.
But meanwhile the other negative result is all the image on product collection page became fade and hardly visible .
Could you kindly help me to check what is wrong?
I have followed this tutorial exactly and nothing happens. This is my site.
Has anyone else run into the hover effect not working for them? I'm using Debut theme.
Has anyone else run into the hover effect not working for them? I'm using Debut theme.
Hey saknight19 – I'm in the same boat. Check this video out for Debut theme solution.
It works but only on the first page of 20 products... how can I make it work if I have more pages on a collection because of 20+ products?
User | Count |
---|---|
418 | |
209 | |
144 | |
53 | |
42 |