# Static Metadata

> Generating SEO tags with the Metadata API.

Subject: Next.js | Lesson 53 of 65 | 2 min read
Interactive lesson: https://codewithanimation.in/nextjs/static-metadata
Previous: [Third-Party Integrations](https://codewithanimation.in/nextjs/third-party-integrations.md) | Next: [Dynamic Metadata](https://codewithanimation.in/nextjs/dynamic-metadata.md)

## The Metadata API

Search Engine Optimization (SEO) requires injecting `<title>` and `<meta>` tags into the `<head>` of your HTML document.

In the Next.js App Router, you do this by simply exporting a static `metadata` object from any `page.tsx` or `layout.tsx` file.

## No More React Helmet

In standard React, developers relied on third-party libraries like `react-helmet` to inject SEO tags.

Because Next.js streams the HTML response from the server, it needs absolute control over the `<head>`. The Metadata API is deeply integrated with React's streaming architecture, ensuring that SEO tags are always sent to the browser before the body content begins.

## Implementation

1. Open a `page.tsx` or `layout.tsx` file.

2. Add: `export const metadata = { title: 'My Site', description: 'A great site' }`.

3. That's it. Next.js will automatically generate the corresponding `<title>` and `<meta name="description">` tags in the HTML.

## Common mistake: The Manual Head Trap

A common mistake for beginners migrating to the App Router is trying to manually render `<head>` and `<title>` elements inside their layout.

This will clash with the internal Metadata API and cause severe hydration mismatch errors.

## Try it: Object to HTML

Examine how the Next.js compiler takes a simple JavaScript object and automatically transforms it into standard HTML `<head>` tags.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/nextjs/static-metadata

## Check yourself

### Question 1

How do you define static SEO tags in a Next.js App Router page?

- A. Render a <title> element inside the return statement.
- B. Import the Next.js <Head> component.
- C. Export a static `metadata` object.
- D. Configure them in next.config.js.

Correct answer: C

Next.js uses a configuration-based approach. You simply export a constant named `metadata` and the framework handles injecting the actual HTML tags.

- Why not A: Never render manual title elements; it conflicts with the streaming architecture.
- Why not B: The next/head component is a legacy Pages Router feature. It does not work in the App Router.
- Why not D: Metadata is defined per-route inside the page or layout file, not globally in the config.

## Remember this

- Export a static `metadata` object from `page.tsx` or `layout.tsx` to set SEO tags.
- Do NOT manually render `<title>` or `<meta>` tags in your components.
- Do NOT use the legacy `next/head` component in the App Router.
- Metadata exported from a layout applies to all child pages, unless a child page overrides it.
