Image Tag
You get an HTML <img> tag for an image URL. Use it after image_url.
liquid
{{ image | image_url: width: number | image_tag: options }}Options
| Option | Type | Description |
|---|---|---|
alt | string | The alt attribute. When you do not set it, an empty alt attribute is added. |
width | number | The width attribute. When you do not set it, the width of the URL is used. Set it to nil to remove the attribute. |
height | number | The height attribute. When you do not set it, the height of the URL is used. Set it to nil to remove the attribute. |
widths | string | The widths of the srcset, separated by commas. Widths larger than the width of the URL are not used. |
srcset | string | A srcset to use instead of the generated one. Set it to nil to remove the attribute. |
sizes | string | The sizes attribute. |
Every other option is added as an attribute of the tag, with the same name, for example class, loading or fetchpriority. All values are escaped.
Srcset
When a width is set in the URL, a srcset is added. These widths are used, up to the width of the URL: 352, 832, 1200, 1920, 2560, 3840. The width of the URL is always added. With widths, your widths are used instead.
When a width and a height are set in the URL, the height of each srcset entry is changed in the same ratio.
Example
liquid
{{
section.settings.image
| image_url: width: 1000
| image_tag: widths: '400, 800', sizes: '100vw', class: 'banner', loading: 'lazy'
}}Output
html
<img src="https://cdn.youcan.shop/stores/acme/hat.png?width=1000" alt="" srcset="https://cdn.youcan.shop/stores/acme/hat.png?width=400 400w, https://cdn.youcan.shop/stores/acme/hat.png?width=800 800w" width="1000" sizes="100vw" class="banner" loading="lazy">