Z O B A E R

Loading

Free code library No sign-up

Shopify Code Snippets: Copy-Paste Code for Dawn and Horizon

Search tested CSS and Liquid code for Dawn and Horizon, see exactly where to paste each snippet, and copy it in one click. Every card links to its full guide.

Shopify Select Partner

fiverr. Vetted Pro · Top Rated

DKNRJ★★★★★ 4.9from 1,350+ client reviews · 5,000+ clients
Theme
Type

23 snippets

All 23 snippets shown. CSS goes in Theme settings > Custom CSS; Liquid needs a Custom Liquid block or Edit code.

DawnHorizonCSS

Hide the Sale badge but keep Sold out

Hides only the Sale badge, so the crossed-out price and the Sold out badge stay. Copy the version for your theme.

Dawn

Where to paste: Online Store > Themes > Edit theme > Theme settings (gear icon) > Custom CSS. Paste, then Save.

/* Dawn: hide the Sale badge, keep Sold out */
.card-wrapper:has(.price--on-sale:not(.price--sold-out)) .card__badge {
  display: none;
}
.price--on-sale.price--show-badge .price__badge-sale {
  display: none;
}
Horizon

Where to paste: Online Store > Themes > Edit theme > Theme settings (gear icon) > Custom CSS. Paste, then Save.

/* Horizon: hide the Sale badge, keep Sold out */
.product-badges:has(.color-custom-badge-sale) {
  display: none;
}
Full guide: Shopify Sale Badge: Change Text, Color, % Off or Remove
DawnHorizonLiquid

Show "% off" on the sale badge

Shows the real saving, so $40.00 down to $29.99 reads "25% off", and falls back to your normal sale text when a variant isn't on sale. Duplicate your theme first, and redo the edit if a theme update replaces the file.

Dawn: product cards

Where to paste: Edit code > snippets/card-product.liquid. Search products.product.on_sale (it appears twice) and replace each of those two lines with this. Save.

{%- liquid
  assign sale_variant = card_product.selected_or_first_available_variant
  if sale_variant.compare_at_price > sale_variant.price
    assign percent_off = sale_variant.compare_at_price | minus: sale_variant.price | times: 100.0 | divided_by: sale_variant.compare_at_price | round
    echo percent_off | append: '% off'
  else
    echo 'products.product.on_sale' | t
  endif
-%}
Dawn: product page

Where to paste: Edit code > snippets/price.liquid. Search products.product.on_sale (it appears once) and replace that line with this. Save.

{%- if compare_at_price > price -%}
  {{- compare_at_price | minus: price | times: 100.0 | divided_by: compare_at_price | round -}}% off
{%- else -%}
  {{- 'products.product.on_sale' | t -}}
{%- endif -%}
Horizon: product cards

Where to paste: Edit code > blocks/_product-card-gallery.liquid. Search content.product_badge_sale and replace that line with this. Save.

{%- liquid
  assign sale_variant = product.selected_or_first_available_variant
  if sale_variant.compare_at_price > sale_variant.price
    assign percent_off = sale_variant.compare_at_price | minus: sale_variant.price | times: 100.0 | divided_by: sale_variant.compare_at_price | round
    echo percent_off | append: '% off'
  else
    echo 'content.product_badge_sale' | t
  endif
-%}
Full guide: Shopify Sale Badge: Change Text, Color, % Off or Remove
DawnHorizonCSS

Hide the quantity selector in the cart and cart drawer

Hides the quantity box in cart lines only, so the product page box and the remove button stay. Dawn's second rule hides the Quantity column heading but keeps its space.

Dawn

Where to paste: Online Store > Themes > Edit theme > Theme settings (gear icon) > Custom CSS. Paste, then Save.

/* Dawn: hide quantity in the cart page and cart drawer */
quantity-input.cart-quantity {
  display: none;
}
.cart-items__heading--quantity {
  visibility: hidden;
}
Horizon

Where to paste: Online Store > Themes > Edit theme > Theme settings (gear icon) > Custom CSS. Paste, then Save.

/* Horizon: hide quantity in the cart page and cart drawer */
.cart-items__quantity .quantity-selector-wrapper {
  display: none;
}
Full guide: Remove the Quantity Selector in Shopify
DawnHorizonLiquidJavaScript

Free shipping progress bar in the cart

Shows "You're $17.50 away from free shipping" with a bar that fills up, and hides when the cart is empty. In Step 1, change USD and 50 to your currency and your free shipping minimum.

Step 1: the snippet file (both themes)

Where to paste: Duplicate your theme, then Edit code > snippets folder > add a new file named free-shipping-bar.liquid. Paste this and Save.

{% comment %}
  Free shipping bar (zobaer.me). Set your free shipping minimum below.
  Use the same amount as your free shipping rate in Settings > Shipping and delivery.
{% endcomment %}
{%- liquid
  assign threshold = 0
  case cart.currency.iso_code
    when 'USD'
      assign threshold = 50
  endcase
  assign threshold_cents = threshold | times: 100
  assign remaining = threshold_cents | minus: cart.total_price
-%}
<div class="fs-bar-wrap">
  {%- if threshold > 0 and cart.item_count > 0 -%}
    {%- assign progress = cart.total_price | times: 100 | divided_by: threshold_cents | at_most: 100 -%}
    <div class="fs-bar">
      <p class="fs-bar__text">
        {%- if remaining > 0 -%}
          You're <strong>{{ remaining | money }}</strong> away from free shipping
        {%- else -%}
          Your order ships free!
        {%- endif -%}
      </p>
      <div class="fs-bar__track" role="progressbar" aria-label="Progress to free shipping" aria-valuemin="0" aria-valuemax="100" aria-valuenow="{{ progress }}">
        <span class="fs-bar__fill" style="width: {{ progress }}%"></span>
      </div>
    </div>
  {%- endif -%}
