When beginning to build a theme or prototype, many developers use some form of placeholder text or image. This is usually because we want and need our design to feel real, authentic, and similar to the final product. The best way to do that is with real content, but when you don’t have access to real content—since that’s usually the last thing a client gives you—the next best alternative is to use placeholder images and text. Often we turn to solutions likeplaceholder.comor{placekitten}for images, andlorem ipsumor its many variations for text.
While images of kittens are pretty amazing, they don’t necessarily convey any information about the purpose of an image within your design. Luckily, Shopify has a built-in solution for your placeholder needs, especially when building Liquid templates and theme styles. This is what’s known as theplaceholder_svg_tag
filter, which takes a placeholder name and outputs a placeholder SVG illustration. In this article, you’ll learn how to use this tag in your theme development work.
Learning Liquid: Getting Started with Shopify Theming
Get this free guide and learn practical tips, tricks, and techniques to start modifying, developing, and building Shopify themes.
By entering your email - we’ll also send you marketing emails related to Shopify. You can unsubscribe anytime. Note: the guide won't be delivered to role-based emails, like info@, developer@, etc.
Why are placeholder images useful?
As was previously mentioned, when developing websites, you might not always have real content to use in the building stage. It’salways best to use real contentif you have it, but if that’s not possible, an alternative is to use placeholders. In these cases, we still need to build something, and often we already have a good idea of what the image dimensions are that we need to lay out in a theme design.
Placeholders can help us better understand and interpret how images and their layout will move, shape, resize, and reflow as the browser or device changes.
They are also helpful, when given a bit of context, to convey meaning about the intended content. For example, a placeholder image that shows a single product versus several products conveys to a client what the intended use of this image might be in the future, and what to replace it with.
You might also like:How We Improved Theme Development Tooling Using Checksums.
Using theplaceholder_svg_tag
filter
It’s really easy to use Shopify’s placeholder SVGs, since including them is a breeze with theplaceholder_svg_tag
filter.
Simply include the placeholder name, followed by theplaceholder_svg_tag
filter:
{{ 'product-1' | placeholder_svg_tag }}
The output is simply an inline SVG:
Image options
There are several types of SVG placeholder illustrations that you can render with theplaceholder_svg_tag
filter, including image, collection, lifestyle, and product.
You can see a preview of each placeholder name in the chart below, along with the preview of what they render:
Placeholder Name |
Preview |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You might also like:How to Use Math Filters with Liquid.
Adding a custom class
You can add a custom CSS class or classes to your SVG by passing a class parameter to theplaceholder_svg_tag
filter:
{{ 'product-1' | placeholder_svg_tag: 'my-custom-class' }}
To add more than one class to the SVG, simply add a space between them inside the class parameter:
{{ 'product-1' | placeholder_svg_tag: 'my-custom-class my-custom-class--two' }}
There are several important things to remember about class names:
- Similar to adding CSS classes to HTML elements, if you use spaces between class names, a web browser renders them as separate classes
- You should never start a class name with a number or dashes, as per theW3C specification
- Class names can only contain the characters
[a-zA-Z0-9]
andISO 10646
charactersU + 00 a0
and higher, plus the hyphen-
and the underscore_
- The best practice is to use
lowercase-separated-with-dashes
- Class names are case sensitive, so it’s best to avoid randomly capitalizing letters
- Use values that describe the nature of the content, rather than values that describe the desired presentation of the content, as per theW3C specification
Using placeholder images for all things !
To summarize, using theplaceholder_svg_tag
filter is as simple as knowing the placeholder name and where you’d like to output that image. Placeholder images help developers and designers test their work and provide context for themselves and their clients.
This is especially helpful when the final content for a website is unavailable. A placeholder image can communicate what type of image is intended to be shown in a particular place, and how it should layout, resize, and flow within the browser.
Start taking advantage of Shopify placeholder images today!
Grow your business with the Shopify Partner Program
Whether you offer web design and development services or want to build apps for the Shopify App Store, the Shopify Partner Program will set you up for success. Join for free and access revenue share opportunities, developer preview environments, and educational resources.
Sign up