# Gatsby SEO

> Use Gatsby

Canonical: https://scaplet.com/seo/gatsby

Guide Gatsby Gatsby · Framework guide

Use Gatsby's Head API for page metadata, verify generated HTML, and keep sitemap URLs aligned with published routes.

3 min

read

5

sources

Oct 24, 2026

updated

Scaplet Editorial Team

author

In one line

Use Gatsby's built-in `Head` export on pages and `createPage` templates to render page-specific title, description, canonical, and social metadata into generated HTML. Support for Head was added in gatsby@4.19.0; older projects need a compatible alternative. Set `siteUrl`, add `gatsby-plugin-sitemap`, then build and inspect both the generated HTML and the sitemap.

30-second check

## Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fgatsby%20(%22Gatsby%20SEO%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fgatsby%20(%22Gatsby%20SEO%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fgatsby%20(%22Gatsby%20SEO%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fgatsby%20(%22Gatsby%20SEO%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

On this page

## 3 parts, 3 minutes.

1. [Render metadata with Gatsby Head 01](#render-metadata-with-gatsby-head)
2. [Generate a sitemap from the production route set 02](#generate-a-sitemap-from-the-production-route-set)
3. [Check crawlability after the build 03](#check-crawlability-after-the-build)

_01_Checklist

## Render metadata with Gatsby Head

Gatsby's `Head` export adds page-specific tags to the generated HTML. Gatsby's docs say support was added in gatsby@4.19.0. The `Head` function receives `location.pathname`, `params` (for `matchPath` pages), `data` from the page's GraphQL query, and `pageContext`, which makes it useful for CMS-backed templates created with `createPage`. Valid tags inside it are `link`, `meta`, `style`, `title`, `base`, `script` and `noscript`.

First_2_
Export `Head` from the page or its `createPage` template. Gatsby's docs say you can only define it inside a page (templates for `createPage` included), not in a component.

Use page query data or `pageContext` for route-specific metadata. Add fallbacks for missing optional fields without repeating one generic title across every page.

Next_1_
Give tags an `id` when you need only one of them rendered: in a list of items with the same `id`, the last item wins and is used in the HTML.

Then_1_
For Gatsby versions older than 4.19.0, upgrade or use a metadata method that version supports. Editing `<html>` and `<body>` attributes from `Head` needs gatsby@5.5.0, and reading React Context from `wrapRootElement` needs gatsby@5.6.0.

A page-level Head export

```
export function Head({ data, location }) { const page = data?.contentfulPage const title = page?.seoTitle || page?.title || 'Example site' const description = page?.seoDescription || page?.summary const canonical = \`https://www.example.com${location.pathname}\` return ( <> <title>{title}</title> {description && <meta name="description" content={description} />} <link rel="canonical" href={canonical} /> </> ) }
```

**Check the built HTML**Run `gatsby build` and open the generated HTML (or view source on `gatsby serve`) to confirm each route has the intended title, description, and canonical before relying on browser-only inspection.

_02_How it works

## Generate a sitemap from the production route set

1. 1

### Set the production site URL

Define `siteUrl` in `siteMetadata` using the canonical [HTTPS](/glossary/https) origin. Gatsby's guide says it must be defined and not left empty; the plugin README says it is needed unless you set the `resolveSiteUrl` option.
2. 2

### Add the official Gatsby sitemap plugin

Install `gatsby-plugin-sitemap` and include it in the `plugins` array in `gatsby-config.js` or `gatsby-config.ts`.
3. 3

### Run a production build

Run `gatsby build && gatsby serve`; the plugin only generates output in production mode. By default it writes `sitemap-index.xml` at the site root, plus a new `sitemap-X.xml` for every 45000 URLs (`entryLimit`). Point [Search Console](/glossary/google-search-console) at `https://www.example.com/sitemap-index.xml`.
4. 4

### Compare sitemap URLs with deployed pages

Check representative static and CMS-generated routes. Remove drafts, previews, duplicates, and routes that redirect or return errors.

gatsby-config.js

```
module.exports = { siteMetadata: { siteUrl: 'https://www.example.com', }, plugins: ['gatsby-plugin-sitemap'], }
```

If your pages come from a CMS, confirm that the Gatsby build created them before expecting the sitemap plugin to list them. By default the sitemap includes all of the site's pages except those you exclude via `excludes`; `/dev-404-page`, `/404` and `/offline-plugin-app-shell-fallback` are always excluded. The default output gives every URL the same `changefreq` and `priority`, which Google ignores. The README recommends a custom `serialize` that supplies an accurate `lastmod`.

_03_Validate the page and route, not just the component

## Check crawlability after the build

Check

### [Rendered HTML](/glossary/rendered-html)

What good looks like

One accurate title, useful description, canonical, and main content in the page output

If it fails

Check Head export location, GraphQL data, and fallbacks

Check

### [Canonical URL](/glossary/canonical-url)

What good looks like

Absolute production URL for the intended page

If it fails

Check `siteUrl`, path normalization, and preview host configuration

Check

### Sitemap

What good looks like

Contains public canonical routes that return success

If it fails

Check production build, page creation, filters, and plugin configuration

Check

### JavaScript-dependent content

What good looks like

Important content and links appear in the rendered page

If it fails

Review [rendering](/glossary/rendering) and use [URL Inspection](/glossary/url-inspection-tool) to compare Google's fetched page

- Do not add a second SEO plugin until you have checked whether the Head API or existing components already emit the same tags.
- If `Head` is composed through shared utilities, keep a single source of truth for title, description, and canonical data.
- Use structured data only when it describes visible page content and meets Google's guidelines; test it after build output changes.
- Submit the sitemap in Search Console if you want processing diagnostics. Submission does not guarantee crawling or indexing.

See the [Gatsby Head API](https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-head/), [Gatsby sitemap guide](https://www.gatsbyjs.com/docs/how-to/adding-common-features/creating-a-sitemap/), [JavaScript SEO basics](/glossary/javascript-seo), and [Google sitemap submission](/seo/google-search-console/sitemap-submission).

Sources · 5

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- gatsbyjs.com
- github.com
- google.com

1. 01 [Gatsby Head API | Gatsby Docs](https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-head/) gatsbyjs.com · checked 2026-10-24
2. 02 [Creating a Sitemap | Gatsby Docs](https://www.gatsbyjs.com/docs/how-to/adding-common-features/creating-a-sitemap/) gatsbyjs.com · checked 2026-10-24
3. 03 [gatsby-plugin-sitemap README | GitHub](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-sitemap/README.md) github.com · checked 2026-10-24
4. 04 [JavaScript SEO basics | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics) developers.google.com · checked 2026-10-24
5. 05 [Build and submit a sitemap | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap) developers.google.com · checked 2026-10-24

Questions

## Asked a lot.

3 questions people ask next, answered from the sources on this page.

_01_ Does Gatsby have built-in SEO metadata?

Gatsby has a built-in Head export for adding elements to the document head of a page. Support was added in gatsby@4.19.0, so check the project version before using it.

_02_ Where should I add Gatsby meta tags?

Export a named `Head` function from a page or page template, including templates created with `createPage`. Use queried data or page context for page-specific values.

_03_ How do I generate a Gatsby sitemap?

Set `siteUrl` in `siteMetadata`, add `gatsby-plugin-sitemap`, and run a production build. The plugin writes `sitemap-index.xml` by default; check that its URLs resolve on the live site.

## Keep learning

[All platform guides](/seo)

[Learn Gatsby redirects Frameworks](/seo/gatsby/redirects) [Related Canonical URL Crawling and indexing](/glossary/canonical-url) [Read next Astro SEO Frameworks](/seo/astro) [Do Run a free site audit Free, about two minutes](/site-audit)

Nearby in platform guides
[Framer robots.txt](/seo/framer/robots-txt) [Framer XML sitemap](/seo/framer/xml-sitemap) [Gatsby redirects](/seo/gatsby/redirects) [Ghost SEO](/seo/ghost)

More in Frameworks
[Angular SEO](/seo/angular) [Astro SEO](/seo/astro) [Gatsby SEO](/seo/gatsby) [Next.js SEO](/seo/nextjs) [Nuxt SEO](/seo/nuxt)

Terms on this page
[HTTPS](/glossary/https) [Google Search Console](/glossary/google-search-console) [Rendered HTML](/glossary/rendered-html) [Canonical URL](/glossary/canonical-url) [Rendering](/glossary/rendering) [URL Inspection tool](/glossary/url-inspection-tool) [JavaScript SEO](/glossary/javascript-seo)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

Run the free audit, then approve the fixes. Every change can be undone.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