</div>
<style>
  .fs-bar { margin: 0 0 12px; text-align: center; }
  .fs-bar__text { margin: 0 0 6px; font-size: 0.9em; line-height: 1.4; }
  .fs-bar__track { height: 8px; border-radius: 8px; overflow: hidden; background: color-mix(in srgb, currentColor 15%, transparent); }
  .fs-bar__fill { display: block; height: 100%; border-radius: inherit; background: #2e7d32; transition: width 0.4s ease; }
</style>
Step 2, Dawn: show it in the cart

Where to paste: Cart drawer: snippets/cart-drawer.liquid, paste right under the line that starts with <div class="cart-drawer__footer". Cart page: sections/main-cart-footer.liquid, paste right under the line that starts with <div class="js-contents". For the drawer, set Theme settings > Cart > Type to Drawer.

{% render 'free-shipping-bar' %}
Step 2, Horizon: show it in the cart

Where to paste: snippets/cart-summary.liquid, paste right above the line <div class="cart-totals">. This one line covers the cart drawer and the cart page.

{% render 'free-shipping-bar' %}
Optional, Dawn: live update in a Custom Liquid section

Where to paste: Only if you put the render line in a Custom Liquid section on Dawn's cart page: paste this under the render line in the same Liquid code box. Inside the drawer and cart footer, the bar updates by itself.

<script>
  (() => {
    const section = document.currentScript.closest('.shopify-section');
    const id = section.id.replace('shopify-section-', '');
    document.addEventListener('DOMContentLoaded', () => {
      if (typeof subscribe !== 'function') return;
      subscribe(PUB_SUB_EVENTS.cartUpdate, async () => {
        const res = await fetch(window.location.pathname + '?section_id=' + id);
        const html = new DOMParser().parseFromString(await res.text(), 'text/html');
        const fresh = html.querySelector('.fs-bar-wrap');
        const wrap = section.querySelector('.fs-bar-wrap');
        if (fresh && wrap) wrap.innerHTML = fresh.innerHTML;
      });
    });
  })();
</script>
Full guide: Shopify Free Shipping Bar Without an App
DawnHorizonLiquid

Cart upsell: one add-on that matches the cart

Shows one "Add this to your order" card, picked from a custom.cart_upsell product metafield (Settings > Metafields and metaobjects > Products, type Product) with a store-wide fallback. Change gift-box on line 7 to your fallback product's handle.

The upsell code

Where to paste: Cart page, no files: open the Cart template in the theme editor. Dawn: Add section > Custom Liquid, drag it between Items and Subtotal. Horizon: Add block inside the Cart section > Custom Liquid. Paste into Liquid code. For the cart drawer instead: Edit code > snippets > add a file named cart-upsell.liquid and paste this.

{%- comment -%}
  Cart upsell (zobaer.me). Shows one add-on product in the cart.
  1. Each product can point to its add-on with a product metafield: custom.cart_upsell (type: Product).
  2. If no product in the cart has one, the store-wide fallback below is used.
{%- endcomment -%}
{%- liquid
  assign fallback_handle = 'gift-box'
  assign upsell = nil
  for item in cart.items
    assign pick = item.product.metafields.custom.cart_upsell.value
    if pick != blank and pick.available
      assign in_cart = cart.items | where: 'product_id', pick.id | size
      if in_cart == 0
        assign upsell = pick
        break
      endif
    endif
  endfor
  if upsell == nil and fallback_handle != blank
    assign pick = all_products[fallback_handle]
    if pick != blank and pick.available
      assign in_cart = cart.items | where: 'product_id', pick.id | size
      if in_cart == 0
        assign upsell = pick
      endif
    endif
  endif
-%}
{%- if cart.item_count > 0 and upsell -%}
  {%- assign v = upsell.selected_or_first_available_variant -%}
  <div class="cart-upsell">
    <p class="cart-upsell__title">Add this to your order</p>
    <div class="cart-upsell__card">
      {%- if upsell.featured_image -%}
        <img class="cart-upsell__img" src="{{ upsell.featured_image | image_url: width: 160 }}" alt="{{ upsell.title | escape }}" width="64" height="64" loading="lazy">
      {%- endif -%}
      <div class="cart-upsell__info">
        <a class="cart-upsell__name" href="{{ upsell.url }}">{{ upsell.title }}</a>
        <span class="cart-upsell__price">{{ v.price | money }}</span>
      </div>
      {%- if upsell.has_only_default_variant -%}
        <form action="{{ routes.cart_add_url }}" method="post">
          <input type="hidden" name="id" value="{{ v.id }}">
          <input type="hidden" name="quantity" value="1">
          <button type="submit" class="cart-upsell__btn">Add</button>
        </form>
      {%- else -%}
        <a class="cart-upsell__btn" href="{{ upsell.url }}">Choose</a>
      {%- endif -%}
    </div>
  </div>
  <style>
    .cart-upsell { margin: 0 0 16px; }
    .cart-upsell__title { margin: 0 0 8px; font-size: 0.9em; font-weight: 600; }
    .cart-upsell__card { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid rgba(128, 128, 128, 0.3); border-radius: 8px; }
    .cart-upsell__img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
    .cart-upsell__info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 0.9em; line-height: 1.3; }
    .cart-upsell__name { color: inherit; text-decoration: none; overflow-wrap: anywhere; }
    .cart-upsell__card form { margin: 0; flex-shrink: 0; }
    .cart-upsell__btn { display: inline-block; flex-shrink: 0; padding: 8px 16px; border: 1px solid currentColor; border-radius: 6px; background: transparent; color: inherit; font: inherit; font-size: 0.9em; text-decoration: none; cursor: pointer; }
  </style>
{%- endif -%}
Cart drawer, Dawn: render line

Where to paste: snippets/cart-drawer.liquid, paste right above <div class="drawer__footer">. Save.

