Table of Contents
Image shortcode
Baseline ships an image shortcode that wraps @11ty/eleventy-img to generate responsive <picture> markup.
What it does
- Generates multiple formats and widths, returns
<picture>+<img>; wraps in<figure>when a caption is provided. - Uses on-request transforms during
ELEVENTY_RUN_MODE=serve(viatransformOnRequest) to speed up dev startup. If it fails, retries without it. In build mode, errors throw immediately. - Adds
eleventy:ignorewheneleventyImageTransformPluginis present to avoid double-processing. This means you can use both the shortcode and the Image Transform plugin in the same project — the shortcode's output won't be rewritten by the transform.
Required
src— local path or remote URL. Throws an error if missing.alt— strongly recommended. A missingaltlogs a warning but doesn't break the build. Use an empty string for decorative images.
Defaults
- Widths:
320, 640, 960, 1280, 1920, 'auto' - Formats:
avif, webp(order matters) - Sizes:
(max-width: 768px) 100vw, 768px - Output:
urlPath: "/media/",outputDirderived from Eleventy's output directory (e.g../dist/media/) - Filenames:
name-hash-widthw.format(e.g.hero-a1b2c3-640w.avif). The hash is a 6-character content digest that prevents collisions when different source images share a filename. - Caption off unless
captionis set; when set, wraps in<figure>. - Adds
width/heightunlesssetDimensions: false.
Common options
caption,loading(lazy/eager),containerClass,imageClasswidths,formats,sizesoutputDir,urlPathattrs: extra attributes on<img>;classmerges withimageClassstyle: inline style on<img>. Separate fromattrs.style— if both are passed,attrs.styletakes precedence.figure(defaulttrue),setDimensions—figureonly has an effect whencaptionis also set.
Usage
{% image {
src: "/media/mountains.jpg",
alt: "Mountains at sunset",
caption: "Responsive image via Baseline",
widths: [320, 640, 960],
formats: ["avif", "webp", "jpeg"]
} %}
Notes
- Keep
site.urlset so generated URLs are correct when published. - If you use the HTML Image Transform plugin, Baseline still provides the shortcode; the transform focuses on rewriting existing
<img>in content. Use whichever fits the page.
Previous: Shortcodes
Next: Modules