OG Images in Eleventy (11ty)

Eleventy gives you full control of your HTML and leaves the rest to you. There's no built-in Open Graph feature, so you add the tags to a layout yourself, and if you want a unique image per post you either make them by hand or generate them.

This guide covers adding the tags with Eleventy's data cascade, generating images at build time with an async shortcode and Satori, the honest trade-offs of that approach, and the alternative: computing a hosted Unfurlkit URL per page so there's nothing to generate.

Sources checked (Oct 2026): Eleventy docs for Computed Data (https://www.11ty.dev/docs/data-computed/) and Shortcodes, including async shortcodes and scoped data (https://www.11ty.dev/docs/shortcodes/). Satori's supported font formats are cross-checked against the Next.js ImageResponse docs, which use Satori (https://nextjs.org/docs/app/api-reference/functions/image-response).

Step 1: Absolute URLs and a base layout

og:image and og:url must be absolute. Put your production URL in global data:

Replace your-site.com with your own site.

// _data/site.js
export default {
  url: 'https://your-site.com',
  name: 'Example Blog',
};

Then add the tags to your base layout (Nunjucks shown):

{# _includes/base.njk #}
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>{{ title }} · {{ site.name }}</title>
  <meta name="description" content="{{ description }}">
  <meta property="og:title" content="{{ title }}">
  <meta property="og:description" content="{{ description }}">
  <meta property="og:type" content="article">
  <meta property="og:url" content="{{ site.url }}{{ page.url }}">
  <meta property="og:image" content="{{ ogImage }}">
  <meta property="og:image:width" content="1200">
  <meta property="og:image:height" content="630">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:image" content="{{ ogImage }}">
</head>
<body>
  {{ content | safe }}
</body>
</html>

page.url is Eleventy's site-relative URL for the current page, so prefixing site.url makes it absolute. Nunjucks escapes the output by default, which protects you from quotes in titles.

Step 2: Compute ogImage with the data cascade

You don't want to type ogImage into every post's front matter. Eleventy's Computed Data (eleventyComputed) runs at the end of the data cascade and can derive values from other data, including Eleventy-provided values like page. Per the docs, if you want JavaScript functions here you need a JavaScript data file (template, directory, or global). YAML and JSON front matter only support template strings.

A directory data file applies to everything in that folder:

// posts/posts.11tydata.js
export default {
  layout: 'base.njk',
  eleventyComputed: {
    ogImage: (data) => `${data.site.url}/og/${data.page.fileSlug}.png`,
  },
};

Posts can still override it: a post that sets ogImage in its own front matter wins, the way the data cascade normally works. Check the cascade docs for your version if overrides don't behave as expected.

Now every post points at /og/<slug>.png. Next you need to create those files.

Step 3 (DIY): Generate images at build time

Eleventy supports async shortcodes (addAsyncShortcode, and since v2.0 addShortcode also accepts async functions), and shortcodes can read the current page through this.page. You can use one to render a PNG with Satori and Resvg during the build.

npm install satori @resvg/resvg-js
// eleventy.config.js
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import satori from 'satori';
import { Resvg } from '@resvg/resvg-js';

const font = await readFile('./fonts/Inter-Bold.ttf'); // TTF/OTF/WOFF, not WOFF2

export default function (eleventyConfig) {
  eleventyConfig.addAsyncShortcode('ogImage', async function (title) {
    const slug = this.page.fileSlug;
    const svg = await satori(
      {
        type: 'div',
        props: {
          style: {
            width: '100%', height: '100%', display: 'flex',
            flexDirection: 'column', justifyContent: 'center',
            padding: 72, background: '#0b0d12', color: '#fff',
            fontFamily: 'Inter', fontSize: 64,
          },
          children: title,
        },
      },
      { width: 1200, height: 630, fonts: [{ name: 'Inter', data: font, weight: 700, style: 'normal' }] }
    );
    const png = new Resvg(svg).render().asPng();
    await mkdir('./_site/og', { recursive: true });   // match your output dir
    await writeFile(`./_site/og/${slug}.png`, png);
    return ''; // the shortcode prints nothing
  });
}

Call it once per post from the layout or the post template:

{% ogImage title %}

The honest trade-offs

This works, and it keeps everything inside one npx @11ty/eleventy run. Before you adopt it, know what it costs:

  • Build time grows with posts. Every build renders every image again unless you add your own caching, for example by skipping a file that already exists and whose title hash hasn't changed.
  • Writing into the output folder is a side effect. Eleventy didn't create those files, so watch mode, incremental builds, and output cleanup don't know about them. Make sure the output path matches your configured output directory.
  • Native dependency. @resvg/resvg-js ships platform-specific binaries, which can cause trouble in some CI images. A WASM build exists as a fallback.
  • Satori's CSS subset. It supports flexbox and absolute positioning but not grid, and elements with more than one child need display: flex. Fonts must be TTF, OTF, or WOFF, and WOFF2 isn't supported.
  • Design lives in code. Changing the card means editing JavaScript and rebuilding.

There are also community Eleventy plugins that wrap this pattern. They differ in maintenance and features, so check their recent releases before depending on one.

Step 3 (alternative): One URL with Unfurlkit

Change one line of computed data and delete the shortcode:

// posts/posts.11tydata.js
const ogUrl = (title) =>
  'https://unfurlkit.com/v1/basic.png?' + new URLSearchParams({ title: title || 'My Site', theme: 'dark' }).toString();

export default {
  layout: 'base.njk',
  eleventyComputed: {
    ogImage: (data) => data.ogImage ?? ogUrl(data.title),
  },
};

That's the whole integration. The layout from Step 1 doesn't change. You can remove satori, @resvg/resvg-js, the font file, and the og/ output folder.

The basic template accepts title (trimmed to 120 characters), subtitle (trimmed to 160), theme (dark or light), and accent (6-digit hex without #). Unknown parameters return 400.

Plans. Every image URL needs your key. A Free key gets 10 renders in total (no monthly reset), with a small "unfurlkit" watermark, and needs no card. Pro is $9/mo or $90/yr, with 10,000 renders a month, no watermark, and custom fonts (Inter, Roboto, Playfair Display, JetBrains Mono) and logo. Pro URLs add your public key k and a signature s. Eleventy builds run in Node, so you can sign inside the same computed-data function, reading the secret from an environment variable during the build. The secret never ships in the HTML. See Signing Pro URLs for the Node and Python snippets.

A render is counted only when a unique image is generated and wasn't already cached. Shares and cache hits don't count. Over the limit, images keep rendering. On a signed Free key, images already made keep showing, and new ones get a plain version (your title on the basic card, with the small mark) that doesn't count. Upgrade to Pro for more renders. Upgrade to Pro to remove watermarks from all your images.

What changes:

  • Builds stay fast. There's nothing to render at build time.
  • No native binaries in CI.
  • Titles and images stay in sync. Change the title, rebuild, and the URL (and therefore the image) changes.
  • Same pattern on your other sites, whatever they're built with.

Which option should you use?

Situation Use
One static image for the whole site A file in your passthrough-copied assets + site.url prefix
Small site, you enjoy owning the pipeline Async shortcode + Satori
Many posts, slow builds, or CI trouble with native deps Unfurlkit URL in computed data

Debugging checklist

  1. Build and view _site/<post>/index.html. Is og:image present and absolute? A path starting with / means site.url wasn't prefixed.
  2. Is ogImage empty? Computed data needs a JavaScript data file for functions. A function in YAML front matter won't run.
  3. DIY: do the PNGs exist in the output og/ folder after the build? If not, check that the shortcode is actually called on each page and that the output path matches your output directory.
  4. Open the image URL. It should return 200 with image/png. With Unfurlkit, a 400 points to an invalid parameter.
  5. Size limits. 1200×630 is a safe target. Meta documents an 8 MB maximum, LinkedIn 5 MB, and WhatsApp recommends under 600 KB. See the OG image size guide.
  6. Refresh platform caches with Meta's Sharing Debugger (https://developers.facebook.com/tools/debug/) and LinkedIn's Post Inspector (https://www.linkedin.com/post-inspector/).
  7. Check the deployed URL with the Free OG Image Checker. It shows previews for X, LinkedIn, Facebook, WhatsApp, Slack, Discord, and iMessage, and lists what to fix. We don't store the URLs you check.

FAQ

Which languages and scripts are supported? Right-to-left scripts such as Arabic and Hebrew aren't supported yet at launch.

Can I use Liquid instead of Nunjucks? Yes. The layout syntax shown is also close to valid Liquid, and computed data works the same with any template language.

Should I use page.fileSlug or the title in the image path? fileSlug is stable and URL-safe. Titles change and need escaping. For Unfurlkit URLs, the title goes in the query string and URLSearchParams handles the encoding.

How do I make images for tag or listing pages? Add the same computed data to those templates' data files, using the page's heading as the title.

Does this work with Eleventy's dev server? Yes. With Unfurlkit, the URL in the HTML is the production URL, so the image loads in local preview too, as long as you're online.

Summary

Eleventy makes the tags easy: one layout plus computed data. The images are the work. A build-time Satori shortcode is free and flexible but adds build time and dependencies, while a computed Unfurlkit URL keeps your build exactly as fast as it is today.

See Unfurlkit pricing · Check any page with the Free OG Image Checker.

Updated 2026-10-21

Try it freePricing