{% render 'cart-upsell' %}
Cart drawer, Horizon: render line

Where to paste: snippets/cart-summary.liquid, paste right above <div class="cart-totals">. This covers the drawer and the cart page, so don't also add the Custom Liquid block or the card shows twice.

{% render 'cart-upsell' %}
Full guide: Shopify Upsell Without App
Any themeLiquid

Scrolling announcement bar on every page

A looping text bar that pauses on hover and stops for shoppers who reduce motion. Change the three messages, and hide the built-in Announcement bar so you don't show two.

Any theme with a Custom Liquid section

Where to paste: Online Store > Themes > Edit theme > Header area > Add section > Custom Liquid. Drag it above the Header section and paste into Liquid code. Dawn: set Top and Bottom padding to 0. Horizon: set Width to Full. Save.

{%- capture messages -%}
  <span>Free shipping on orders over $50</span>
  <span>30-day easy returns</span>
  <span><a href="/collections/all">New arrivals are here</a></span>
{%- endcapture -%}

<div class="ann-marquee" role="region" aria-label="Announcements">
  <div class="ann-marquee__track">
    <div class="ann-marquee__group">{{ messages }}</div>
    <div class="ann-marquee__group" aria-hidden="true" inert>{{ messages }}</div>
  </div>
</div>

<style>
  .ann-marquee {
    --ann-speed: 30s;
    overflow: hidden;
    background: #111111;
    color: #ffffff;
    font-size: 14px;
    line-height: 1.2;
    padding: 12px 0;
  }
  .ann-marquee__track {
    display: flex;
    width: max-content;
    animation: ann-scroll var(--ann-speed) linear infinite;
  }
  .ann-marquee:hover .ann-marquee__track,
  .ann-marquee:focus-within .ann-marquee__track {
    animation-play-state: paused;
  }
  .ann-marquee__group {
    display: flex;
    flex-shrink: 0;
    justify-content: space-around;
    gap: 48px;
    min-width: 100vw;
    padding-right: 48px;
  }
  .ann-marquee span { white-space: nowrap; }
  .ann-marquee a { color: inherit; }
  @keyframes ann-scroll {
    to { transform: translateX(-50%); }
  }
  @media (max-width: 749px) {
    .ann-marquee { font-size: 13px; --ann-speed: 20s; }
  }
  @media (prefers-reduced-motion: reduce) {
    .ann-marquee__track { animation: none; width: auto; }
    .ann-marquee__group { flex-shrink: 1; min-width: 0; flex-wrap: wrap; justify-content: center; gap: 8px 24px; padding: 0 16px; }
    .ann-marquee__group[aria-hidden] { display: none; }
  }
</style>
Full guide: Scrolling Announcement Bar in Shopify
DawnHorizonLiquid

Remove "Powered by Shopify" from the footer in code

Try the no-code way first: a space in Edit default theme content (Dawn) or the Copyright block checkbox (Horizon). Use this only when those fail, on a duplicate theme, because an update can bring the line back.

Dawn: delete this line

Where to paste: Edit code > sections/footer.liquid. Search powered_by_link and delete this whole line, tags included. Save.

<small class="copyright__content">{{ powered_by_link }}</small>
Horizon: delete these three lines

Where to paste: Edit code > blocks/footer-copyright.liquid. Delete these three lines. Save.

{%- if block_settings.show_powered_by -%}
  , {{ powered_by_link }}
{%- endif -%}
Full guide: Remove Powered by Shopify From Your Footer
DawnLiquid

Payment icons under Add to cart (Dawn)

Prints the logos of the payment methods your store accepts, using the same filter as Dawn's footer, and updates when you change providers. Horizon needs no code: add its Payment icons block under Details.

Dawn

Where to paste: Edit theme > Products > Default product > Product information > Add block > Custom Liquid. Paste into Liquid code, drag it under Buy buttons, Save.

{%- if shop.enabled_payment_types.size > 0 -%}
<ul class="trust-pay" role="list" aria-label="Payment methods">
  {%- for type in shop.enabled_payment_types -%}
    <li>{{ type | payment_type_svg_tag }}</li>
  {%- endfor -%}
</ul>
<style>
  .trust-pay { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 12px 0 0; padding: 0; }
  .trust-pay svg { width: 38px; height: 24px; }
</style>
{%- endif -%}
Full guide: Shopify Trust Badges: 3 Free Ways
DawnHTML

Trust badge image under Add to cart (Dawn)

For a wide designed badge, since Dawn's Product information section has no Image block. Upload the image in Content > Files, copy its link, and write alt text that says what the badge says.

Dawn

Where to paste: Edit theme > Products > Default product > Product information > Add block > Custom Liquid. Paste, replace the link and the alt text, Save.

<img src="PASTE-YOUR-FILE-LINK-HERE" alt="30-day money-back guarantee" width="300" height="80" loading="lazy" style="max-width: 100%; height: auto;">
Full guide: Shopify Trust Badges: 3 Free Ways
Any themeHTML

Size chart table template for a page

A ready size chart table in inches. The numbers are examples only, so replace them with your own product measurements.

Any theme

Where to paste: Online Store > Pages > Add page (title: Size chart). In the content editor click Show HTML (the <> icon), paste this, Save.

<p>Measurements are in inches. Between two sizes? Choose the larger one.</p>
<table>
  <tr><th>Size</th><th>Chest</th><th>Waist</th><th>Hips</th></tr>
  <tr><td>XS</td><td>31-32</td><td>24-25</td><td>34-35</td></tr>
  <tr><td>S</td><td>33-34</td><td>26-27</td><td>36-37</td></tr>
  <tr><td>M</td><td>35-36</td><td>28-29</td><td>38-39</td></tr>
  <tr><td>L</td><td>37-39</td><td>30-32</td><td>40-42</td></tr>
  <tr><td>XL</td><td>40-42</td><td>33-35</td><td>43-45</td></tr>
