Eleventy Plugin Baseline

A magic carpet ride

Documentation — Table of Contents

Image Shortcode Basics

Render a responsive image with Baseline’s image shortcode (eleventy-img). You’ll add a source image, call the shortcode with alt/caption, see generated formats, and verify output in /dist/media/. Uses npm, Node 20.15.0+, and the same Baseline setup as earlier tutorials.

What you’ll build

Prerequisites

1) Add a sample image

Place an image at src/media/example.jpg. JPEG/PNG are fine.

2) Use the shortcode in a page

Create src/content/pages/image-demo.md:

---
title: "Image Shortcode Demo"
description: "Responsive image via Baseline shortcode"
permalink: "/image-demo/"
layout: "layouts/base.njk"
---

This page displays an image using the {% raw %}`{% image {} %}`{% endraw %} shortcode.

{% image {
  src: "/media/example.jpg",
  alt: "A descriptive alt text for accessibility",
  caption: "Example image rendered responsively with the image shortcode."
} %}

Defaults (from the shortcode):

The shortcode resolves the input directory automatically: a leading-slash path like /media/example.jpg maps to src/media/example.jpg. You can still pass a fully qualified path if you prefer.

3) Optional tweaks

4) Run and verify

npx rimraf dist/ && npm run dev

5) Production build

npx rimraf dist/ && npm run build

6) Notes

7) Optional: use the Image Transform plugin

If you prefer not to call the shortcode, you can add Eleventy’s Image Transform plugin to process all <img>/<picture> tags automatically. See the official Image plugin docs for configuration and trade-offs (e.g., transforms every image it finds, rather than opt-in shortcode usage).

Previous: Deployment URL Checks

Next: How-To’s