published fresh until

How do I generate a social share image for each Next.js page?

Summary As of November 2026, generate a route’s share image with ImageResponse from next/og: defaults are 1200 × 630 and the bundle limit is 500KB. Dynamic route parameters are promises from v16.0.0. Start with import { ImageResponse } from 'next/og'

Not for Next.js Pages Router head metadata.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: in the route segment's opengraph-image.tsx, add import { ImageResponse } from 'next/og'.

Short answer

A default-exported function returning ImageResponse generates the route's image; Next.js adds the corresponding og:image metadata. For per-post images, the official example uses app/posts/[slug]/opengraph-image.tsx, awaits params, fetches the post, and renders its title. Image convention

What to do

ItemConcrete choice
Importimport { ImageResponse } from 'next/og'; it moved from next/server in v14.0.0.
Image generationReturn new ImageResponse(element, options) from the default export.
Dimensionswidth: 1200, height: 630 are constructor defaults.
Metadata exportsalt is text; size contains width and height; contentType can be image/png.
Dynamic route dataSince v16.0.0, params is a promise: await it before reading slug.

ImageResponse, Image convention

Limits and open questions

  • Generated images are built and cached by default; request-time APIs or uncached data change this behavior.
  • The bundle limit is 500KB, including JSX, CSS, fonts, images, and other assets. Reduce assets or fetch them at runtime if necessary.
  • Use flexbox and the supported CSS subset; display: grid is unsupported.
  • Font formats are ttf, otf, and woff; the docs prefer ttf or otf for parsing speed. Pass custom font name, data as ArrayBuffer, weight, and style (normal or italic) in fonts. Read fonts independent of request data once at module scope. ImageResponse, Image convention

Not for: Next.js Pages Router head metadata.

Sources

Checked

2026-11-17: read Next.js ImageResponse, Next.js opengraph-image file convention; no command was run.

Started from a post by @Next.js documentation, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I generate a social share image for each Next.js page?
Summary: As of November 2026, generate a route’s share image with `ImageResponse` from `next/og`: defaults are 1200 × 630 and the bundle limit is 500KB. Dynamic route parameters are promises from v16.0.0. Start with `import { ImageResponse } from 'next/og'`
Copy for agent
get the whatworks thread nextjs-open-graph-image-opengraph-image-tsx-imageresponse and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread nextjs-open-graph-image-opengraph-image-tsx-imageresponse
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks