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.

The nextra() function is the default export of the nextra package and serves as the entry point for integrating Nextra into your Next.js project. It accepts a configuration object and returns a higher-order function that wraps your next.config — letting Nextra instrument the webpack and Turbopack pipelines, register MDX loaders, and inject the page-map build step transparently.

Function Signature

import nextra from 'nextra'

function nextra(config: NextraConfig): (nextConfig?: NextConfig) => NextConfig
Call nextra() once with your Nextra options to get withNextra, then pass your Next.js config object to that wrapper:
next.config.mjs
import nextra from 'nextra'

const withNextra = nextra({
  defaultShowCopyCode: true,
  search: { codeblocks: false },
  latex: true,
  mdxOptions: {
    rehypePlugins: [],
    remarkPlugins: [],
  },
})

export default withNextra({
  // Regular Next.js configuration here
})
The returned withNextra function merges Nextra’s webpack rules into your existing Next.js config rather than replacing it. All standard NextConfig options continue to work as expected.

NextraConfig Options

Core Options

defaultShowCopyCode
boolean
Enable the copy button for all code blocks by default, without needing to set the copy=true attribute in each code block’s metadata string. You can still disable the button on a per-block basis with copy=false.
Enable search functionality powered by Pagefind. When enabled, Nextra adds the data-pagefind-body attribute to the <main> element so Pagefind can index your content.
staticImage
boolean
default:"true"
Automatically optimise static image imports written with Markdown syntax (e.g. ![Alt text](/demo.png)). Nextra will pass these through Next.js <Image> for automatic resizing and format selection.
readingTime
boolean
Adds an estimated reading time to the front matter of every .md and .mdx file under the readingTime key. Powered by the reading-time package.
codeHighlight
boolean
default:"true"
Enable or disable syntax highlighting for code blocks. Highlighting is performed at build time by Rehype Pretty Code backed by Shiki. Disable this if you want to use a different client-side highlighter.
whiteListTagsStyling
string[]
Allows additional HTML elements to be replaced by components defined in mdx-components.js. By default Nextra only replaces <details> and <summary>. Pass extra tag names here to extend that behaviour.
contentDirBasePath
string
default:"/"
Serve your .md and .mdx files from the content directory at a custom URL path instead of the root (/). Must begin with / and must not end with / (except for the root itself).
// Files in content/ will be served under /docs/...
nextra({ contentDirBasePath: '/docs' })
Prefixes the current locale to all links in the page-map. Useful for i18n setups where you manage routing yourself and don’t want to use Nextra’s built-in middleware.
This option is unstable and its API may change in a future minor release.

mdxOptions

mdxOptions
MdxOptions
default:"{}"
Fine-grained control over the MDX compilation pipeline. All sub-options are optional.

latex

latex
boolean | KatexConfig | MathjaxConfig
Enable LaTeX math rendering. Pass true to use KaTeX with default settings, or supply a renderer-specific object for fine-grained control.

Full Configuration Example

import nextra from 'nextra'

const withNextra = nextra({
  defaultShowCopyCode: true,
  search: { codeblocks: false },
  latex: {
    renderer: 'katex',
    options: { strict: false },
  },
  mdxOptions: {
    remarkPlugins: [],
    rehypePlugins: [],
    rehypePrettyCodeOptions: {
      theme: 'github-dark',
    },
  },
  contentDirBasePath: '/docs',
})

export default withNextra({
  reactStrictMode: true,
})
You can run next dev --turbopack with Nextra. Turbopack support is configured automatically — no extra flags needed in nextra().

Build docs developers (and LLMs) love