Course map
Stage 1: App Router Foundations
Stage 2: The Rendering Model
Stage 3: Data, Caching and Mutations
Stage 4: Full-Stack Next.js
Stage 5: Production and Specialization

Part 04 / Topic 1 of 8

Static metadata, and how title templates cascade

A static metadata export works in a layout.tsx or a page.tsx — the installed package's own getting-started guide is blunt about the mechanism: "Next.js will automatically generate the relevant <head> tags for your page." The root layout (harness/app/layout.tsx, Part 1) now carries this course's own metadata instead of create-next-app's defaults:

export const metadata: Metadata = {
  metadataBase: new URL("https://nextjs-step-by-step.test"),
  title: { template: "%s | Next.js Step by Step", default: "Next.js Step by Step" },
  description: "A hands-on Next.js 16 course, built and verified one part at a time.",
};

.test is an IANA-reserved domain suffix guaranteed never to resolve on a real network — a safe placeholder metadataBase for a course that is never actually deployed, the same idea the reference material's own track.acme.test domain uses. metadataBase matters later in this part, for resolving the Open Graph image's URL (section 7).

harness/app/store/layout.tsx (Part 3) adds a second, nested title template, scoped to everything under /store:

export const metadata: Metadata = {
  title: { template: "%s | Apna Bazaar", default: "Apna Bazaar" },
  description: "Shop handmade pottery, textiles and kitchenware from Jaipur, Varanasi and Chennai.",
};

And a leaf page can set its own plain string title, which runs through the nearest ancestor's template:

// app/store/(shop)/products/page.tsx
export const metadata: Metadata = {
  title: "Full catalog",
  description: "Every product Apna Bazaar currently ships, from Jaipur pottery to Varanasi silk.",
};

Curled for real, across every page that got its own title in this part:

$ curl -s http://localhost:PORT/ | grep -o '<title>[^<]*</title>'
<title>Next.js Step by Step</title>
$ curl -s http://localhost:PORT/store/products | grep -o '<title>[^<]*</title>'
<title>Full catalog | Apna Bazaar</title>
$ curl -s http://localhost:PORT/store/about | grep -o '<title>[^<]*</title>'
<title>About | Apna Bazaar</title>
$ curl -s http://localhost:PORT/store/contact | grep -o '<title>[^<]*</title>'
<title>Contact | Apna Bazaar</title>

Each leaf's plain string title ("Full catalog", "About", "Contact") was formatted through app/store/layout.tsx's template — /store is their nearest ancestor that defines one — never through the root's.

Now the subtle part, found by testing /store itself, which has no metadata export of its own:

$ curl -s http://localhost:PORT/store | grep -o '<title>[^<]*</title>'
<title>Apna Bazaar | Next.js Step by Step</title>

Not "Apna Bazaar" alone. The store layout's own default: "Apna Bazaar" is a fallback for pages below it that set no title, but that fallback is not run through the same layout's own template — a template only formats a title coming from further down the tree, never the title the current layout is itself supplying as a default. So "Apna Bazaar" bubbles up as the current title string, unformatted by its own layout, and the next ancestor with a template — the root — formats it instead, producing "Apna Bazaar | Next.js Step by Step". This is a real, tested result, not a guess from the docs: it is the one case in this section where two different layouts' metadata genuinely interact rather than the nearest one simply winning.

Full files: examples/01-root-layout-metadata-and-fonts.tsx, examples/02-store-layout-metadata.tsx, examples/04-products-static-metadata.tsx, examples/05-about-static-metadata.tsx.

Done here? The practice set for Part 4 — including the solutions — is on the part page.

Search the guide