completefrontend

Is Next.js good for SEO?

Next.js sends HTML with your content and tags already in it, and has built-in tools for titles, sitemaps, robots rules, and canonical addresses. Here's how it helps search, and the easy mistakes that undo it.

Title card: is Next.js good for SEO, with chips for the title tag, sitemap.xml, robots.txt, canonical, and JSON-LD

Picture walking past a shop. If you can see the shelves through the window, you know what it sells before you step inside. If the window is covered with a sign that says "the shelves appear once you come in", plenty of people walk on by. Search engines and link previews are those passers-by, and the first HTML a page sends is its window.

Yes, Next.js is good for SEO. It sends HTML with your content and your page's tags already in it, made on the server during the build or for each request, and it has built-in tools for titles, descriptions, sitemaps, robots rules, canonical addresses, and link previews. What it can't do is fill those in for you, and a few easy mistakes undo the benefit.

Why does the first HTML matter for SEO?

A search engine finds pages with a crawler: a program that downloads a page, follows its links, and downloads the pages they point to. What it reads first is the HTML your server sends.

A client-rendered React app, set up the way a new Vite app is, sends a nearly empty page with one <div id="root">. React draws the content in the browser once the JavaScript has run. Googlebot runs JavaScript, so it can still get there. Many other programs don't, like the bots that draw link previews in chat apps: they see an empty page. Next.js also keeps a list of what it calls HTML-limited bots, which may only look for a page's tags in the <head> of the first HTML. Bingbot, Slackbot, Twitterbot, facebookexternalhit, and Discordbot are all on it.

Two HTML responses side by side: a client-rendered React app sends one title for every page and a body with only an empty root div and a script, while Next.js sends the page's own title, description, and canonical link, and a body with the heading and the price already in it
What a crawler gets from each app

A Next.js page arrives with its heading, its text, and its links in the HTML, so every one of those programs sees the same page your visitors do. Why Next.js? shows both responses from a real app.

Which rendering is best for SEO in Next.js?

All of them put the content in the HTML. After next build, Next.js prints a symbol for each route:

  • ○ Static. The HTML was made once, during the build. It's ready the moment a crawler asks, and a CDN can keep a copy close to visitors.
  • ◐ Partial Prerender. A static shell was made during the build, and the parts that need the request are streamed in.
  • ƒ Dynamic. The page is made on the server for each request.

Streaming doesn't hide anything. The parts that arrive later are in the same HTML response, so a program that reads the whole response gets them too. And when a page's metadata waits for the request, Next.js makes HTML-limited bots wait for it, so the title is in the <head> for them. Rendering in Next.js explains how Next.js decides which symbol each page gets.

Client Components are fine too. A component that starts with "use client" still has its HTML made on the server. What's missing from the first HTML is anything that only appears after the JavaScript runs: data a Client Component fetches in an Effect, or a component loaded with next/dynamic and ssr: false.

What SEO tools does Next.js give you?

Each job has its own place, and Next.js writes the tags or the files for you:

Job Where it goes in Next.js
Title and description A metadata object, or generateMetadata for data, in a layout or a page
Link previews openGraph in the metadata, and an opengraph-image file for the picture
A list of every page app/sitemap.ts, served as /sitemap.xml
Rules for crawlers app/robots.ts, served as /robots.txt
A page's main address alternates.canonical in the metadata, with metadataBase in the root layout
What a page is about A JSON-LD script in the page
Missing pages notFound(), which answers 404 and adds a noindex tag

Here's a tea page that sets its own title and canonical address from its data:

import type { Metadata } from "next";
import { getTea } from "@/lib/teas";

type Props = { params: Promise<{ id: string }> };

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const { id } = await params;
  const tea = await getTea(id);
  return {
    title: tea ? tea.name : "Tea not found",
    alternates: { canonical: `/teas/${id}` },
  };
}

Next.js calls generateMetadata with the same params the page gets, and writes a <title> and a <link rel="canonical"> into the page's <head>. With metadataBase set in the root layout, the canonical link becomes a complete address. The Metadata API, sitemaps, robots and structured data, and Open Graph images lessons teach each tool with a recorded app.

Speed counts too. Google Search uses the Core Web Vitals, among many other signals, and next/image and next/font help keep them good: images in the right size, and text that doesn't jump when its font arrives. Core Web Vitals in Next.js shows how to measure them and fix a slow one, and SEO and Core Web Vitals explains how they fit into search.

What SEO mistakes are easy to make in Next.js?

Each of these builds and runs without an error, except the second, and each one quietly costs you:

  1. Loading the main content in an Effect. A heading or product list that a Client Component fetches after load isn't in the first HTML. Load it in a Server Component instead.
  2. Exporting metadata from a "use client" page. The build stops. Keep the page a Server Component, and move the interactive part into a Client Component of its own.
  3. Setting a page's title but not its link preview. A page's openGraph replaces the layout's whole object, and a page without one inherits the layout's. If the layout sets openGraph.title, every page without its own openGraph shows that title in its preview. Give each page its own, and copy the shared fields in with spread.
  4. Putting the canonical address in the root layout. It merges down to every page, so each page says its main address is the home page. Set it in each page.
  5. Hiding a page with Disallow in robots.txt. That only asks crawlers to skip it. To keep a page out of results, set robots: { index: false } in its metadata, and don't also disallow it, or crawlers never read that tag.
  6. Using new Date() for every date in the sitemap. Every page then looks changed on every request, and the sitemap is made again each time. Use the dates your data already has.
  7. Calling notFound() after the page has started streaming. The status has already gone out as 200, so Next.js adds a noindex tag instead. When a missing page must answer a real 404, check before the first Suspense, or in proxy.ts. Not found, forbidden and unauthorized shows both cases.

Is a plain React app bad for SEO?

Not always. It depends on who needs to read the page. A dashboard behind a login doesn't need search at all, since search engines never sign in. A public page that should rank, or that people share in chat apps, needs its content and tags in the first HTML. That's where a framework like Next.js earns its place. Why Next.js? has a whole section on when a plain React app is enough.

Where to go next

Start with the Metadata and SEO lessons in the Next.js course, then practice them in the Next.js practice problems: titles, descriptions, and social cards for tea pages, a sitemap built from the data, and product structured data. To check what you'd say in an interview, try when to use metadata or generateMetadata from the Next.js interview questions.

Written by Shrikanth PS

Senior Software Engineer at Microsoft, working on Copilot Enterprise, with more than nine years in frontend engineering.