</table>
Full guide: How to Add a Size Chart in Shopify
DawnCSS

Hide the Shop Pay Installments banner (Dawn)

Hides the installments message on product pages and in the cart, but shoppers can still choose installments at checkout. Horizon has a Show Shop Pay payment options checkbox instead.

Dawn

Where to paste: Online Store > Themes > Edit theme > Theme settings (gear icon) > Custom CSS. Paste, then Save.

shopify-payment-terms {
  display: none !important;
}
Full guide: Remove Shop Pay Installments in Shopify
DawnCSS

Hide prices in one collection grid (Dawn)

Section CSS only affects that one section, so product pages keep their prices. Also set Quick add to None in the same section, because its pop-up shows the price.

Dawn

Where to paste: Edit theme > Collections > Default collection > Product grid section. Scroll to Custom CSS at the bottom of the section settings, paste, Save.

.price { display: none; }
Full guide: Shopify Hide Price: 5 Easy Ways
DawnCSS

Hide prices on every product card (Dawn)

Hides the price on collections, search, featured collections and related products. Product page prices stay visible.

Dawn

Where to paste: Online Store > Themes > Edit theme > Theme settings (gear icon) > Custom CSS. Paste, then Save.

.card-information .price { display: none; }
Full guide: Shopify Hide Price: 5 Easy Ways
DawnCSS

Hide the price of sold-out products (Dawn)

Hides the price of sold-out products on cards and of sold-out variants on product pages, while the Sold out badge stays. The price comes back when a shopper picks an in-stock variant.

Dawn

Where to paste: Online Store > Themes > Edit theme > Theme settings (gear icon) > Custom CSS. Paste, then Save.

.price--sold-out .price__container { display: none; }
Full guide: Shopify Hide Price: 5 Easy Ways
DawnHorizonLiquid

Hide prices by tag, login or stock (price.liquid)

Rule 1 shows "Contact for price" on products tagged hide-price, Rule 2 shows "Log in to see prices" to guests, and Rule 3 hides sold-out prices, so delete the rules you don't need. The editor preview isn't logged in, so it shows the login text everywhere.

Dawn: top of the file

Where to paste: Duplicate your theme. On the copy: Edit code > snippets/price.liquid. Paste directly above the line {%- unless target == null and placeholder == null -%}.

{%- liquid
  assign hide_price = false
  assign hide_price_text = 'Contact for price'

  # Rule 1: products with the tag hide-price
  if product.tags contains 'hide-price'
    assign hide_price = true
  endif

  # Rule 2: visitors who are not logged in
  if customer == blank
    assign hide_price = true
    assign hide_price_text = 'Log in to see prices'
  endif

  # Rule 3: sold-out products and variants
  if available == false and placeholder == blank
    assign hide_price = true
    assign hide_price_text = ''
  endif
-%}
{%- if hide_price -%}
  <div class="price price--hidden">
    <span class="price-item">{{ hide_price_text }}</span>
  </div>
{%- else -%}
Horizon: top of the file

Where to paste: Duplicate your theme. On the copy: Edit code > snippets/price.liquid. Paste directly above the line <div ref="priceContainer">.

{%- liquid
  assign hide_price = false
  assign hide_price_text = 'Contact for price'

  # Rule 1: products with the tag hide-price
  if product_resource.tags contains 'hide-price'
    assign hide_price = true
  endif

  # Rule 2: visitors who are not logged in
  if customer == blank
    assign hide_price = true
    assign hide_price_text = 'Log in to see prices'
  endif

  # Rule 3: sold-out products and variants
  if product_resource != blank and selected_variant.available == false
    assign hide_price = true
    assign hide_price_text = ''
  endif
-%}
{%- if hide_price -%}
  <div ref="priceContainer">
    <span class="price">{{ hide_price_text }}</span>
  </div>
{%- else -%}
Both themes: close the rule

Where to paste: Add this as the very last line of price.liquid, then Save. Without it the file breaks.

{%- endif -%}
Optional: approved (wholesale) buyers only

Where to paste: Replace Rule 2 in the code above with this, and tag approved customers wholesale in your admin.

  # Rule 2: everyone except customers tagged wholesale
  unless customer.tags contains 'wholesale'
    assign hide_price = true
    assign hide_price_text = 'Log in to see prices'
  endunless
Full guide: Shopify Hide Price: 5 Easy Ways
DawnHorizonLiquid

Replace Add to cart with a Contact for price button

Hides the buy buttons for tagged products and guests and shows a contact or login button instead (change /pages/contact to your page). It only hides the buttons, so set a product to draft if it must never sell online.

Dawn

Where to paste: Edit theme > Products > Default product > Product information > Add block > Custom Liquid, right under the price. Paste, Save.

{%- liquid
  assign hide_buy = false
  assign button_text = 'Contact for price'
  assign button_link = '/pages/contact'

  if product.tags contains 'hide-price'
    assign hide_buy = true
  endif

  if customer == blank
    assign hide_buy = true
    assign button_text = 'Log in to see prices'
    assign button_link = routes.account_login_url
  endif
-%}
{%- if hide_buy -%}
  <style>
    .product-form__buttons, .product-form__quantity { display: none; }
  </style>
  <a class="button button--full-width" href="{{ button_link }}">{{ button_text }}</a>
{%- endif -%}
Horizon

Where to paste: Edit theme > Products > Default product > Product information > Add block > Custom Liquid, right under the price. Paste, Save.

{%- liquid
  assign hide_buy = false
  assign button_text = 'Contact for price'
  assign button_link = '/pages/contact'

  if product.tags contains 'hide-price'
    assign hide_buy = true
  endif

  if customer == blank
    assign hide_buy = true
    assign button_text = 'Log in to see prices'
    assign button_link = routes.account_login_url
  endif
-%}
{%- if hide_buy -%}
  <style>
    .buy-buttons-block { display: none; }
  </style>
  <a class="button" href="{{ button_link }}">{{ button_text }}</a>
{%- endif -%}
Full guide: Shopify Hide Price: 5 Easy Ways
DawnHorizonLiquid

Product page tabs from your description headings

Each H3 heading in the product description becomes a tab, plus a Care guide tab (metafield descriptors.care_guide) and a Shipping & returns tab (page shipping-returns) when they exist. Hide the old description afterwards.

Dawn and Horizon

Where to paste: Dawn: Product information > Add block > Custom Liquid. Horizon: under Details in Product information > Add block > Custom Liquid. Paste into Liquid code, drag the block to where the description sits, Save.

{%- liquid
  assign first_tab = 'Description'
  assign lt = '<'
  assign h_open = lt | append: 'h3'
  assign h_close = lt | append: '/h3>'
  assign source = product.description

  assign care = product.metafields.descriptors.care_guide
  if care != blank
    assign care_html = care | metafield_tag
    assign source = source | append: h_open | append: '>Care guide' | append: h_close | append: care_html
  endif

  assign shared = pages['shipping-returns']
  if shared.content != blank
    assign source = source | append: h_open | append: '>Shipping & returns' | append: h_close | append: shared.content
  endif

  assign parts = source | split: h_open
  assign uid = 'ptabs-' | append: product.id
  assign n = 0
  assign tabs = ''
  assign panels = ''
-%}
{%- for part in parts -%}
  {%- liquid
    if forloop.first
      assign title = first_tab
      assign body = part
      assign check = body | strip_html | strip
      if check == ''
        continue
      endif
    else
      assign head = part | split: h_close | first
      assign title = h_open | append: head | strip_html | strip | default: 'Details'
      assign body = part | remove_first: head | remove_first: h_close
    endif
    assign n = n | plus: 1
  -%}
  {%- capture tabs -%}{{ tabs }}<button type="button" role="tab" id="{{ uid }}-t{{ n }}" aria-controls="{{ uid }}-p{{ n }}" aria-selected="{% if n == 1 %}true{% else %}false{% endif %}"{% if n != 1 %} tabindex="-1"{% endif %}>{{ title | escape_once }}</button>{%- endcapture -%}
  {%- capture panels -%}{{ panels }}<div class="ptabs__panel rte" role="tabpanel" id="{{ uid }}-p{{ n }}" aria-labelledby="{{ uid }}-t{{ n }}" tabindex="0"{% if n != 1 %} hidden{% endif %}>{{ body }}</div>{%- endcapture -%}
{%- endfor -%}
{%- if n > 0 -%}
<div class="ptabs" data-ptabs>
  <div class="ptabs__list" role="tablist" aria-label="Product details">{{ tabs }}</div>
  {{ panels }}
</div>
{%- endif -%}
<style>
  .ptabs { width: 100%; min-width: 0; margin: 24px 0; }
  .ptabs__list { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid rgba(128, 128, 128, 0.35); }
  .ptabs__list::-webkit-scrollbar { display: none; }
  .ptabs [role="tab"] { flex: none; margin: 0 0 -1px; padding: 12px 16px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: inherit; font: inherit; opacity: 0.7; cursor: pointer; white-space: nowrap; }
  .ptabs [role="tab"][aria-selected="true"] { opacity: 1; font-weight: 600; border-bottom-color: currentColor; }
  .ptabs [role="tab"]:focus-visible { outline: 2px solid currentColor; outline-offset: -4px; }
  .ptabs__panel { padding: 16px 0; overflow-wrap: break-word; }
  .ptabs__panel[hidden] { display: none; }
  .ptabs__panel img { max-width: 100%; height: auto; }
  .ptabs__panel table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
  .ptabs__panel :is(th, td) { padding: 6px 10px; border: 1px solid rgba(128, 128, 128, 0.35); text-align: left; }
</style>
<script>
  (function () {
    if (window.ptabsReady) return;
    window.ptabsReady = true;
    function pick(tab) {
      var box = tab.closest('[data-ptabs]');
      box.querySelectorAll('[role="tab"]').forEach(function (t) {
        var on = t === tab;
        t.setAttribute('aria-selected', on ? 'true' : 'false');
        t.tabIndex = on ? 0 : -1;
        box.querySelector('#' + t.getAttribute('aria-controls')).hidden = !on;
      });
      tab.focus();
      tab.scrollIntoView({ block: 'nearest', inline: 'nearest' });
    }
    document.addEventListener('click', function (e) {
      var tab = e.target.closest('[data-ptabs] [role="tab"]');
      if (tab) pick(tab);
    });
    document.addEventListener('keydown', function (e) {
      var tab = e.target.closest('[data-ptabs] [role="tab"]');
      if (!tab) return;
      var all = Array.prototype.slice.call(tab.parentNode.querySelectorAll('[role="tab"]'));
      var i = all.indexOf(tab);
      var go = { ArrowRight: i + 1, ArrowLeft: i - 1 + all.length, Home: 0, End: all.length - 1 }[e.key];
      if (go === undefined) return;
      e.preventDefault();
      pick(all[go % all.length]);
    });
  })();
</script>
Full guide: Shopify Product Page Tabs (No App)
DawnHorizonHTML

Autoplay background video banner

A muted, looping video with a heading and a button on top, which stops for shoppers who reduce motion. Replace the two PASTE links with links from Content > Files, or delete the poster line if you have no image.

Dawn and Horizon

Where to paste: Edit theme > Add section > Custom Liquid. Paste into Liquid code and drag it under the header. Dawn: set Top and Bottom padding to 0. Horizon: set Width to Full. Save.

