<head> tags for SEO, social sharing, and browser behavior. Next.js automatically generates the relevant HTML from the metadata you export.
The
metadata export and generateMetadata function are only supported in Server Components (layouts and pages).Default fields
Two<meta> tags are always added by Next.js, even when no metadata is defined:
Static metadata
Export ametadata object from a layout.tsx or page.tsx file:
Dynamic metadata
UsegenerateMetadata to fetch metadata that depends on route parameters or external data:
Avoiding duplicate data fetches
When the same data is needed in bothgenerateMetadata and the page component, use React’s cache to deduplicate the request:
Metadata fields
TheMetadata object supports the following commonly used fields:
Basic fields
Basic fields
The page title. Can be a plain string, or an object with
default, template, and absolute for title inheritance across layouts.Page description used by search engines.
Keywords for the page.
Page authors.
Canonical and alternate URLs.
OpenGraph
OpenGraph
Used by social platforms (Facebook, LinkedIn, Slack) to generate link previews.
Twitter card
Twitter card
Controls how your page appears when shared on X (formerly Twitter).
Robots
Robots
Instructs search engine crawlers.
Icons
Icons
Define favicons and Apple touch icons.
File-based metadata
Next.js supports special file conventions that generate metadata automatically:| File | Purpose |
|---|---|
favicon.ico | Browser tab icon |
icon.png / icon.svg | App icon |
apple-icon.png | Apple touch icon |
opengraph-image.jpg | OG image for social sharing |
twitter-image.jpg | Twitter card image |
robots.txt | Search crawler instructions |
sitemap.xml | Site URL map for crawlers |
app directory (or in a route segment folder for route-specific metadata).
Generated Open Graph images
Use theImageResponse constructor from next/og to generate dynamic OG images using JSX:
ImageResponse supports flexbox and a subset of CSS properties. Advanced layouts using display: grid are not supported. Test your OG images at the Vercel OG Playground.Streaming metadata
For dynamically rendered pages, Next.js streams metadata separately from page content, injecting it into<head> once generateMetadata resolves. This means visual content can start streaming before metadata is ready.
Streaming metadata is disabled for known bots and crawlers (e.g. Twitterbot, Bingbot) that expect metadata to be in the initial HTML. You can customize this behavior with the htmlLimitedBots config option.