Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/shuding/nextra/llms.txt

Use this file to discover all available pages before exploring further.

Nextra includes a full-page search feature powered by Pagefind — a static search library that indexes your HTML output at build time and serves results entirely client-side with no server or external API required. Search is enabled by default; you only need to install Pagefind and add a postbuild script to activate it.

Setup

1
Install Pagefind as a dev dependency
2
Add pagefind to your project’s dev dependencies:
3
npm
npm i -D pagefind
yarn
yarn add -D pagefind
pnpm
pnpm add -D pagefind
4
Add a postbuild script
5
Pagefind indexes .html files, so the indexing must run after your Next.js build completes. Add a postbuild script to package.json:
6
Server Builds
{
  "scripts": {
    "build": "next build",
    "postbuild": "pagefind --site .next/server/app --output-path public/_pagefind"
  }
}
Static Exports
{
  "scripts": {
    "build": "next build",
    "postbuild": "pagefind --site out --output-path out/_pagefind"
  }
}
7
npm, yarn, and pnpm all run postbuild automatically after the build script finishes.
8
Ignore generated index files
9
Add the generated _pagefind/ directory to your .gitignore so index files are not committed to version control:
10
_pagefind/
11
Verify the setup
12
Run your build and check that a _pagefind/ directory exists in public/ (server builds) or out/ (static exports). Start your app and use the search bar to confirm results appear correctly.
13
npm
npm run build
yarn
yarn build
pnpm
pnpm build

How It Works

When search is enabled, Nextra adds a data-pagefind-body attribute to the <main> element of each page. Pagefind uses this attribute to identify the content regions to index, so only the page body is searchable — not navigation, headers, or footers.

Configuration

Search is enabled by default. Configure it in next.config.mjs by passing a search option to nextra():
import nextra from 'nextra'

const withNextra = nextra({
  search: false
})

export default withNextra({})

Exclude Code Blocks from Index

By default, code blocks are included in the search index. To keep search enabled but exclude code block content, set codeblocks: false:
import nextra from 'nextra'

const withNextra = nextra({
  search: { codeblocks: false }
})

export default withNextra({})
When codeblocks: false is set, Nextra adds data-pagefind-ignore="all" to every <pre> element so Pagefind skips them during indexing.
The default value of search is { codeblocks: false }, meaning code blocks are excluded from the index unless you explicitly set search: true or search: { codeblocks: true }.

Configuration Reference

OptionTypeDefaultDescription
searchboolean | { codeblocks: boolean }{ codeblocks: false }Enable/disable search or configure code indexing.
search.codeblocksbooleanfalseWhether to include code blocks in the search index.

Alternative Search Providers

Pagefind works great for most documentation sites, but Nextra also supports replacing the default search with other providers.

Typesense

Self-hostable, typo-tolerant search engine with a community-maintained adapter. Ideal for large documentation sites that need faceted search.

AI Search (Inkeep)

Add an AI-powered chat assistant to your docs using Inkeep, letting users ask natural language questions instead of typing keywords.

Build docs developers (and LLMs) love