Skip to content

Liquid and CSS Basics for Code Mode

How a template's files fit together, the Liquid you need to print, test and loop over order data, and how to restyle a document with CSS.

Medium BusinessUpdated 2026-11-03

The Files

Open the Code tab. It has two tabs of its own:

  • Liquid, with a File list: Layout is the page itself, which places every block in order; Head holds the page's metadata and the rules that apply your Template Settings (colours, fonts, sizes); then one file per block (Shop Details, Line Items, Totals…) with that block's content.
  • CSS: the template's stylesheet.

The preview on the right re-renders half a second after you stop typing and opens at 90% zoom, or smaller if the page is too narrow. Guide, at the right of the Liquid and CSS tabs, opens the Liquid Variables article. Edit Liquid for This Block at the bottom of any block's settings jumps straight to its file. Your code is saved with the template's Save and Publish like every other change.

How a Block Is Wired

In Layout, each block sits in a wrapper the visual editor relies on:

{% if blocks.block_line_items.visible %}
  <div data-block="line-items" data-block-id="block_line_items">
    {% include "blocks/line-items", id: "block_line_items" %}
    {%- comment -%}sub-blocks: block_line_items{%- endcomment -%}
  </div>
{% endif %}

Move a block by cutting its whole wrapper, from {% if blocks.… .visible %} to its {% endif %}, and pasting it where the block should print. Keep the data-block-id and the sub-blocks comment: Preview mode uses them to select the block and to place blocks added inside it. Some wrappers have an extra line that skips the block when it has nothing to print (Notes, Terms & Refund Policy, Validity, Payment Terms, Social Links); move that with it. Bill To, Ship To and Invoice Details share one row, and Payment Method, Shipping Method and Totals sit in shared containers, so moving one of them out of its container changes the layout.

Liquid in Five Minutes

  • Print a value: {{ order.name }}, {{ customer.email }}, {{ total }}. Amounts are already formatted in the document currency.
  • Show something only when it exists: {% if order.note != blank %}<p>{{ order.note }}</p>{% endif %}. An empty value prints nothing, so guard the label with it.
  • Choose between cases: {% if order.has_payment %}Paid{% elsif has_amount_due %}Due: {{ amount_due }}{% endif %}.
  • Loop over lines:
    {% for item in line_items %}
      {{ item.quantity }} × {{ item.title }}
    {% endfor %}
  • Transform with filters: {{ order.name | remove: "#" }}, {{ item.title | upcase }}, {{ order.total_amount | times: 0.5 | money }}.
  • Keep a value: {% assign first = line_items | first %}, and {% capture greeting %}Hello {{ billing_address.name }}{% endcapture %} for a block of text.
  • Read a block's setting: {{ blocks.block_notes.settings.label }}.

Every variable is listed in Liquid Variables for Custom Templates; metafields are covered in Using Metafields in Templates. Order values are made safe for HTML before the template sees them, so a customer's input never becomes markup; comparisons see that safe form (an apostrophe is &#39;).

CSS for Documents

  • Change a block's look: find its class in the block's file, then style it in the CSS tab — for example .notes-body { font-style: italic; } or .items th { letter-spacing: 0.04em; }.
  • Prefer Template Settings for colours and fonts. The Head file applies them after your stylesheet and marks them important, so a colour or font picked there wins over your CSS; use CSS for what the settings do not cover.
  • Use relative sizes (em, rem, %) rather than fixed widths, so the page fits A4 PDFs and whatever paper the browser prints on.
  • Page breaks: .totals { break-inside: avoid; } keeps the totals on one page; break-before: page; starts a block on a new page.
  • Print only: put rules inside @media print { … } to change the printed page but not the preview.
  • Web fonts and other stylesheets: an @import url(…); at the very top of the CSS tab is loaded in the preview, prints and PDFs.

What Does Not Run

Scripts in a template never run: not in the preview, not in a print and not in the PDF. Build everything with Liquid, HTML and CSS. A Liquid error disables Save until it is fixed; the banner names the line and column, and the app refuses to save a template whose Liquid does not render.

Starting Over

There is no undo for code once it is saved. Before a big change, copy the file's code somewhere safe; a fresh start is always one Customize away on the built-in theme.

Was this guide missing something? Tell us and we will fix it.

Contact Us