Skip to main content
Next.js provides two ways to define metadata (such as <title> and <meta> tags): a static metadata export and an async generateMetadata function. Both are Server Component-only exports from layout.tsx or page.tsx.

Static metadata object

Export a Metadata object for static, non-dynamic metadata:
layout.tsx

generateMetadata function

Use generateMetadata when metadata depends on dynamic information such as route params or external data:
app/products/[id]/page.tsx

Parameters

object
An object containing the current route’s parameters:
  • params (Promise<object>) — Dynamic route parameters from root to the current segment.
  • searchParams (Promise<object>) — The current URL’s search params. Only available in page.js.
ResolvingMetadata
A promise resolving to the metadata from parent route segments. Use to extend rather than replace parent values.

Returns

A Metadata object (or a Promise<Metadata> for async functions).

Good to know

  • Only Server Components can export metadata or generateMetadata.
  • You cannot export both from the same route segment.
  • fetch requests inside generateMetadata are automatically memoized.
  • File-based metadata takes priority over metadata or generateMetadata.
  • redirect() and notFound() can be called inside generateMetadata.

Metadata fields

title

You can also use an object for templates:
app/layout.tsx
app/about/page.tsx
Use title.absolute to override parent templates:

description

metadataBase

Set a base URL for all relative URL fields:
app/layout.tsx

openGraph

twitter

robots

icons

Prefer the file-based metadata API for icons when possible.

manifest

alternates

verification

other (custom tags)

Behavior

Evaluation order

Metadata is evaluated from the root segment down to the closest page.tsx:
  1. app/layout.tsx (root layout)
  2. app/blog/layout.tsx (nested layout)
  3. app/blog/[slug]/page.tsx (page)

Merging

Metadata objects from multiple segments are shallowly merged. Duplicate keys are replaced by the value from the deepest segment. Nested objects like openGraph are replaced entirely (not merged).

Streaming metadata

Next.js 15.2+ supports streaming metadata: the initial UI is sent to the browser without waiting for generateMetadata to complete. For HTML-limited bots (e.g. Facebook’s crawler) metadata continues to block rendering. See htmlLimitedBots to configure this.

Version history