Dynamic Metadata for SEO in Next.js

Last Updated : 11 Jul, 2026

Dynamic Metadata in Next.js enables page-specific metadata to be generated dynamically based on the content being displayed. This helps search engines and social media platforms present accurate information for dynamic pages such as blogs, products, documentation, and user profiles.

  • Creates page-specific metadata automatically.
  • Improves search engine indexing.
  • Generates richer social media previews.
  • Ensures metadata reflects the displayed content.

Importance of Dynamic Metadata for SEO

Dynamic metadata helps search engines and social media platforms display accurate information for every page, improving discoverability and content presentation.

  • Improves search engine indexing.
  • Provides unique titles and descriptions.
  • Enhances social media link previews.
  • Keeps metadata synchronized with changing content.

Common SEO Metadata

SEO metadata provides information about a webpage to search engines and social media platforms. Next.js supports various metadata fields that help improve search visibility and content presentation.

  • Title: Specifies the page title displayed in search engine results and browser tabs.
  • Description: Provides a brief summary of the page content for search engines and link previews.
  • Open Graph Metadata: Controls how pages appear when shared on platforms such as Facebook and LinkedIn.
  • Twitter Card Metadata: Defines how shared links are displayed on X (formerly Twitter).
  • Canonical URL: Indicates the preferred version of a page to prevent duplicate content issues.
  • Robots Metadata: Instructs search engines whether a page should be indexed or followed.

Note: These metadata fields can be defined statically or generated dynamically using the Next.js Metadata API.

Working of Dynamic Metadata

Dynamic metadata is generated when a page is requested. In Next.js, generateMetadata() creates page-specific metadata before rendering, ensuring accurate information is included in the HTML for search engines and social media platforms.

user_requests_a_page-
  • Receives a request for a page.
  • Uses generateMetadata() to generate page-specific metadata.
  • Includes the generated metadata in the HTML response.
  • Enables search engines and social media platforms to read the metadata.

Example: Dynamic Metadata Using generateMetadata()

This example uses generateMetadata() to generate a unique page title and description dynamically based on the requested blog post (slug).

JavaScript
// app/blog/[slug]/page.tsx

import type { Metadata } from "next";

const posts = {
  "nextjs-guide": {
    title: "Complete Next.js Guide",
    description: "Learn the fundamentals of Next.js App Router.",
  },
  "react-hooks": {
    title: "React Hooks Explained",
    description: "Understand useState, useEffect, and other React Hooks.",
  },
};

export async function generateMetadata({
  params,
}: {
  params: Promise<{ slug: string }>;
}): Promise<Metadata> {
  const { slug } = await params;
  const post = posts[slug];

  return {
    title: post?.title || "Blog",
    description: post?.description || "Blog post",
  };
}

export default async function BlogPost({
  params,
}: {
  params: Promise<{ slug: string }>;
}) {
  const { slug } = await params;
  const post = posts[slug];

  return (
    <main>
      <h1>{post?.title}</h1>
      <p>{post?.description}</p>
    </main>
  );
}

Visit:

http://localhost:3000/blog/nextjs-guide

and

http://localhost:3000/blog/react-hooks

Open View Page Source (crtl+u) to verify that generateMetadata() dynamically generates the page title and description.

Output:

Static Metadata Vs Dynamic Metadata

Here are some differences:

Static Metadata

Dynamic Metadata

Defined with fixed values in the application.

Generated based on page content or route data.

Remains the same for every request.

Changes according to the requested page.

Suitable for pages with fixed content.

Suitable for pages with dynamic or frequently changing content.

Uses predefined metadata values.

Uses route parameters or fetched data to generate metadata.

Requires manual updates when metadata changes.

Updates automatically as the underlying content changes.

Best for pages such as Home, About, or Contact.

Best for blogs, products, documentation, and user profiles.

Provides consistent metadata across all requests.

Provides unique metadata for each page to improve SEO.

Uses of Dynamic Metadata for SEO

Dynamic metadata is widely used in applications where each page requires unique SEO information based on its content.

  • Generate unique metadata for blog posts and articles.
  • Create page-specific metadata for product and e-commerce pages.
  • Improve SEO for user profiles and portfolio pages.
  • Display accurate previews when pages are shared on social media.
  • Optimize documentation and knowledge base pages for search engines.
  • Manage SEO efficiently across large applications with dynamic routes

Benefits of Dynamic Metadata for SEO

Dynamic metadata helps improve the visibility and relevance of web pages by generating metadata tailored to each page's content.

  • Improves search engine indexing with page-specific metadata.
  • Generates accurate previews for social media sharing.
  • Increases the visibility of dynamic content in search results.
  • Reduces duplicate metadata across pages.
  • Simplifies SEO management for dynamic applications.
  • Keeps metadata synchronized with page content automatically.

Also Check:

Comment

Explore