
Using the powerful Eleventy Image plugin, we have three ways to optimize images: HTML Transform, Markdown syntax, and a Nunjucks shortcode.
HTML Transform
Transforms any <img>
or <picture>
tags in HTML files as a post-processing step. Find the default settings directly in eleventy.config.js
.
<img src="./co-located-image.jpg" alt="alt text">
<img src="/assets/images/tutos/pexels-timmossholder.jpg" alt="alt text">
We can pass in overrides for every instance and use attributes. By default all images are set to be lazy loaded, but we can override this by directly setting loading="eager"
and decoding="sync"
on the <img>
element.
Another thing to note is the widths: ['auto']
setting, which by default only includes the original size image. You can set the dedicated widths
to be used by adding eleventy:widths="800,1200"
on the element. For images with Markdown syntax, I set fixed widths
so we don’t need to set a value on every instance.
sizes
defaults to auto
, which is applied to all lazy loading images. For eager-loading images, the value is equivalent to 100vw
See: https://github.com/whatwg/html/pull/8008. We can still overwrite this, by setting the sizes
attribute directly on the <img>
element, with something specific like sizes="(max-width: 615px) 50vw, 100vw"
.
<img eleventy:ignore src="./path/to/image.jpg" alt="alt text" class="half" loading="eager" decoding="sync">
More info: https://www.11ty.dev/docs/plugins/image/#html-transform.Bâtard de ciarge de cul de batince de viande à chien de saintes fesses de mautadine d’astie de géritole de baptême.
Purée de verrat de cimonaque de colon de viande à chien de cossin de tabarouette de baptême de charrue de tabarslaque.
Sacréfice de batince de charrue de patente à gosse de cul de sainte-viarge de sacristi de colon de torrieux de viande à chien.
Enfant d’chienne de sainte-viarge de mosus de saint-sacrament de câliboire de mangeux d’marde de cibouleau de tabarnouche d’ostie de crime.
Bâtard de boswell de purée de verrat de Jésus de plâtre de marde de crucifix d’enfant d’chienne de caltor de viande à chien.
Viarge de cochonnerie de saint-ciboire de sainte-viarge de crisse de colon d’ostie de batince d’ostifie de bâtard.
Torrieux de calvinouche de maudite marde de sacréfice de câliboire de crisse de câlisse de cimonaque de viande à chien de saint-cimonaque.
Markdown syntax
This also uses Image HTML Transform .
The markdown sytnax for images creates the <img>
element the plugin is looking for, and then transforms it to the <picture>
element (if more than one format is set).
In src/_config/plugins/markdown.js
I customized the Markdown rendering for images slightly. What normally would become a title
attribute is used to create a caption. Note that I set a fixed widths
value instead of auto
as the default.

 'Get Up and Boogy'
widths
, have the image eagerly loaded, or add a class etc. Saintes fesses de cibole de mosus d’étole d’enfant d’chienne de calvaire de sainte-viarge de crucifix de mautadine de purée. Marde de saint-ciboire de gériboire de maudit de cibolac de patente à gosse de saint-cimonaque de sacristi de cimonaque de baptême.
Mosus d’enfant d’chienne de cimonaque de saintes fesses de verrat de batince de cul de calvinouche de charrue de marde.
Câlisse d’enfant d’chienne de cimonaque de sacristi de ciarge de colon de batèche de sapristi de christie de saintes fesses.
{attrs}
{decoding="sync" eleventy:widths="1000" class="full"}
More: