Table of Contents
Image Transform
Use Eleventy’s HTML Transform (eleventyImageTransformPlugin) to rewrite your <img> (and <picture>) into responsive markup with generated assets and caching.
This guide shows you how to wire the `eleventyImageTransformPlugin` plugin from `eleventy-img` alongside Baseline. Baseline does not ship this transform by default.
Prerequisites
- Eleventy 3.x and
@11ty/eleventy-imginstalled. site.urlset to your origin (no subpath).- Images referenced in your content or templates (local or remote).
Steps
-
@11ty/eleventy-imgis already required by Baseline; you can reinstall to ensure it’s present:npm install @11ty/eleventy-imgnpm install @11ty/eleventy-img -
Enable the HTML transform in
eleventy.config.js.import baseline, { config as baselineConfig } from './_baseline/eleventy.config.js'; import path from 'node:path'; import { eleventyImageTransformPlugin } from '@11ty/eleventy-img'; /** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */ export default async function (eleventyConfig) { eleventyConfig.addPlugin(baseline()); eleventyConfig.addPlugin(eleventyImageTransformPlugin, { urlPath: '/media/', outputDir: './dist/media/', formats: ['avif', 'webp', 'jpeg'], widths: [320, 640, 960, 1280], filenameFormat(id, src, width, format) { const extension = path.extname(src); const name = path.basename(src, extension); return `${name}-${width}w.${format}`; } }); } export const config = baselineConfig; -
Write plain
<img>in content.The transform rewrites
<img>to<picture>(with sources) at build time. Keepalton every image. Example in Markdown:## Image Transform Plugin <figure> <img src="/media/mountains.jpg" alt="Mountains at sunset" loading="lazy"> <figcaption> Example image rendered responsively with the Eleventy Image Transform plugin. </figcaption> </figure> -
Handle remote images and caching.
Remote
srcvalues are fetched and cached on disk. Ensure the build environment can reach them. Cache defaults come from the plugin; adjust if you need a different cache dir. -
Build and verify.
- Dev:
npx rimraf dist/ && npm run dev - Build:
npx rimraf dist/ && npm run build - Inspect rendered HTML: you should see
<picture>with multiple<source>tags and<img>including width/height. - Check generated files under
dist/media/.
- Dev:
Notes
- Keep
site.urlorigin-only; if you deploy under a subpath, setpathPrefixseparately. formatsorder matters; the first format is preferred by the browser.- Use
sizes(default from plugin) if you need custom responsive behavior; setsizesin the plugin options. - For advanced options (cache, returnType/htmlOptions, remote fetch), see the Eleventy Image docs.
Previous: Deploy Under a Subpath
Next: Multilingual Index