Application-wide sharing image
A site needs a default social preview for all pages.
Next.js 16+ · Directive
The opengraph-image convention sets the Open Graph preview image for an App Router route segment. Use a supported image file for static metadata or a JavaScript, TypeScript, or TSX file to generate the image.
Place a static image or a code-based file named opengraph-image in an App Router route segment. Next.js uses the most specific matching segment, serves the asset, and adds the corresponding Open Graph metadata to the document head. Code-based variants can return an ImageResponse and export image metadata such as alt text, dimensions, and content type.
app/**/opengraph-image.(jpg|jpeg|png|gif|js|ts|tsx)A static image asset or a generated image response used as the route segment's Open Graph image.
// app/blog/opengraph-image.tsx
import { ImageResponse } from 'next/og'
export const alt = 'Blog post'
export const size = { width: 1200, height: 630 }
export const contentType = 'image/png'
export default function Image() {
return new ImageResponse(
<div
style={{
fontSize: 64,
background: 'white',
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
Blog post
</div>,
)
}This route-specific file generates an Open Graph image with JSX and CSS for the /blog segment.
A site needs a default social preview for all pages.
A blog or product route needs its own preview artwork.
Preview text or branding depends on route data.
Different nested routes need distinct social previews.
Add an opengraph-image.jpg, .jpeg, .png, or .gif file to the relevant route segment. Next.js evaluates the convention and adds the appropriate Open Graph tags to the document head.
Follow-up: How would you make the image depend on route data? Create an opengraph-image.js, .ts, or .tsx file that default-exports a function returning an ImageResponse.
The route segment can contain a code-based opengraph-image file. Its default export generates the image, commonly by returning ImageResponse from next/og with JSX and CSS.
Follow-up: Which route wins when multiple images apply? The image located in the more specific, deeper segment takes precedence.
The convention supports .jpg, .jpeg, .png, and .gif image files. The generated-file form supports JavaScript, TypeScript, and TSX extensions.
Follow-up: What operational limit matters for static OG assets? An opengraph-image must not exceed 8 MB, or the build fails.
twitter-imageopengraph-image.alttwitter-image.altImageResponsegenerateImageMetadata