Start building

Guides

Add a size chart to Shopify without an app

The code is the small part. What decides whether this stays easy is where the chart's numbers live once you have forty products and three kinds of garment.

The Klorr teamUpdated 8 min read

  • Size chart
  • Product page
  • Metafields
  • No app

Key takeaways

  • Shopify has no metafields on a product type, because a product type is only a text field. A chart per type means matching on that text or referencing a shared metaobject.
  • Avoid pictures of tables. A real table can be read by a screen reader, enlarged, translated and corrected without opening an image editor.
  • On a phone, let the table scroll sideways with the size column pinned, and make the scroll area reachable by keyboard.
  • A plain link to #size-chart next to the variant picker can open a dialog, and still works as a jump to the table when JavaScript fails.

Before writing any code, pick where the numbers live. Change your mind later and you'll be re-entering every chart. Here are the realistic options, roughly from least to most work.

Where the chart livesEditing a chart meansWorks well forFalls down when
A page, shown with your theme's pop-up block (Dawn has one in the product section)Editing the pageOne chart for the whole storeYou need a different chart per product type, since the block points at one page per template
An image in the product descriptionRe-exporting and re-uploading an imageNothing, reallySomeone needs to read it on a phone, translate it, or fix a number
Section blocks matched on product type (this post's default)Editing one block in the theme editorUnder about ten charts, with product types kept tidyA type is too broad, such as one brand fitting differently within "Shirts"
A metaobject referenced by a product metafield (this post's override)Editing one entry under Content, and every linked product followsMany products sharing a few charts across brandsIt takes the most setup, and every product needs the reference filled in
A text metafield on each productEditing each productA handful of one-off itemsForty products share a chart, and one number changes

One thing trips people up when they search for "metafield per product type". Shopify doesn't have one. A product's type is a string on the product, so there's nothing to attach a metafield to. A chart per type therefore means either comparing that string in Liquid or pointing each product at a shared record. The section below does both: it checks for a metaobject reference first and falls back to a block whose type matches.

The complete section

Paste this in as a new section, following how to add a custom section to Shopify. It only offers itself on product templates, renders nothing when no chart applies, and needs no JavaScript to show the table. Rows are typed as text with | between cells, so a chart from a spreadsheet can be pasted with small changes.

sections/size-chart.liquid
{%- liquid
  assign chart_text = product.metafields.custom.size_chart.value.table.value
  assign chart_title = product.metafields.custom.size_chart.value.title.value
  assign active_block = nil
  if chart_text == blank and product.type != blank
    assign wanted = product.type | strip | downcase
    for block in section.blocks
      assign candidate = block.settings.product_type | strip | downcase
      if candidate == wanted and block.settings.rows != blank
        assign chart_text = block.settings.rows
        assign chart_title = block.settings.title
        assign active_block = block
        break
      endif
    endfor
  endif
  if chart_title == blank
    assign chart_title = section.settings.heading
  endif
-%}

{%- if chart_text != blank -%}
  <div id="size-chart" class="sc-{{ section.id }}" {% if active_block %}{{ active_block.shopify_attributes }}{% endif %}>
    <div data-chart>
      <h2 class="sc-title">{{ chart_title | escape }}</h2>
      <div class="sc-scroll" role="region" aria-label="{{ section.settings.scroll_label | escape }}" tabindex="0">
        <table>
          {%- assign rows = chart_text | newline_to_br | split: '<br />' -%}
          {%- assign header_done = false -%}
          {%- for row in rows -%}
            {%- assign clean = row | strip -%}
            {%- if clean != blank -%}
              {%- assign cells = clean | split: '|' -%}
              {%- if header_done == false -%}
                <thead>
                  <tr>
                    {%- for cell in cells -%}<th scope="col">{{ cell | strip | escape }}</th>{%- endfor -%}
                  </tr>
                </thead>
                <tbody>
                {%- assign header_done = true -%}
              {%- else -%}
                <tr>
                  {%- for cell in cells -%}
                    {%- if forloop.first -%}
                      <th scope="row">{{ cell | strip | escape }}</th>
                    {%- else -%}
                      <td>{{ cell | strip | escape }}</td>
                    {%- endif -%}
                  {%- endfor -%}
                </tr>
              {%- endif -%}
            {%- endif -%}
          {%- endfor -%}
          </tbody>
        </table>
      </div>
      {%- if section.settings.note != blank -%}
        <p class="sc-note">{{ section.settings.note | escape }}</p>
      {%- endif -%}
    </div>

    <dialog class="sc-dialog" data-size-dialog aria-label="{{ chart_title | escape }}">
      <button type="button" class="sc-close" data-size-close>{{ section.settings.close_label | escape }}</button>
      <div data-size-slot></div>
    </dialog>
  </div>
{%- endif -%}

{%- if request.design_mode -%}
  {%- for block in section.blocks -%}
    {%- unless block.id == active_block.id -%}
      <p {{ block.shopify_attributes }} style="margin:0;padding:6px 16px;font-size:12px;opacity:.6">
        Chart for "{{ block.settings.product_type | escape }}" doesn't apply to this product.
      </p>
    {%- endunless -%}
  {%- endfor -%}
{%- endif -%}

<style>
  .sc-{{ section.id }} {
    max-width: 800px;
    margin: 0 auto;
    padding: 32px 16px;
    color: {{ section.settings.ink }};
  }
  .sc-{{ section.id }} table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
  .sc-{{ section.id }} th, .sc-{{ section.id }} td {
    padding: 10px 14px;
    border-bottom: 1px solid {{ section.settings.line }};
    text-align: left;
    white-space: nowrap;
  }
  .sc-{{ section.id }} .sc-scroll { overflow-x: auto; }
  .sc-{{ section.id }} .sc-scroll:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
  .sc-{{ section.id }} tr > th:first-child {
    position: sticky;
    left: 0;
    background: {{ section.settings.background }};
  }
  .sc-{{ section.id }} .sc-note { margin: 12px 0 0; font-size: 14px; }
  .sc-{{ section.id }} .sc-dialog {
    width: min(720px, calc(100vw - 24px));
    padding: 20px;
    border: 0;
    border-radius: 12px;
    background: {{ section.settings.background }};
    color: {{ section.settings.ink }};
  }
  .sc-{{ section.id }} .sc-dialog::backdrop { background: rgba(0, 0, 0, .5); }
  .sc-{{ section.id }} .sc-close {
    float: right;
    min-height: 44px;
    padding: 0 12px;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
  }
</style>

<script>
  (function () {
    // No chart for this product: hide any link pointing at it.
    if (!document.getElementById('size-chart')) {
      document.querySelectorAll('a[href="#size-chart"]').forEach(function (a) { a.hidden = true; });
    }
    if (window.sizeChartBound) return;
    window.sizeChartBound = true;
    // Bound to the document and looked up on click, so a re-rendered section still works.
    document.addEventListener('click', function (event) {
      var root = document.getElementById('size-chart');
      if (!root) return;
      var dialog = root.querySelector('[data-size-dialog]');
      if (event.target.closest('a[href="#size-chart"]') && dialog.showModal) {
        event.preventDefault();
        dialog.querySelector('[data-size-slot]').innerHTML = root.querySelector('[data-chart]').innerHTML;
        dialog.showModal();
      } else if (event.target.closest('[data-size-close]') || event.target === dialog) {
        dialog.close();
      }
    });
  })();
</script>

{% schema %}
{
  "name": "Size chart",
  "tag": "section",
  "limit": 1,
  "enabled_on": { "templates": ["product"] },
  "settings": [
    { "type": "text", "id": "heading", "label": "Default heading", "default": "Size chart" },
    { "type": "text", "id": "note", "label": "Note under the chart", "default": "Body measurements in cm. Between sizes? Take the larger one." },
    { "type": "text", "id": "close_label", "label": "Close button", "default": "Close" },
    { "type": "text", "id": "scroll_label", "label": "Label for screen readers", "default": "Size chart, scrolls sideways" },
    { "type": "color", "id": "background", "label": "Background", "default": "#ffffff" },
    { "type": "color", "id": "ink", "label": "Text", "default": "#1a1a1a" },
    { "type": "color", "id": "line", "label": "Row lines", "default": "#e4e4e4" }
  ],
  "blocks": [
    {
      "type": "chart",
      "name": "Chart for a product type",
      "settings": [
        { "type": "text", "id": "product_type", "label": "Product type", "default": "Shirts", "info": "Must match the product's type. Capitals don't matter." },
        { "type": "text", "id": "title", "label": "Heading", "default": "Shirt sizes" },
        {
          "type": "textarea",
          "id": "rows",
          "label": "Rows",
          "info": "One row per line, cells separated by |. The first line is the header.",
          "default": "Size | Chest | Waist | Sleeve\nS | 88-94 | 74-80 | 61\nM | 94-100 | 80-86 | 62\nL | 100-106 | 86-92 | 63\nXL | 106-114 | 92-100 | 64"
        }
      ]
    }
  ],
  "presets": [
    { "name": "Size chart", "blocks": [ { "type": "chart" } ] }
  ]
}
{% endschema %}

Opening it from beside the variant picker

A section sits between other sections, and a size question comes up in the buy box, which belongs to the product section. To connect them, add a small link inside the product section. In Dawn and most themes built on it, that means adding a Custom Liquid block and moving it under the variant picker:

markup.html
<a href="#size-chart">Size chart</a>

The script above catches that click, copies the table into a native <dialog> and opens it, which handles Esc and focus for you. If the script fails or the browser lacks dialog, the link simply jumps down the page to the table. On a product with no chart the script hides the link, so place the size chart section below the product section, because the link has to exist before that check runs.

Setting up the shared chart

Skip this if matching on product type is enough for you. Use it when one type needs several charts, such as two brands that fit differently, or when you'd rather choose the chart on the product itself.

  1. Create a metaobject definition

    In Settings › Metafields and metaobjects, add a metaobject definition called Size chart with two fields: title (single line text) and table (multi-line text). Those keys are what the section reads.

  2. Add your entries

    Under Content › Metaobjects, add one entry per chart, for example "Men's shirts, regular fit", with rows typed the same way as in the block. Keep each entry's status active.

  3. Create the product metafield

    Under the same settings, add a product metafield definition with namespace and key custom.size_chart, of type metaobject reference, pointing at Size chart.

  4. Link the products

    On a product, pick the chart in its Size chart metafield. For many products, Shopify's bulk editor can show metafield columns, so check whether it handles this one in your admin before doing them by hand.

  5. Check a product of each kind

    Open a product with a linked chart, one that falls back to a block, and one with neither. The third should show no section and no link.

Getting the table right on a phone

A five-column table doesn't fit a 390px screen at a readable size, and shrinking it until it fits is the common mistake. Three lines in the stylesheet do most of the work:

  • overflow-x: auto on the wrapper, so the table scrolls by itself and the page doesn't.
  • white-space: nowrap on cells, so "88-94" never breaks across two lines.
  • position: sticky; left: 0 on the first cell of each row, with a background, so the size stays visible while the numbers scroll under it.

Sticky needs a solid background color: without one, the numbers show through as they pass underneath. The tabindex="0" and role="region" on the wrapper let a keyboard user reach the area and scroll it with arrow keys, and give a screen reader a name for it. Row and column headers use th with scope, so a screen reader announces "M, Chest, 94-100" and not three unrelated values.

If most of your charts have seven or more columns, ask whether a shopper needs them all. Splitting tops and bottoms into separate charts usually removes half of them. Test on a real phone in portrait with your widest chart, because that's the case that decides whether this layout is enough.

When a table isn't enough

This section shows one unit. To serve both centimeters and inches you can type both into each cell ("88-94 cm / 35-37 in"), which is simple and wider, or keep two charts. Anything that converts or recommends needs more script. These three go further and show where each one fits:

A size table with a slider where a highlight glides to the row that fits and a switch between centimeters and inches
Size Chart Table (€4, or €3 with a plan) takes the same pipe-separated rows. Notice the highlight moving as the measurement slider changes, and the cm to inches switch rolling every figure over.
A tailor's tape measure dragged above a size chart, with fit questions in an accordion beside it
Sizing Guide Accordion (€5, or €4 with a plan) adds a draggable tape measure and sets fit questions beside the chart. Worth a look if your support inbox gets the same fit questions over and over.
A pair of jeans with a yellow tape unrolling across the waist and down the inseam to a recommended size
Tape Size Finder (€4, or €3 with a plan) is a recommender and doesn't show a full chart. Height, weight and fit go in and a size comes out, read from a size table you supply. It's built for jeans and trousers, so its usefulness depends on how good that table is.

An app is the better answer if you want fit recommendations based on other customers' purchases and returns, since that takes a database a theme section doesn't have. It's also worth it if you have hundreds of charts maintained by a team that needs an import tool. For a store with a handful of charts, a section with no app bill does the job, and for a layout your theme can't produce you can describe it to the Shopify Liquid code generator.

What to put in the chart

  • Say whether numbers are body measurements or garment measurements. A 92 cm chest means very different things in each, and this is the source of many sizing returns.
  • Include how to measure, in one line per measurement, where the question actually comes up.
  • Add a fit note for anything unusual: "runs small, size up" is more useful than one more column.
  • Use the same size labels as your variants. If the picker says "Medium" and the chart says "M", a shopper has to translate.
  • Keep your product types consistent. "T-Shirts", "T-shirts" and "Tee" are three types: the section ignores capitals, and it can't fix spelling.

Questions, answered

How do I add a size chart to Shopify without an app?

Add a section that renders a table from settings or metafields, then place it on your product template. The section in this post picks the chart by product type or a metafield, and a small link in the buy box opens it in a dialog. On Dawn, a quicker option for a single chart is the product section's pop-up block pointed at a page containing the table.

Can I show a different size chart for each product type in Shopify?

Yes, though product types can't hold metafields since they are plain text on the product. Either compare product.type with a list of charts in Liquid, as this section's blocks do, or give each product a metafield referencing a shared metaobject.

How do I make a size chart table work on mobile?

Put the table in a wrapper with overflow-x set to auto, stop cells from wrapping, and make the first column sticky with a solid background. Add tabindex=0 and a label on the wrapper so keyboard users can scroll it too.

Should my Shopify size chart be an image?

It's better not to. An image can't be read by a screen reader, translated or enlarged cleanly, and each correction means a new export. Use an HTML table instead, even a simple one pasted into a page.

Why isn't my size chart showing on some products?

With this section, a chart shows only when the product has a linked metafield or its type matches a block. Check the product's type field for spelling and that the block has rows. Capitals are ignored, but extra words aren't, so "Mens Shirts" won't match "Shirts".

Get the whole section written for you

Describe the section you want. Klorr writes the Liquid, the CSS, the schema and every theme-editor setting — code that lives in your theme and stays yours.