KoderSolution Logo
HomeArticlesTutorialsForumAI LabRun Code
KoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Engineering Newsletter

Join 100,000+ engineers receiving curated high-signal content weekly.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
▲

Next.js

Topic Hub & Articles

Next.js Intro

10 min

Recap Quiz

5 Questions

Next.js Installation

10 min

Next.js Routing

10 min

Next.js Pages

10 min

Recap Quiz

5 Questions

Next.js App Router

10 min

Next.js Layouts

10 min

Next.js Linking and Navigating

10 min

Recap Quiz

5 Questions

Next.js Loading UI and Streaming

10 min

Next.js Error Handling

10 min

Next.js Data Fetching

10 min

Recap Quiz

5 Questions

Next.js Server Actions

10 min

Next.js Rendering

10 min

Next.js CSS Modules

10 min

Recap Quiz

5 Questions

Next.js Image Optimization

10 min

Next.js Font Optimization

10 min

Next.js Script Optimization

10 min

Recap Quiz

5 Questions

Next.js Static File Serving

10 min

Next.js Metadata

10 min

Next.js API Routes

10 min

Recap Quiz

5 Questions

Next.js Middleware

10 min

Next.js Authentication

10 min

Next.js Deployment

10 min

Recap Quiz

5 Questions

Next.js Internationalization

10 min

Next.js Security

10 min

Next.js Performance

10 min

Progress
0%

0 / 25 Lessons

Next.jsNext.js Tutorial
Lesson

Next.js Metadata

10 min reading
Free Course

Next.js Metadata: Managing SEO Page Titles, Open Graph, and Metadata API

Next.js Metadata guides developers through setting page titles, description tags, and social media Open Graph cards using the Metadata API.

Next.js manages document head tags using exported static objects or dynamic metadata functions inside page.tsx and layout.tsx files.

Static Metadata Definitions

Export a static metadata object from any layout.tsx or page.tsx file:

// app/about/page.tsx
import { Metadata } from 'next';

export const metadata: Metadata = {
  title: 'About Us | My Application',
  description: 'Learn more about our team, vision, and technology stack.',
  openGraph: {
    title: 'About Us | My Application',
    description: 'Learn more about our team and vision.',
    images: ['/images/about-og.jpg'],
  },
};

export default function AboutPage() {
  return (
    <div className="p-6">
      <h1 className="text-2xl font-bold">About Our Company</h1>
    </div>
  );
}

Dynamic Metadata Generation

For dynamic routes like blog posts or product listings, export an async generateMetadata function:

// app/products/[id]/page.tsx
import { Metadata } from 'next';

interface Props {
  params: Promise<{ id: string }>;
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const { id } = await params;
  const product = await fetch(`https://api.example.com/products/${id}`).then((res) => res.json());

  return {
    title: `${product.title} - Online Store`,
    description: product.summary,
    openGraph: {
      title: product.title,
      images: [product.imageUrl],
    },
  };
}

export default async function ProductPage({ params }: Props) {
  const { id } = await params;
  return <div>Viewing product ID: {id}</div>;
}

Dynamic Sitemap and Robots Files

Create sitemap.ts inside app/ to generate a dynamic XML sitemap automatically:

// app/sitemap.ts
import { MetadataRoute } from 'next';

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  return [
    {
      url: 'https://example.com',
      lastModified: new Date(),
    },
    {
      url: 'https://example.com/about',
      lastModified: new Date(),
    },
  ];
}

Best Practices

  • Set Metadata Base URLs: Configure metadataBase in your Root Layout to resolve relative social share image paths cleanly.
  • Inherit Parent Layout Metadata: Nested routes inherit metadata from parent layouts automatically; override only necessary fields.

Summary

The Next.js Metadata API provides type-safe control over SEO head tags and social share previews, ensuring search engine visibility across all application routes.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Recommended Courses & Books

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum