How Can I Add Image Swatches to the Dawn Theme?

Topic summary

A user seeks to add image swatches for product color variants in Shopify’s Dawn theme without using external apps. They want a lightweight, code-based solution but struggle to find clear instructions.

Solution Provided:
Another user offers a detailed walkthrough involving:

  • Assigning variant images in Shopify Admin
  • Modifying product-variant-picker.liquid to render custom image swatches for the “Color” option
  • Adding CSS to base.css for swatch styling (40x40px images with selected state borders)
  • Including JavaScript to trigger variant selection changes when swatches are clicked

Implementation Challenges:
The original poster successfully adds the visual swatches but encounters a critical issue: clicking the image swatches doesn’t actually change the selected variant. The helper diagnoses this as missing JavaScript event triggers—Dawn’s <variant-selects> component needs manual change events dispatched on the custom radio inputs.

Current Status:
Despite adding the recommended JavaScript snippet and restructuring the label/input pairing, the variant switching still doesn’t work. The conversation remains unresolved, with the user awaiting further troubleshooting. An alternative video tutorial is suggested but rejected as it requires re-registering all products from scratch.

Summarized with AI on October 28. AI used: claude-sonnet-4-5-20250929.

Hi everyone, I hope you’re doing well!

I’m using the Dawn theme on Shopify and I would like to add image swatches for product variants (such as colour options), without using any external apps, to keep my store lightweight. I’ve searched for working code and tutorials, but I haven’t found anything clear or helpful. I’m looking for a working code snippet and precise instructions on where exactly to place it within Shopify’s code editor.

Can anyone help me with this or point me in the right direction? I’d really appreciate it!

1 Like

Hello @vhboy To add image swatches for color variants in the Dawn theme on Shopify (without using apps), you’ll need to customize the main-product.liquid, product-variant-picker.liquid, and global.js files. I’ll walk you through the full process to achieve this cleanly.

What You’ll Achieve:
. Replace the default color variant dropdown or pills with clickable image swatches.

. Keep it lightweight, without apps.

. Show selected state clearly.

Prerequisites:
. You’re using Dawn 9.0.0+ (let me know if your version is older).

. Your product variants have images assigned per color.

Step-by-Step Instructions:

  1. Assign Images to Each Variant
    In your Shopify Admin:

. Go to Products > [Your Product].

. Scroll to Variants, click each one, and upload an image that represents the color.

  1. Edit main-product.liquid
    File path: Sections/main-product.liquid

Look for this block (or similar):

{% render 'product-variant-picker', ... %}

It should already be rendering the picker, so no changes needed here unless it’s missing.

Modify product-variant-picker.liquid
File path: Snippets/product-variant-picker.liquid

Replace the contents only for the color option with image swatches.

Find this loop:

{% for option in product.options_with_values %}

And inside it, look for:

{% if option.name == 'Color' %}

If it doesn’t exist, wrap it yourself like this:

Replace or Insert this inside the loop:

{% if option.name == 'Color' %}
  
{% else %}
  {% render 'product-variant-options', product: product, option: option, product_form_id: product_form_id %}
{% endif %}

This creates image swatches instead of default text/pills for Color.

  1. Add CSS for Swatches
    File path: Assets/base.css or Assets/component-product.css

Scroll to the bottom and add this:

