select variant by clicking the image

Automatic Select Variant Option Using Product Images

How to see the code

1. Please log in/create an account first. This is to ensure that all purchases are connected to an account and can be viewed on different devices.

2. Purchase the code using the "purchase box" on the specific page of the desired code.

3. After the purchase, please refresh the page.

Compatibility: Dawn 2.5 version and above, and any Shopify 2.0 FREE themes

Someone asked to do a variant select using the thumbnail images. There are lot of video tutorials available but none of them work with Dawn theme or in Shopify 2.0 themes. The answer is not always an APP either. This can be done with a simple snippet code. I also added a feature that will select the option using multiple variant images. I used the image alt to do the job. It is tedious work to assign alt to multiple images, but if you already have a CSV file for the product, this can easily be done.

Check this demo product. Password: Made4uo

NOTE: Before you start, makes sure you have the "Hide other variants’ media after selecting a variant" unclick from your theme editor and use "thumbnail carousel" or "thumbnails."  You also have to make sure tat you assign an image on every variants options. 

We cannot have one image with multiple tags, so you cannot assign an image to multiple variant options but you can assign several images in one option.

This will not work if you have an APP that changes the product options.

For product that has several options, always put the variant to select as FIRST in the variant selection. In this way, the code does not need to figure out what is the variant option it has to respond to, since an image can be use several times in the options. 

What you are buying:

  • Select the product option using multiple thumbnail images
  • Works with either dropdown or radio buttons variant picker
  • Updates the product information, eg. price
  • Well written code with NO external library being use

What makes our code better:

  • We do not use external libraries, with that being said, our code will have no to minimal effect to your website's speed performance
  • We do not leave or add codes use to advertise for our website
  • Our code is mobile friendly

Any issues related to the code will be fix with no additional cost, excluding code customization requests. Simply contact us with "Chat with us." We are just a button away. 

To start:

1. We need to go to our Admins store and open the code editor. Click Online store > Themes > Actions > Edit code.

2. We need to open the Asset folder and look for media-gallery.js. If you don't have this file, this code will not work for you. Open the media-galley.js and find the code below. 

 mediaToSwitch.querySelector('button').addEventListener('click', this.setActiveMedia.bind(this,, false));  

Then insert the code below it. Please refer to the image for placement



3. Let's start in a new line, then add the code below, after the closing curly bracket. Please refer to the image for placement. Then click SAVE.



Code Placement:

code placement


4. Next, we need to add the code in the media-gallery. Please check which version of Dawn do you have.

For Dawn below 8.0 version, open the Section folder and open the main-product.liquid. Inside the file, search for "<media-gallery." Below the media-gallery, add the code below.

For Dawn abow 8.0 version, open the product-media-gallery.liquid under the Asset folder, add the code below after the ">", please refer to image below

media gallery


Continue below if you want multiple image connected to the variant option. Otherwise, just SAVE the main-product.liquid or product-media-gallery.liquid and that is it. 

5. If you have multiple images in a variant option, you need to add the code below next to the "<media-gallery." Please check the image for placement. Click SAVE.



For Dawn below 8.0 version, you have to open the main-product.liquid under the Asset folder:



For Dawn below 8.0 version, you have to open the product-media-gallery.liquid

media gallery multiple images


6. This is only if you have multiple images associated to the variant option. Go to your Admin screen and click "Products", click the product, then under the Media section. Click on the images and assign the media alt the same with the variant option. Please check the image for more information. Make sure to click SAVE.

Image alt insertion


Step 3 will open the window below. Add the image alt the same as the option. E.g. Option is "White", add a media alt "White." This is case sensitive. 

Image alt text


NOTE: If you don't assign a media alt, this image will not be use to select the variant option. 

That's it (",)


Updated 03/14/23. Added the instructions to add in Dawn 8.0 version

Back to blog


Hi @Jasmin,

I understand your concern. I hope you read the use of alt tag explained in this page prior to purchase (images provided as well). Unfortunately, to keep the code still a non-developer friendly, we need to utilize the alt tag to call from the backend. We can however add some code to show different tag for image and different tag for SEO. Another way is to upload the images as a variant metafield but this will require more work. You can contact me for this issue using Chat with us.


Hey there, I purchased your code snippet and it is great in it’s own right! However, my concern is that it is using alt tag which should be reserved for SEO. Do you have a code snippet that uses that image linked to the variant?

Thanks in advance


Leave a comment