imgTag filter
The imgTag
filter is a helper method in Liquid, that will make it much easier to work with images in your template code.
It's always used together with an Image
input. It ouputs an img
tag, with height and a style attribute with both width and height set. This is the best practice for dealing with images with a fixed width. The url outputted in the src tag, will be the resized version of the image, served from a CDN.
We use Cloudflare's Image Optimization behind the scenes. It can be useful to their docs, to learn more about the arguments and behaviour.
Basic example
Additional arguments
width
- Overwrites the width provided in Image input options and uses this value for resizingheight
- Sets the height explicitly and resizes based on this, depending onfit
argument.dpr
- Overwrites the dpr provided in Image input options and uses this value for resizing.fit
- Affects interpretation of width and height. All resizing modes preserve aspect ratio. Read about the options here.background
- Sets a background color for the resulting image, used together withfit=pad
.style
- Adds additional values to thestyle
attribute of the outputtedimg
tag.class
- Adds aclass
attribute to the outputtedimg
tag with the classes specified here.altText
- Addsalt
attribute to outputtedimg
tag
Advanced example
Last updated