.swatch-container {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.swatch-label {
  position: relative;
  cursor: pointer;
  border: 2px solid transparent;
  padding: 2px;
  border-radius: 4px;
}

.swatch-label input[type="radio"] {
  display: none;
}

.swatch-label .swatch-image {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.swatch-label input[type="radio"]:checked + .swatch-image {
  border: 2px solid #000;
}

Done! Test It Out:

  1. Visit a product page with color variants.

  2. Swatches should appear.

  3. Selecting a swatch should change the product image and update the variant selection.

Would you like me to help add hover titles, color names under images, or support for mobile styling

plz let me know

Thank you :blush:

1 Like

Hello @goldi07 , hope you’re doing well. Thank you for helping me out.

I have a few questions, if you don’t mind clearing them up for me:

I couldn’t find where to place the code in product-variant-picker.liquid. I don’t really understand much about loops and things like that — would it be okay if I send you my full code so you can add it for me? Or perhaps you could tell me exactly which line to insert the code on, if that’s not too much trouble.

{% comment %}
  Renders product variant-picker

  Accepts:
  - product: {Object} product object.
  - block: {Object} passing the block information.
  - product_form_id: {String} Id of the product form to which the variant picker is associated.
  Usage:
  {% render 'product-variant-picker', product: product, block: block, product_form_id: product_form_id %}
{% endcomment %}
{%- unless product.has_only_default_variant -%}
  
{%- endunless -%}

[email removed]

1 Like

yes, it helps a lot to see your actual product-variant-picker.liquid snippet. I’ll guide you through an exact modification so you can add image swatches for the Color option only, while keeping the other options as they are (dropdowns, buttons, etc.).

Where to Insert the Code
We’ll be modifying just one part inside your existing loop:

{%- for option in product.options_with_values -%}

That loop is already rendering different picker types (swatch, button, dropdown) based on picker_type.

We’ll now intercept that flow for just the Color option and render our custom image swatch block instead.

Step-by-Step Code Insert

  1. Inside your loop, just after this line:

Add this conditional right after the loop starts:

{%- if option.name == 'Color' -%}
  
{%- else -%}
  1. Then, scroll down and find this line (which closes your current picker rendering):
{%- endif -%}
  1. Just after that, add:
{%- endif -%}

This closes your custom if option.name == ‘Color’ logic cleanly.

Your Updated Flow Will Look Like:

{%- for option in product.options_with_values -%}

  {%- if option.name == 'Color' -%}
    
  {%- else -%}
    
    {%- if picker_type == 'swatch' -%}
      ...
    {%- elsif picker_type == 'button' -%}
      ...
    {%- else -%}
      ...
    {%- endif -%}
  {%- endif -%}

{%- endfor -%}

CSS Reminder
In your Assets/base.css (or component-product.css), don’t forget to add:

.swatch-container {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.swatch-label {
  position: relative;
  cursor: pointer;
  border: 2px solid transparent;
  padding: 2px;
  border-radius: 4px;
}

.swatch-label input[type="radio"] {
  display: none;
}

.swatch-image {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.swatch-label input[type="radio"]:checked + .swatch-image {
  border: 2px solid #000;
}

try this and let me if this work i also add a sacreenshot

thank you :blush:

1 Like

I managed to add it successfully, but when I click on the variant, which is now an image, it doesn’t switch. It’s only possible to view the colour without being able to change it. Do you know how to fix this? I’ll send you my code so you can see how it turned out.

{% comment %}
  Renders product variant-picker

  Accepts:
  - product: {Object} product object.
  - block: {Object} passing the block information.
  - product_form_id: {String} Id of the product form to which the variant picker is associated.
  Usage:
  {% render 'product-variant-picker', product: product, block: block, product_form_id: product_form_id %}
{% endcomment %}
{%- unless product.has_only_default_variant -%}
  
{%- endunless -%}

image.png

1 Like

hey @vhboy Thanks for sharing your code, — you’re super close! The issue is that while your custom image swatches are rendering perfectly, they’re missing the JavaScript trigger that tells Shopify’s component to update the selected variant when you change the radio button.

Here’s what’s happening:

. The is being rendered correctly.

. But Shopify’s built-in variant-selects.js component listens for change events on the

1 Like

Hi my friend, how are you? I hope you’re having an excellent day. First of all, I want to thank you for your patience and help—it’s really been a huge support!

I managed to do everything you mentioned, but when I click on the image, it still doesn’t change the variant. I’d like to know what’s missing or what I might have done wrong. I’ll leave my code below.

{% comment %}
  Renders product variant-picker

  Accepts:
  - product: {Object} product object.
  - block: {Object} passing the block information.
  - product_form_id: {String} Id of the product form to which the variant picker is associated.
  Usage:
  {% render 'product-variant-picker', product: product, block: block, product_form_id: product_form_id %}
{% endcomment %}
{%- unless product.has_only_default_variant -%}
  
  
{%- endunless -%}

Hi @vhboy ,

Please refer the below video to see how you can activate color swatch in DAWN theme.

I can’t do what this video suggests with existing products — I’d have to register everything from scratch, and that wasn’t what I was looking for. But I really appreciate your help, mate. @gr_trading