1. Go to Themes -> Edit code -> Config -> settings_schema.json
Paste below code in line: 10. Or you can follow the video instructions to exactly compare the code next to it.
{
"name": "Color Swatches by MrDigitals",
"settings": [
{
"type": "paragraph",
"content": "Support MrDigitals by [Subscribing our Channel](https:\/\/youtube.com\/@amazinglearning?sub_confirmation=1)"
},
{
"type": "text",
"id": "optionName",
"label": "Swatch option name",
"default": "Color",
"info": "Make sure capitalization is same as variant for e.g Color not color "
},
{
"type": "paragraph",
"content": "If your store is in different languages, type in all the different words and separate them with commas. For example: Color, Colour, Couleur"
},
{
"type": "select",
"id": "swatchType",
"label": "Swatch type",
"options": [
{
"value": "color",
"label": "Color"
},
{
"value": "variantImage",
"label": "Variant image"
}
],
"default": "color"
},
{
"type": "textarea",
"id": "swatchColors",
"label": "Colors",
"placeholder": "Red:#ff0000\nGreen:#00ff00\nBlue:#0000ff",
"default": "Black:#000000\nWhite:#f5f5f5\nBlue:#005eff\nRed:#c9002c\nPink:#ffd5e6\nBrown:#a2896b\nOlive:#808000\nGreenRed:#008000#c9002c\nGreenRedBlue:#008000#c9002c#005eff",
"info": "One rule per line. Example: Blue:#005eff\n2 Color Swatch Example: GreenRed:#008000#c9002c\n3 Color Swatch Example: GreenRedBlue:#008000#c9002c#005eff"
},
{
"type": "paragraph",
"content": "You can also add [image files](\/admin\/content\/files?selectedView=all&media_type=Image) instead of using colors, in lowercase with spaces replaced by hyphens. Example: Green kaki: green-kaki.png"
},
{
"type": "select",
"id": "swatchStyle",
"label": "Swatch style",
"options": [
{
"value": "round",
"label": "Round"
},
{
"value": "square",
"label": "Square"
},
{
"value":"square-round-corners",
"label":"Square round corners"
},
{
"value": "portrait",
"label": "Portrait"
}
],
"default": "round",
"info":"Portrait mode is only available for the variant image type."
},
{
"type": "range",
"id": "swatchSize",
"min": 20,
"max": 120,
"step": 2,
"unit": "px",
"label": "Swatch size",
"default": 42
}
]
},2. Go to Snippets -> product-variant-picker.liquid
Find below lines of code:
<fieldset class="js product-form__input product-form__input--pill">
<legend class="form__label">{{ option.name }}</legend>
{% render 'product-variant-options',
product: product,
option: option,
block: block,
picker_type: picker_type
%}
</fieldset>Replace above lines of code with:
<fieldset class="js product-form__input product-form__input--pill">
{%- liquid
assign optionNames = settings.optionName | split:","
assign useColor = false
for optionColor in optionNames
if optionColor == option.name
assign useColor = true
break
endif
endfor
-%}
{%- if useColor -%}
<legend class="form__label ">{{ option.name }}:<span id="selected-{{ option.name }}"> {{ option.selected_value }}</span></legend>
{% render 'color-option', product: product, option: option, block: block %}
{%- else -%}
<legend class="form__label">{{ option.name }}</legend>
{% render 'product-variant-options', product: product, option: option, block: block, picker_type: picker_type %}
{%- endif -%}
</fieldset>3. Go to Snippets and create a new snippet and name it ‘color-option’ and paste below code.
Replace above lines of code with:
{% comment %}
Renders product variant options
Accepts:
- product: {Object} product object.
- option: {Object} current product_option object.
- block: {Object} block object.
Usage:
{% render 'product-variant-options',
product: product,
option: option,
block: block
%}
{% endcomment %}
{%- liquid
assign variants_available_arr = product.variants | map: 'available'
assign variants_option1_arr = product.variants | map: 'option1'
assign variants_option2_arr = product.variants | map: 'option2'
assign variants_option3_arr = product.variants | map: 'option3'
assign product_form_id = 'product-form-' | append: section.id
assign swatchType = settings.swatchType
assign swatchStyle = settings.swatchStyle
assign swatchSize = settings.swatchSize
assign swatchColors = settings.swatchColors | newline_to_br | split: '<br />'
-%}
<style>
.product-form__input input[type='radio'] + label.color-swatch,
.product-form__input input[type='radio'] + label.color-swatch:after,
.product-form__input input[type='radio'] + label.color-swatch:before{
border-radius: 0;
}
.product-form__input input[type='radio'] + label.color-swatch.round,
.product-form__input input[type='radio'] + label.color-swatch.round:after,
.product-form__input input[type='radio'] + label.color-swatch.round:before{
border-radius: 100%;
}
.product-form__input input[type='radio'] + label.color-swatch.round-corners,
.product-form__input input[type='radio'] + label.color-swatch.round-corners:after,
.product-form__input input[type='radio'] + label.color-swatch.round-corners:before{
border-radius: 5px;
}
.product-form__input input[type='radio'] + label.color-swatch{
border:1px rgb(214,214,214) solid;
width: {{swatchSize}}px;
height: {{swatchSize}}px;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
margin-right: 9px;
}
.product-form__input input[type='radio'] + label.color-swatch:before{
content: "";
position: absolute;
top: -1px;
left: -1px;
width: calc(100% + 2px);
height: calc(100% + 2px);
border: 1px rgb(214,214,214) solid;
z-index: 0;
}
.product-form__input input[type='radio'] + label.color-swatch:after{
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
{%- if settings.dark or swatchType == "variantImage" -%}
border: none;
{%- else -%}
border: 3px rgb(255 255 255) solid;
{%- endif -%}
}
.product-form__input input[type='radio'] + label.color-swatch:hover:before{
border: 1px rgb(125 124 124) solid;
}
.product-form__input input[type='radio']:checked + label.color-swatch:before{
{%- if settings.dark -%}
box-shadow: 0 0 0 2px rgb(var(--color-foreground));
{%- else -%}
box-shadow: 0 0 0 1px rgb(var(--color-foreground));
{%- endif -%}
border-color:rgb(var(--color-foreground));
}
.product-form__input input[type='radio'] + label.color-swatch.variant-swatch{
background-color:white;
{%- if swatchStyle == "portrait" -%}
height: calc({{swatchSize}}px/ 0.66);
{%- endif -%}
}
</style>
{%- for value in option.values -%}
{%- liquid
assign option_disabled = true
for option1_name in variants_option1_arr
case option.position
when 1
if variants_option1_arr[forloop.index0] == value and variants_available_arr[forloop.index0]
assign option_disabled = false
endif
when 2
if option1_name == product.selected_or_first_available_variant.option1 and variants_option2_arr[forloop.index0] == value and variants_available_arr[forloop.index0]
assign option_disabled = false
endif
when 3
if option1_name == product.selected_or_first_available_variant.option1 and variants_option2_arr[forloop.index0] == product.selected_or_first_available_variant.option2 and variants_option3_arr[forloop.index0] == value and variants_available_arr[forloop.index0]
assign option_disabled = false
endif
endcase
endfor
-%}
{%- if block.settings.picker_type == 'button' -%}
<input
type="radio"
id="{{ section.id }}-{{ option.position }}-{{ forloop.index0 }}"
name="{{ option.name }}"
value="{{ value | escape }}"
form="{{ product_form_id }}"
{% if option.selected_value == value %}
checked
{% endif %}
{% if option_disabled %}
class="disabled"
{% endif %}
>
{%- if swatchType == "variantImage" -%}
<label
data-{{ option.name }}="{{value}}"
style="background-image:url(
{%- liquid
assign optionIndex = option.position | minus: 1
for variant in product.variants
if variant.options[optionIndex] == value
assign swatchSizePortrait = swatchSize | times: 2
echo variant.image | image_url: width: swatchSizePortrait
break
endif
endfor
-%}
);"
class="color-swatch variant-swatch {% case swatchStyle %}{% when "round" %}round{% when "square-round-corners" %}round-corners{% endcase %}"
for="{{ section.id }}-{{ option.position }}-{{ forloop.index0 }}">
<span class="visually-hidden">{{ 'products.product.variant_sold_out_or_unavailable' | t }}</span>
</label>
{%- else -%}
{%- liquid
for colorData in swatchColors
assign colorDataArr = colorData | split:":"
assign ruleName = colorDataArr[0] | strip
if value == ruleName
assign colorCodes = colorDataArr[1] | strip | split :"#"
assign colorNumber = 0 | plus: colorCodes.size
break
endif
endfor
-%}
<label
data-{{ option.name }}="{{value}}"
style="
{%- case colorNumber -%}
{%- when 2 -%}
background-color: #{{ colorCodes[1] }}
{%- when 3 -%}
background: linear-gradient(135deg, #{{ colorCodes[1] }} 50%, #{{ colorCodes[2] }} 50%);
{%- when 4 -%}
background: linear-gradient(to right,#{{ colorCodes[1] }} 33%,#{{ colorCodes[2] }} 33%,#{{ colorCodes[2] }} 66%, #{{ colorCodes[3] }} 66%);
{%- else -%}
background-image:url({{ colorCodes[0] | downcase | replace: ' ', '-' | file_img_url }})
{%- endcase -%}
;"class="color-swatch {% case swatchStyle %}{% when "round" %}round{% when "square-round-corners" %}round-corners{% endcase %}"
for="{{ section.id }}-{{ option.position }}-{{ forloop.index0 }}">
<span class="visually-hidden">{{ 'products.product.variant_sold_out_or_unavailable' | t }}</span>
</label>
{%- assign colorCodes = "" -%}
{%- endif -%}
{%- elsif block.settings.picker_type == 'dropdown' -%}
<option
value="{{ value | escape }}"
{% if option.selected_value == value %}
selected="selected"
{% endif %}
>
{% if option_disabled -%}
{{- 'products.product.value_unavailable' | t: option_value: value -}}
{%- else -%}
{{- value -}}
{%- endif %}
</option>
{%- endif -%}
{%- endfor -%}
<script>
document.querySelectorAll('input+label[data-{{ option.name | downcase }}]').forEach(el=>{
el.addEventListener('click',()=>{
document.querySelector('#selected-{{option.name}}').textContent = " "+el.getAttribute('data-{{ option.name | downcase }}')
})
})
</script>Add Color Swatches in Shopify Product Pages – All Free Themes
If you run a Shopify store that sells clothing, shoes, accessories, or other products with different color options, adding color swatches to your product pages can make shopping much easier for your customers.
Instead of selecting colors from a traditional dropdown menu, visitors can click small colored circles or squares to choose the option they want. This creates a cleaner shopping experience, makes product variations easier to understand, and gives your store a more professional appearance.
The good news is that Shopify offers native color swatch functionality, so you may not need to install a paid app. However, the exact setup depends on whether your free theme and its current version support this feature.
What Are Color Swatches in Shopify?
Color swatches are small visual buttons that represent the available colors of a product. For example, if you sell a T-shirt in black, white, blue, and red, customers can see those colors directly on the product page.
When a customer selects a swatch, the product variant can update to the selected color. If your product images are configured correctly, the displayed product image can also change to show the selected variation.
Unlike traditional dropdown menus, color swatches make the available options easier to recognize at a glance.
Why Should You Add Color Swatches to Your Shopify Store?
A good product page should make it easy for customers to understand what they are buying. Color swatches help achieve this by turning product options into visual choices.
Here are some important benefits:
- Better shopping experience: Customers can see available colors without opening a dropdown menu.
- Professional appearance: Visual options can make product pages look cleaner and more modern.
- Easier product selection: Visitors can compare colors more quickly.
- Improved product presentation: Customers can connect color choices with the correct product images.
- Less confusion: Visual options help shoppers understand the differences between product variations.
These small improvements can make your product pages more convenient and attractive.
How to Add Color Swatches Using Shopify’s Free Features
Shopify supports native color swatches through compatible themes and product variant color information. You can use this functionality without purchasing a separate swatch app.
The general setup involves preparing your product variants, connecting the appropriate color information, and enabling swatches in your theme editor.
1. Create Color Variants for Your Products
First, open your Shopify admin and navigate to the product you want to update.
Under the product’s options, make sure you have a color option, such as Black, White, Blue, or Red. Each color should be configured as a product variant when customers can purchase that specific color.
Use clear and consistent color names so customers can easily understand the available choices.
2. Connect Color Category Metafields
For Shopify’s native swatches, simply naming your variant option “Color” may not be enough.
You may need to assign an appropriate product category and connect each color variant to the matching color entry in Shopify’s category metafields.
These entries can contain color information, such as a specific color value, allowing compatible themes to display the correct swatch.
You can also customize color entries to better represent your products and branding.
3. Open Your Shopify Theme Editor
Once your product variants are ready, navigate to:
Shopify Admin → Online Store → Themes → Customize
Open your product page template and locate the Variant Picker block.
If your theme supports native swatches, you should be able to choose an available swatch display style through the block’s settings.
Depending on the theme, you may have options for circular swatches, square swatches, or other variant selection styles.
4. Enable and Customize the Swatches
Choose the swatch option if it is available in your theme settings. Review the product page preview to make sure the colors appear correctly.
Pay attention to the selected state, spacing, and appearance of unavailable variants. Your swatches should be easy to recognize and comfortable to click, especially on mobile devices.
Finally, save your changes and preview the live product page.
Does This Work With All Free Shopify Themes?
This is an important point to understand.
Shopify offers several free themes, but not every free theme or older theme version automatically includes native color swatch settings.
For example, newer versions of Dawn support Shopify’s native swatch functionality. Other themes may have different settings or require additional customization.
If you cannot find a swatch option in your theme editor, it does not necessarily mean you have configured your products incorrectly. Your theme may simply lack the required functionality.
You have three practical choices:
- Use a compatible free theme: Choose a Shopify free theme that supports native swatches.
- Customize your existing theme: A developer can add swatch functionality through Shopify Liquid, CSS, and JavaScript.
- Use a swatch app: Some Shopify apps offer color swatches without requiring manual theme development. Check their free-plan limitations before installing.
You do not need to pay for a theme just to have color swatches, but the amount of work required depends on your current theme.
Common Problems When Adding Color Swatches
Sometimes swatches do not appear even after configuring product variants. Here are a few things worth checking.
Incorrect option names: Some themes recognize only specific names, such as Color or Colour. Check the theme’s settings if you use a different name.
Missing color information: Native swatches may require color category metafields to be connected to the variants.
Unsupported theme version: An older version of a free theme might not include the native swatch functionality.
Incorrect product images: Make sure each color variant is associated with the appropriate product image when you want the main image to change after selection.
Changes not saved: Always save your theme editor changes and preview the product page again.
Best Practices for Professional Color Swatches
When adding swatches, focus on making them easy to understand and use.
Choose colors that closely represent the actual products. For patterned products, consider using appropriate images rather than relying on a single solid color. Make the selected option visually clear and ensure that customers can identify unavailable variants.
It is also important to test the swatches on mobile devices. Many Shopify customers browse stores using their phones, so the options should be large enough to select comfortably.
Finally, keep your product images consistent. When customers select a different color, the corresponding product image should accurately represent that choice.
Conclusion
Adding color swatches to Shopify product pages is a simple way to improve product presentation and make shopping more convenient. Shopify’s native functionality allows compatible themes to display visual color options without requiring a paid app.
However, the phrase “all free themes” needs a little clarification: native swatch support depends on the theme and its version. If your current theme does not include this feature, you may need a theme customization or a suitable app.
With properly configured product variants, accurate color information, and a responsive design, you can create cleaner product pages and give customers a better shopping experience without necessarily spending extra money.
Ready to become a better coder? Don’t miss this tutorial! Animation Direction in CSS