<div class="zh-video-hero">
  <video class="zh-video-hero__video" autoplay muted loop playsinline preload="metadata"
    poster="PASTE-YOUR-POSTER-IMAGE-LINK-HERE" aria-hidden="true">
    <source src="PASTE-YOUR-MP4-LINK-HERE" type="video/mp4">
  </video>
  <div class="zh-video-hero__content">
    <h2 class="zh-video-hero__title">New summer collection</h2>
    <a class="zh-video-hero__button" href="/collections/all">Shop now</a>
  </div>
</div>

<style>
  .zh-video-hero { position: relative; overflow: hidden; height: 80vh; min-height: 420px; max-height: 760px; background: #111; }
  .zh-video-hero__video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
  .zh-video-hero__content { position: relative; z-index: 1; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 24px; text-align: center; background: rgba(0, 0, 0, 0.3); }
  .zh-video-hero__title { margin: 0; color: #fff; font-size: clamp(28px, 6vw, 56px); line-height: 1.1; }
  .zh-video-hero__button { display: inline-block; padding: 14px 32px; background: #fff; color: #111; text-decoration: none; font-weight: 600; border-radius: 4px; }
  @media (max-width: 749px) { .zh-video-hero { height: 70vh; min-height: 360px; } }
</style>

<script>
  if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
    document.querySelectorAll('.zh-video-hero__video').forEach(function (v) { v.removeAttribute('autoplay'); v.pause(); });
  }
</script>
Full guide: Add Video to Shopify Homepage
DawnHorizonCSS

Use your own font file (Custom CSS)

Upload your font files in Content > Files and paste their links, because Custom CSS only accepts cdn.shopify.com links. Change Brand Sans to your font's name, and use the theme-wide box, not a section's box.

Dawn

Where to paste: Online Store > Themes > Edit theme > Theme settings (gear icon) > Custom CSS. Paste, then Save.

@font-face {
  font-family: "Brand Sans";
  src: url("https://cdn.shopify.com/s/files/1/XXXX/files/BrandSans-Regular.woff2?v=1") format("woff2"),
       url("https://cdn.shopify.com/s/files/1/XXXX/files/BrandSans-Regular.woff?v=1") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Brand Sans";
  src: url("https://cdn.shopify.com/s/files/1/XXXX/files/BrandSans-Bold.woff2?v=1") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
html:root {
  --font-body-family: "Brand Sans", sans-serif;
  --font-heading-family: "Brand Sans", sans-serif;
}
Horizon: replace the last part

Where to paste: Same box: keep the two @font-face blocks from the Dawn version, and use this instead of its html:root part.

html:root {
  --font-body--family: "Brand Sans", sans-serif;
  --font-subheading--family: "Brand Sans", sans-serif;
  --font-heading--family: "Brand Sans", sans-serif;
  --font-accent--family: "Brand Sans", sans-serif;
}
Full guide: Shopify Custom Font: Change It or Upload Your Own
Any themeLiquid

Load a font file in theme.liquid (developers)

The file_url filter finds the file in Content > Files by its name. Keep the html:root part in Custom CSS, and expect to redo this after a theme update.

Any theme

Where to paste: Duplicate your theme, then Edit code > layout/theme.liquid. Paste just above {{ content_for_header }}. Save.

<style>
  @font-face {
    font-family: "Brand Sans";
    src: url("{{ 'BrandSans-Regular.woff2' | file_url }}") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
  }
</style>
Full guide: Shopify Custom Font: Change It or Upload Your Own
DawnHorizonLiquid

Larger favicon for Google and iPhone home screens

Adds a 96 x 96 icon and a 180 x 180 apple-touch-icon, because Dawn and Horizon only output 32 x 32. Upload a favicon of at least 180 x 180 pixels, and remember that Google decides which icon it shows.

Dawn and Horizon

Where to paste: Edit code > layout/theme.liquid. Find the line with settings.favicon and paste this under the endif that closes that favicon block. Save.

{%- if settings.favicon != blank -%}
  <link rel="icon" type="image/png" sizes="96x96" href="{{ settings.favicon | image_url: width: 96, height: 96 }}">
  <link rel="apple-touch-icon" sizes="180x180" href="{{ settings.favicon | image_url: width: 180, height: 180 }}">
{%- endif -%}
Full guide: Shopify Favicon: Size, Setup and Not-Showing Fix

These Shopify code snippets come from my own step-by-step guides. I tested each one against the real Dawn or Horizon theme files before it went into a guide. Search the Shopify code snippets library above, copy the code with one click, and read the “Where to paste” line so it lands in the right place. Below, I explain where Shopify code snippets belong, how to test a change and how to undo it.

Here is what you will learn:

  • How to find and copy Shopify code snippets in the library
  • Where Shopify custom CSS goes, and the limits of the Custom CSS box
  • Where Shopify Liquid code goes, and when you need Edit code
  • How to test a change, and how to undo it if something breaks
  • What changes between Dawn and Horizon

How to use the Shopify code snippets library

Each card in this library of Shopify code snippets does one job, such as “Hide the Sale badge but keep Sold out”. The tags show the theme it was tested on and the kind of code it is.

Shopify code snippets on a desktop screen
The free Shopify code snippets page on a computer screen.
  1. Type a word in the search box, like badge, price or cart. The search looks at the title, the note and the code itself.
  2. Pick your theme. Dawn and Horizon also show code marked Any theme, because that code works in both.
  3. Pick a type if you only want one kind. Choose CSS when you don’t want to touch any theme files.
  4. Read the Where to paste line. It names the exact box or file.
  5. Click Copy, paste the code, then click Save.

A card for both themes has a Dawn version and a Horizon version. Pick one theme in the filter and the other version hides. Bigger jobs come in steps, so do every step, in order. Each card links to its full guide, which shows the no-code way first. New guides add new Shopify code snippets, so the count grows over time.

Shopify custom CSS or Liquid: what is the difference?

Most Shopify code snippets fall into two groups, and each group goes in a different place.

CSS changes how things look. It can hide a badge, change a color or set a font. It can’t add new content, read your products or know who is logged in. CSS is the safest code to add, because it never touches the theme files.

Liquid builds the page. Liquid is Shopify’s template language. Shopify Liquid code can read the cart total, a product’s tags or whether a customer is logged in, and then print HTML. A free shipping bar that says “$17.50 away” needs Liquid, because CSS can’t do sums with your cart.

HTML and JavaScript cards usually go in the same places as Liquid.

Code typeWhat it doesWhere it goesRisk
CSSChanges the lookCustom CSS boxLow
LiquidBuilds content from store dataCustom Liquid or Edit codeMedium
HTMLAdds fixed contentPage editor or Custom LiquidLow
JavaScriptAdds behaviorCustom Liquid or Edit codeMedium

Where to paste Shopify custom CSS

Shopify gives modern themes two Custom CSS boxes. You don’t open any theme file for either of them.

Shopify code snippets on a phone screen
The Shopify code snippets page also works on a phone.

The theme-wide Custom CSS box

Go to Online Store and click Edit theme. Open Theme settings (the gear icon) and click Custom CSS. Paste your code and click Save. Code here works on every page of the store, including the cart drawer. It doesn’t work on the checkout page.

The Custom CSS box in one section

Click any section in the theme editor and scroll to the bottom of its settings. That box only styles that one section. It’s handy for hiding prices in one collection grid only.

The limits of Shopify custom CSS

Shopify’s help page on adding custom CSS lists the rules. These are the ones that trip people up:

  • The theme-wide box holds 1,500 characters. A section box holds 500.
  • The @import, @charset and @namespace rules are blocked in both boxes.
  • A section box only allows @media, @container, @layer and @supports. So a font with @font-face must go in the theme-wide box.
  • The content property isn’t allowed, so you can’t add text with ::before or ::after.
  • Any link inside the CSS must point to cdn.shopify.com. Upload fonts and images in Content, then Files, and use those links.
  • A theme update can rename classes, and then your CSS quietly stops working.

Every CSS card here fits well under these limits, but count your characters if you stack several.

One more plus: Shopify copies theme settings, including this box, into an updated theme version. So Shopify custom CSS survives an update even when a file edit might not.

Where to paste Shopify Liquid code

Liquid has two homes. Use the first one whenever the card allows it.

Custom Liquid blocks and sections (no theme files)

Dawn and Horizon both have a Custom Liquid section, which you add with Add section like any other. Product pages also take a Custom Liquid block. Paste your Shopify Liquid code into the Liquid code box and save. To undo it, delete the block. Nothing else in the theme changes.

The box holds up to 50 KB, far more than any card needs. Shopify won’t save it if the Liquid has an error, which is a useful safety net. It also closes any HTML tag you left open, so paste the whole snippet. One limit matters: code in this box can’t read theme settings, such as your favicon. That’s why the favicon card goes in theme.liquid.

Edit code (theme files)

Some Shopify Liquid code changes what the theme itself prints, like the price or the sale badge text. That needs Edit code. Always work on a copy first:

  1. Go to Online Store, then Themes.
  2. Click the … button next to your live theme and choose Duplicate.
  3. On the copy, click … and choose Edit code.
  4. Open the file named on the card. Press Ctrl + F (Command + F on a Mac) to find the line it mentions.
  5. Paste or replace exactly what the card says, then click Save.
  6. Preview the copy and test it. Publish it only when everything works.

Basic, Grow and Advanced plans allow up to 20 themes in your library. If you’re at the limit, delete an old copy before you duplicate. Paid themes need to be bought before you can edit their code.

A red line under the code is Theme Check warning you. Hover over it and read the message before you save.

How to test Shopify code snippets

I test Shopify code snippets the same way on every client store. It takes about five minutes.

  • Test at phone width. Open the preview on your phone and look for anything that runs off the screen.
  • Check every place the code touches. Check cart code on the cart page and in the cart drawer. Check price code on product cards, the product page and search results.
  • Try the odd cases. Test an empty cart, a sold-out product and a product with several variants.
  • Test as a shopper. The theme editor preview isn’t logged in as a customer. Login rules, like “Log in to see prices”, only show their real result on the live store with a customer account.
  • Reload when nothing changes. Hard-refresh with Ctrl + Shift + R, then check that you saved the theme you’re previewing.

How to undo Shopify code snippets

How you undo Shopify code snippets depends on where you pasted the code.

Where you pastedHow to undo
Custom CSS boxDelete the code and save
Custom Liquid block or sectionDelete the block or section
A theme fileRestore it from Timeline
Anything on a duplicateKeep the old theme live

For a theme file, open it in Edit code and use the Timeline view. Click an older entry to compare it, then right-click it and choose Restore contents. Shopify notes that this restores one file at a time and replaces the whole file. It can’t bring back a deleted file, and the history is limited. Files in the assets folder have no Timeline at all.

That’s why the duplicate matters. If you break something, you don’t need to remember what you changed. Your live theme is still the untouched one.

Dawn vs Horizon: why Shopify Liquid code differs

Dawn and Horizon are both free Shopify themes, but they are built very differently inside. Shopify Liquid code for one rarely works in the other without changes. Not sure which one you have? My Dawn vs Horizon comparison shows how to tell them apart.

  • Class names differ. Dawn’s card badge sits in .card__badge, while Horizon uses .product-badges. CSS that names one theme’s classes does nothing in the other.
  • Font names differ. Dawn’s body font is –font-body-family. Horizon uses –font-body–family, with two dashes in the middle. Miss one dash and the font never changes.
  • Files differ. Dawn’s cart drawer and cart page use separate files. Horizon’s share one summary file, so one line covers both.
  • Horizon has more settings. Some jobs that need code in Dawn are a checkbox in Horizon, like removing “Powered by Shopify”. The cards say so.
  • Custom Liquid sections start differently. Dawn’s adds 40 px of padding on top and 52 px at the bottom. Horizon’s starts at 0 and has a Width setting. For an edge-to-edge bar, set Dawn’s padding to 0 and Horizon’s width to Full.

A paid theme uses its own class names and file names, so start with the Any theme cards there.

Worked examples with Shopify code snippets

Worked example 1: hide the Sale badge on Dawn (CSS)

A Dawn store ends a sale but keeps the compare-at prices for a week. The owner wants the crossed-out price to stay and the badge to go.

  1. Type badge in the search box and pick Dawn.
  2. Find “Hide the Sale badge but keep Sold out” and click Copy.
  3. In the theme editor, open Theme settings, then Custom CSS. Paste and save.
  4. Check a sale product and a sold-out product on a phone. The Sale badge is gone, and Sold out still shows.

To undo it, delete those lines from the box. No theme file is touched. The full Shopify sale badge guide covers color, text and “% off” too.

Worked example 2: add a free shipping bar on Horizon (Liquid)

A Horizon store ships free over $50. The owner wants the cart to show how much is left to spend.

  1. Search shipping and open the free shipping bar card.
  2. Duplicate the theme, then open Edit code on the copy.
  3. Step 1: add a file named free-shipping-bar.liquid in the snippets folder. Paste the Shopify Liquid code, keep USD and 50, and save.
  4. Step 2: open snippets/cart-summary.liquid. Paste the one render line right above the cart-totals line.
  5. Preview the copy. With $32.50 in the cart, the bar says “$17.50 away from free shipping”. At $50, it says the order ships free.
  6. Check the drawer and the cart page, then publish the copy.

My free shipping bar guide covers the Dawn steps too.

Common mistakes with Shopify code snippets

  • Pasting Liquid into Custom CSS. The CSS box only takes CSS. Anything with {% or {{ belongs in a Custom Liquid block or a theme file.
  • Using Shopify code snippets for the wrong theme. Check your theme’s name in Online Store, then Themes. Copy the version that matches it.
  • Editing the live theme. One typo in a theme file can break a page for every shopper. Work on a duplicate.
  • Skipping a step. Cards with steps need every one of them. Leave one out and the Shopify Liquid code does nothing, or the page breaks.
  • Forgetting file edits at update time. Shopify keeps your code edits in an update only when they don’t clash with it. Before you update, check my theme update tracker and test your Shopify code snippets again on the new version.

More free tools like this one are on the Shopify tools page.

FAQ

Questions about the Code Snippets Library

Can’t find your answer? Ask me directly, I’m happy to help.

Where do I add custom CSS in Shopify?

Go to Online Store, click Edit theme, open Theme settings and click Custom CSS. Shopify custom CSS there works on every page except checkout. For one section only, use the box at the bottom of that section’s settings.

Usually the class name comes from a different theme, so the rule matches nothing. Also check for a missing bracket, a blocked rule like @import, or the content property, which Shopify doesn’t allow. Then hard-refresh the page.

The theme-wide box for Shopify custom CSS holds 1,500 characters, and each section’s box holds 500. If you need more, combine rules, delete comments, or move the CSS into a theme file on a duplicate theme.

Yes. Add CSS in the Custom CSS box, Shopify Liquid code and HTML in a Custom Liquid block, and anything else through Edit code. Paid themes need to be bought before you can edit their code.

A section is a part of a page that you can add, move and set up in the theme editor. A snippet is a small reusable file in the snippets folder that sections pull in with a render line. Don’t confuse them with the Shopify code snippets in this library, which are simply ready-made pieces of code.

Yes. Wrap your Shopify custom CSS in a media query, such as @media (max-width: 749px), and it only applies to small screens. Dawn and Horizon switch to their phone layout below 750 pixels.

More free tools

Other free Shopify tools

◎ Free calculator

Shopify Fee Calculator

Add up plan, card, PayPal and third-party fees, then see which Shopify plan is cheapest for you.

Free, no sign-up

◎ Free calculator

Profit Margin Calculator

Real profit per order after discounts, shipping, card fees and ads, plus margin, markup and monthly profit.

Free, no sign-up

◎ Free calculator

Break-Even ROAS Calculator

Find the ROAS and max cost per sale your ads need to break even, and check a campaign's real profit.

Free, no sign-up

◎ Free calculator

Pricing Calculator

Find the price to charge from your costs, fees and goal margin, with .99 rounding and compare-at prices.

Free, no sign-up

◎ Free live tracker

Theme Update Tracker

Live Dawn and Horizon versions, release notes and a checker that shows how far behind your theme is.

Free, no sign-up

◎ Free store checker

Theme Detector & Store Checker

See any store's theme and version, apps, product count and price range from public pages.

Free, no sign-up

◎ Free speed test

Store Speed Test

Get Google's speed score and Core Web Vitals for any store, with the top fixes explained for Shopify.

Free, no sign-up

◎ Free image tool

Image Resizer

Resize product photos, banners and logos to Shopify sizes in your browser. Nothing is uploaded.

Free, no sign-up

◎ Free calculator

Sales Goal Calculator

See the orders, visitors and ad budget you need for a monthly sales goal, or forecast revenue from traffic.

Free, no sign-up

◎ Free SEO tool

SEO Title & Meta Checker

Preview a Shopify page in Google, check title and description width in pixels, and fix the URL handle.

Free, no sign-up

◎ Free calculator

Discount Calculator

See what a sale or discount code does to your profit, and the extra orders you need to keep the same profit.

Free, no sign-up

Let's start

Want a free check of your store?

Send me your store link. I'll look at your homepage, product page and mobile layout and reply with the 3 changes that would help sales most.

✓ Free quote✓ Fixed price✓ You own everything