Build a Shopify theme from scratch, with Liquid · Part 1 of 6
The anatomy of a theme, and one that renders
What the folders mean, the layout, section groups, a section's schema, JSON templates, theme settings turned into CSS variables that Tailwind reads, Theme Check, and a push to the dev store.
By Abhishek Fouzdar
This part ends with a theme of our own on a development store: a layout, a header and footer the merchant can rearrange, a home page with a hero section, every page type the store needs rendering with real products, a stylesheet compiled by Tailwind from theme settings, and Theme Check reporting nothing. The series introduction explains what Lantern is and what the six parts build.

What a theme is
A Shopify theme is a folder. Shopify renders it on its own servers with Liquid, a template language with objects (product, cart, collection), tags ({% if %}, {% for %}, {% render %}) and filters (| money, | image_url). There is no server of yours, no build step Shopify runs, and no JavaScript framework: the folder is uploaded as it is, and the only thing that must exist is layout/theme.liquid.
The folder has a fixed set of directories, and each one has one job:
| Directory | What goes in it |
|---|---|
layout/ |
The HTML around every page. theme.liquid is required. |
templates/ |
One file per page type, JSON, listing which sections the page shows. |
sections/ |
Liquid files a merchant can add, remove, reorder and configure in the theme editor, plus the JSON section groups for the header and footer. |
blocks/ |
Reusable pieces a merchant drops into sections. Part 3. |
snippets/ |
Liquid you render from elsewhere: an icon, a product card. |
config/ |
settings_schema.json, the theme settings the editor shows; settings_data.json, their values. |
locales/ |
Translations for every string the theme prints. |
assets/ |
CSS, JavaScript, images. Served from Shopify's CDN. |
Shopify ships a starting point called the Skeleton theme (shopify theme init clones it), and Dawn and Horizon are the reference themes to read when you want to see how something is done. This series writes every file by hand, because the point is to understand each one, and because a theme you can explain is a theme you can maintain.
The tools
Shopify CLI is the one tool. The series used version 4.9.4:
npm install -g @shopify/cli
shopify version
It logs in through the browser the first time a command needs the store. shopify theme list --store saanjh-living.myshopify.com is the smallest useful command, and it is how to check you are talking to the right store:
╭─ info ───────────────────────────────────────────────────────────────────────╮
│ name role id │
│ ─────────────────────────────── ────────────────────── ────────────── │
│ Horizon [live] #195832611185 │
│ Updated copy of Horizon [unpublished] #209075831153 │
╰──────────────────────────────────────────────────────────────────────────────╯
The development store is the one from the Shopify app series: 38 products with photos and variants, in rupees, behind a storefront password. Horizon is its live theme and stays that way; everything in this series happens on an unpublished theme beside it.
For the CSS the series uses Tailwind 4, compiled on the laptop into one static file. A theme cannot run a build step on Shopify, so the compiled stylesheet is committed and uploaded like any asset:
npm init -y
npm install -D tailwindcss @tailwindcss/cli
package.json gets two scripts, build and watch, both tailwindcss -i src/theme.css -o assets/theme.css, and a .shopifyignore keeps the Node toolchain out of the upload:
src/*
node_modules/*
package.json
package-lock.json
README.md
.gitignore
The layout
layout/theme.liquid is the page around every page. Two objects in it are mandatory, and Theme Check refuses a layout without them: content_for_header, which Shopify fills with its own scripts and the tags apps inject, and content_for_layout, where the template's sections render.
<!doctype html>
<html lang="{{ request.locale.iso_code }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
{{- page_title -}}
{%- if current_page != 1 %} – {{ 'general.pagination.page' | t: page: current_page }}{% endif -%}
{%- unless page_title contains shop.name %} – {{ shop.name }}{% endunless -%}
</title>
{%- if page_description -%}<meta name="description" content="{{ page_description | escape }}">{%- endif -%}
<link rel="canonical" href="{{ canonical_url }}">
{%- comment -%}
Theme settings become CSS variables here; Tailwind's tokens in src/theme.css read them,
so a colour changed in the theme editor changes every utility that uses it.
{%- endcomment -%}
<style>
:root {
--lantern-ground: {{ settings.color_ground }};
--lantern-ground-2: {{ settings.color_ground_2 }};
--lantern-ink: {{ settings.color_ink }};
--lantern-ink-2: {{ settings.color_ink_2 }};
--lantern-line: {{ settings.color_line }};
--lantern-accent: {{ settings.color_accent }};
--lantern-on-accent: {{ settings.color_on_accent }};
--lantern-font-heading: ui-sans-serif, system-ui, sans-serif;
--lantern-font-body: ui-sans-serif, system-ui, sans-serif;
}
</style>
{{ 'theme.css' | asset_url | stylesheet_tag }}
{{ content_for_header }}
</head>
<body class="min-h-screen flex flex-col bg-ground text-ink antialiased">
<a href="#MainContent" class="sr-only focus:not-sr-only focus:absolute focus:top-2 focus:left-2 focus:z-50 focus:bg-ink focus:text-ground focus:px-4 focus:py-2 focus:rounded-full">{{ 'accessibility.skip_to_content' | t }}</a>
{% sections 'header-group' %}
<main id="MainContent" class="flex-1" role="main" tabindex="-1">
{{ content_for_layout }}
</main>
{% sections 'footer-group' %}
<script src="{{ 'theme.js' | asset_url }}" defer></script>
</body>
</html>
Four things to read from it. {{ 'theme.css' | asset_url | stylesheet_tag }} is how an asset is referenced: the filter returns the CDN URL with a cache-busting version, and stylesheet_tag wraps it in a <link>. {{ 'accessibility.skip_to_content' | t }} is a translation: the key lives in locales/en.default.json, and every string the theme prints goes through t, so a merchant can translate the theme without touching Liquid. {% sections 'header-group' %} renders a section group, explained next. And the <style> block is where theme settings turn into CSS variables, which is what makes Tailwind and the theme editor agree; the section on styling below shows the other half.
Section groups
The header and footer are not in the layout. They are section groups, JSON files in sections/ that list which sections render in that area and in which order, and the merchant can change both in the theme editor without a code change. This is a Theme Store requirement, and it is also the right design: an announcement bar is something merchants add and remove weekly.
{
"type": "header",
"name": "Header group",
"sections": {
"announcement-bar": { "type": "announcement-bar", "settings": { "text": "Free delivery across India on orders over ₹1,499" } },
"header": { "type": "header", "settings": {} }
},
"order": ["announcement-bar", "header"]
}
type is header or footer, the two areas Shopify recognises. Each entry's type is a file in sections/, so announcement-bar renders sections/announcement-bar.liquid with the settings given. The footer group is the same shape with one section.
A section, from the inside
A section is a Liquid file with a {% schema %} block at the bottom. The Liquid renders; the schema tells the editor what the section is called, what settings it has, and whether a merchant can add it to a page. The announcement bar is the smallest one:
{%- if section.settings.text != blank -%}
<div class="bg-accent text-on-accent text-[13px] font-medium text-center px-4 py-2.5">
{%- if section.settings.link != blank -%}
<a href="{{ section.settings.link }}" class="underline-offset-2 hover:underline">{{ section.settings.text | escape }}</a>
{%- else -%}
{{ section.settings.text | escape }}
{%- endif -%}
</div>
{%- endif -%}
{% schema %}
{
"name": "Announcement bar",
"settings": [
{ "type": "text", "id": "text", "label": "Text", "default": "Free delivery on orders over ₹1,499" },
{ "type": "url", "id": "link", "label": "Link" }
],
"presets": [{ "name": "Announcement bar" }]
}
{% endschema %}
section.settings.text is whatever the merchant typed, or the default. | escape is there because it is merchant-typed; Liquid does not escape output by itself. presets is what makes the section appear in the editor's "Add section" list; a section without presets can only be placed by a template or group file, which is right for things like the main product section that belongs on exactly one page.
The header is the same pattern with more going on:
<header class="bg-ground border-b border-line {% if section.settings.sticky %}sticky top-0 z-40{% endif %}">
<div class="wrap flex items-center justify-between gap-4 h-[72px]">
<a href="{{ routes.root_url }}" class="font-heading font-extrabold text-[22px] tracking-tight">
{%- if section.settings.logo != blank -%}
{{ section.settings.logo | image_url: width: 300 | image_tag: width: section.settings.logo_width, class: 'h-auto', alt: shop.name }}
{%- else -%}
{{ shop.name }}
{%- endif -%}
</a>
{%- liquid
assign menu = linklists[section.settings.menu]
-%}
<nav class="hidden md:flex gap-1" aria-label="{{ 'general.navigation.main' | t }}">
{%- for link in menu.links -%}
<a href="{{ link.url }}" class="text-[15px] font-medium px-3 py-2.5 rounded-full hover:bg-ground-2 {% if link.current %}underline underline-offset-4{% endif %}" {% if link.current %}aria-current="page"{% endif %}>{{ link.title }}</a>
{%- endfor -%}
</nav>
<div class="flex items-center gap-1">
<a href="{{ routes.search_url }}" class="icon-btn" aria-label="{{ 'general.search.search' | t }}">{% render 'icon', name: 'search' %}</a>
{%- if shop.customer_accounts_enabled -%}
<a href="{{ routes.account_url }}" class="icon-btn" aria-label="{{ 'customer.account.title' | t }}">{% render 'icon', name: 'account' %}</a>
{%- endif -%}
<a href="{{ routes.cart_url }}" class="icon-btn" aria-label="{{ 'cart.general.title' | t }}, {{ 'cart.general.item_count' | t: count: cart.item_count }}">
{% render 'icon', name: 'cart' %}
<span class="absolute top-1 right-1 min-w-[18px] h-[18px] px-1.5 rounded-full bg-accent text-on-accent text-[11px] font-semibold flex items-center justify-center {% if cart.item_count == 0 %}hidden{% endif %}" data-cart-count>{{ cart.item_count }}</span>
</a>
</div>
</div>
</header>
The menu comes from linklists[section.settings.menu]: Navigation in the admin, chosen by the merchant through a link_list setting that defaults to main-menu, which is why the screenshot shows Home, Catalog and Contact without the theme knowing those words. routes.cart_url and its siblings are the store's URLs, which differ by locale and market, so a theme never hard-codes /cart. cart.item_count is live on every page because the cart is part of every request. {% render 'icon', name: 'search' %} renders snippets/icon.liquid with a variable, and a snippet sees only the variables it is given, which is the difference from the older include. The {%- liquid ... -%} tag runs several lines of Liquid without opening and closing a tag on each.
Templates
A template says which sections a page shows. Since Online Store 2.0 they are JSON, not Liquid: the home page is
{
"sections": {
"hero": { "type": "hero", "settings": {} }
},
"order": ["hero"]
}
and the product page is { "sections": { "main": { "type": "main-product", "settings": {} } }, "order": ["main"] }. The same shape every time, which is the point: the page is data the editor can change, and the Liquid lives in sections. Part 1 writes a main-* section for each page type, each doing the simplest correct thing with its object, so that every page renders before any of them is good: main-product shows the title, vendor, price, a variant select and an add-to-cart form; main-collection paginates the products into a grid of product-card snippets; main-cart lists the lines with quantity inputs; search, page, blog, article, 404 and the password page have theirs. Two things stay Liquid templates by design: gift_card.liquid, which renders a gift card with its own markup and no layout, and the password page's layout, layout/password.liquid, a stripped version of the main one.
The list of templates the store needs is the Theme Store's list: index, product, collection, list-collections, cart, page, page.contact, blog, article, search, 404, password as JSON, plus gift_card.liquid. Customer account pages come in part 5.
Settings, and Tailwind reading them
config/settings_schema.json is what the theme editor shows under Theme settings. The first entry is required and names the theme; the rest are groups of settings:
[
{
"name": "theme_info",
"theme_name": "Lantern",
"theme_version": "0.1.0",
"theme_author": "Shipbytes",
"theme_documentation_url": "https://shipbytes.dev/blog/shopify-theme-from-scratch/",
"theme_support_url": "https://github.com/shipbytes/lantern-theme/issues"
},
{
"name": "Colors",
"settings": [
{ "type": "color", "id": "color_ground", "label": "Background", "default": "#F4F2EE" },
{ "type": "color", "id": "color_ground_2", "label": "Background, raised", "default": "#E9E6DF" },
{ "type": "color", "id": "color_ink", "label": "Text", "default": "#1F1F1D" },
{ "type": "color", "id": "color_ink_2", "label": "Text, muted", "default": "#5C5A55" },
{ "type": "color", "id": "color_line", "label": "Lines", "default": "#E3DFD6" },
{ "type": "color", "id": "color_accent", "label": "Accent", "default": "#0F5F5C" },
{ "type": "color", "id": "color_on_accent", "label": "Text on accent", "default": "#F4F2EE" }
]
}
]
Every setting is reachable as settings.color_accent in any Liquid file, and the layout writes each one into a CSS variable. Then Tailwind's source, src/theme.css, declares its tokens as those variables:
@import "tailwindcss";
/* Tailwind only emits classes it finds; tell it where the Liquid lives. */
@source "../layout";
@source "../sections";
@source "../snippets";
@source "../blocks";
@source "../templates";
/* The theme's design tokens. `inline` makes each utility use the CSS variable itself, so
the values can come from theme settings at runtime (layout/theme.liquid sets them). */
@theme inline {
--color-ground: var(--lantern-ground);
--color-ground-2: var(--lantern-ground-2);
--color-ink: var(--lantern-ink);
--color-ink-2: var(--lantern-ink-2);
--color-line: var(--lantern-line);
--color-accent: var(--lantern-accent);
--color-on-accent: var(--lantern-on-accent);
--font-heading: var(--lantern-font-heading);
--font-body: var(--lantern-font-body);
--radius-tile: 16px;
}
@theme inline is the whole trick. With it, bg-accent compiles to background-color: var(--lantern-accent) rather than to a hex, so the compiled stylesheet never contains a colour: the merchant changes Accent in the editor, the layout prints a new variable, every bg-accent, text-accent and border-accent on the site follows, and nobody rebuilds anything. @source tells Tailwind to scan the Liquid for class names, which it must, because it emits only the utilities it finds. A handful of @layer components rules (.btn, .wrap, .icon-btn) give the few repeated patterns one name.
npm run build
Done in 150ms
Sixteen kilobytes, minified, into assets/theme.css.
Check, push, preview
Theme Check is built into the CLI and runs against the folder:
shopify theme check
╭─ success ────────────────────────────────────────────────────────────────────╮
│ Theme Check Summary. │
│ 39 files inspected with no offenses found. │
╰──────────────────────────────────────────────────────────────────────────────╯
It catches the things that are silent in the browser: a missing snippet, a {% render %} of a file that does not exist, a layout without content_for_header, a schema with an invalid setting type, an image without width and height. Running it before every push costs nothing.
Pushing creates the theme in the store's library. --unpublished makes a new one instead of overwriting whatever is selected, and --json returns the ids a script can use:
shopify theme push --unpublished --theme "Lantern (dev)" --store saanjh-living.myshopify.com --json
{"theme":{"id":209640391025,"name":"Lantern (dev)","role":"unpublished","shop":"saanjh-living.myshopify.com","editor_url":"https://saanjh-living.myshopify.com/admin/themes/209640391025/editor","preview_url":"https://saanjh-living.myshopify.com?preview_theme_id=209640391025"}}
The preview URL shows the unpublished theme to anyone with the link and the storefront password, which is how the screenshots in this series were taken: a Playwright script enters the password once and then visits each page with ?preview_theme_id=.
For day-to-day work, shopify theme dev uploads the folder as a development theme, a hidden one that does not count against the store's theme limit, and serves it locally with hot reload:
shopify theme dev --store saanjh-living.myshopify.com
╭─ success ────────────────────────────────────────────────────────────────────╮
│ Preview your theme (t) │
│ • [1] │
│ Next steps │
│ • Share your theme preview (p) [2] │
│ https://saanjh-living.myshopify.com/?preview_theme_id=209640423793 │
│ • Customize your theme at the theme editor (e) [3] │
│ • Preview your gift cards (g) [4] │
╰──────────────────────────────────────────────────────────────────────────────╯
[1] http://127.0.0.1:9292
With npm run watch in a second terminal, a change to any Liquid file rebuilds the stylesheet and the dev server pushes both. Note the two different theme ids: the development theme is not the unpublished one you pushed, and it is deleted after seven days of inactivity or when you log out.
The collection page, with the store's real products through main-collection and the product-card snippet, nothing added to the data:

