image_tag
Render a complete<img> tag with an optimized src, an automatic responsive srcset, and sensible defaults for alt, width, and height.
alt, width, and height attributes were not passed in — they come from the image itself. The srcset contains one entry per value in widths.
Size argument
The optional first argument sets the size used for thesrc URL. It accepts a size shortcut ('large', 'jumbo', …) or a custom size:
You can omit the size argument entirely and pass only named options.
Options
crop, scale, format, quality, and blur apply to the src URL and every srcset URL.
Any other named option — class, loading, style, id, data_*, and so on — is rendered as an HTML attribute. Underscores in attribute names become hyphens (data_index: '1' renders as data-index="1"), a true value renders as a boolean attribute, and false/nil values are omitted.
Automatic behavior
widthandheightattributes are set from the image’s natural dimensions when available, preventing layout shift.- If the image has a focal point configured, an
object-positionstyle is added so crops stay centered on the subject (merged with anystyleyou pass). - All attribute values are HTML-escaped.
- If the image is empty, nothing is rendered.
Usage examples
img_url
Generate an optimized image URL. Use this when you need just the URL — for example in a CSSbackground-image — rather than a full <img> tag.
image_tag: a size shortcut from the table below or a custom size ('400x300', '1024x', 'x600'), plus the same URL options (crop, scale, format, quality, blur).
Available sizes
Usage examples
Responsive images
For responsive<img> tags, prefer image_tag with widths and sizes — it builds the srcset for you. If you need manual control, you can still assemble one with img_url: