What Are Metafields?
Metafields are custom data fields that extend the standard Shopify data model. By default, a product has a title, description, price, and images. But what if you also need to store materials, care instructions, certifications, or a table of nutritional values? That is where metafields come in.
Metafields consist of three parts: a namespace (a grouping identifier like "custom"), a key (the field name like "material"), and a value (the actual data). They were significantly improved in 2021 when Shopify introduced metafield definitions, allowing you to define typed fields with validation rules.
Metafields can be added to products, product variants, collections, customers, orders, blog posts, pages, and the shop itself. They are accessible via Liquid in your theme, via the Storefront API, and via the Admin API.
Creating Metafields
You create metafield definitions in your Shopify admin. This is different from adding values: you first define the field structure, then add values to individual products.
- 1Go to Settings, then Custom Data
The Custom Data section in Settings is where all metafield definitions live. Select the resource type you want to add fields to.
- 2Click Add definition
Give the field a name, a namespace (use "custom" for simplicity), and a key. The key is used in your Liquid code.
- 3Select the content type
Choose a type that matches your data: text, integer, decimal, true/false, date, colour, URL, file, product reference, or JSON.
- 4Add validation rules if needed
Text fields can have minimum/maximum length. Number fields can have min/max values. This prevents bad data entry.
- 5Save and populate
Once saved, the field appears in the product editor. Open any product and scroll down to find the metafields section at the bottom.
Metafield Types
Shopify supports a wide range of metafield content types. Choosing the right type ensures data is stored correctly and displayed properly in your theme.
- •Single-line text: Short strings, ideal for materials, country of origin, or short labels.
- •Multi-line text: Longer blocks of text, useful for care instructions or detailed specifications.
- •Integer and Decimal: Numeric values, good for weights, dimensions, or quantities.
- •True/False: Boolean flags, useful for things like "is vegan" or "is limited edition".
- •File: Upload images or documents directly to the metafield, great for product manuals or certifications.
- •Product reference: Link to another product, used for related products or bundled items.
Displaying in Your Theme
There are two ways to display metafields in your theme: using the theme editor, or by editing Liquid directly.
Modern Online Store 2.0 themes support metafields natively in the editor. You can add a metafield block to a product template and connect it to your definition without writing code. In the theme editor, add a block, select "Metafield", and choose the definition from the dropdown.
For older themes or more control, use Liquid. Access a product metafield with: {{ product.metafields.custom.material }}. Replace "custom" with your namespace and "material" with your key.
Use Cases
Fashion: Fit and Care Information
Store garment measurements, fabric composition, and care instructions per product. Display them in structured tabs on the product page without cluttering the main description.
Food and Drink: Nutritional Values
Store calories, macronutrients, ingredients lists, and allergen information as separate metafields. This keeps data structured and makes it easy to update without editing HTML.
Electronics: Technical Specifications
Store dimensions, weight, power requirements, compatibility, and certifications. Render them as a comparison table across multiple products.
Metafield Sets
Metafield sets (also called definitions) allow you to group related fields together. For example, a "nutrition" set might contain fields for calories, protein, carbs, and fat. This keeps your definitions organised, especially if you have dozens of custom fields.
Shopify also offers standard metafield definitions for common use cases. These follow a standardised schema that some apps and integrations recognise automatically. For example, the standard "product.care_instructions" definition is understood by Google Shopping feeds and some review platforms.