And a product page, with the variant select the product form posts to the cart:

The prices read "Rs. 1,200.00" rather than "₹1,200" because that is the store's money format setting, which the money filter obeys; the theme does not decide it.
What went wrong
Directory pattern may be misleading from shopify theme dev, twice. .shopifyignore wants src/* and node_modules/*, not src/ and node_modules/. The trailing-slash form is accepted and warned about on every run.
An empty templates/customers directory created ahead of part 5 would have been fine for Shopify and invisible to git; it was removed to keep the commit honest about what exists.
A screenshot script counted products on the wrong page. Not the theme's fault, but a reminder that a number printed by a script is only as good as the page it was read from; the 38 in the heading is the collection's own count.
Part 2 is Liquid itself: objects, tags and filters, worked through on the product and collection pages until they look like the design, with the variant picker, sale prices, image sizes and the loops and conditionals that every theme is made of.
New posts by email
Get new posts by email. Nothing else, no digests, unsubscribe in one click.
Comments
Comments are GitHub Discussions in shipbytes/discussions. Sign in with GitHub to post.
In this series
1 / 6- OverviewBuild a Shopify theme from scratch, with Liquid
- Part 1The anatomy of a theme, and one that renders
- Part 2Liquid on the product and collection pages
- Part 3Sections, blocks and the theme editor
- Part 4Variants without reloads, the Cart API and a cart drawer
- Part 5Search, pagination, metafields, translations and customers
- Part 6Performance, accessibility, Theme Check and publishing