Skip to Content
Getting Started

➊ Where to drop a new page

app/ docs/ ← existing docs tree (App Router) <topic>/page.mdx ← add files here **or** content/ ← optional flat MDX tree (no page.mdx rule) src/mdx-components.js ← must exist – leave untouched
  • App folder = “page.mdx” convention. Create app/docs/my-topic/page.mdx.
  • Content folder = filename is route. Create content/my-topic.mdx, plus the catch-all route already in app/[[...mdxPath]]/page.jsx.

If you choose content/, set contentDirBasePath in next.config.mjs if you need a prefix (e.g. /docs).


➋ Front-matter template

Every MDX file should start with something like:

--- title: Awesome Feature # <h1> title sidebarTitle: Awesome # optional, compact label in sidebar description: Short SEO-ish blurb shown in <meta> icon: FileIcon # if the parent section supports it asIndexPage: true # only if this page IS the folder index ---

➌ Adding rich content

WantMinimal syntax (works out-of-box)Notes
TableGFM pipes:
| a | b |
Auto-drawn & styled. Raw <table> needs whiteListTagsStyling option.
Mermaid diagrammermaid code blockPlugin replaces block with <Mermaid> component.
KaTeX / MathJax$a^2+b^2=c^2$ or fenced math blocksEnsure latex: true (KaTeX) or {renderer:'mathjax'} in next.config.mjs.
Syntax-highlighted codejs {1,4-5} copy showLineNumbersShiki; line/substring/filename/highlight/copy supported.
npm → Yarn tabs```sh npm2yarnShows tabs for npm/yarn/pnpm/bun via remark-npm2yarn.
Twoslash TS hovers```ts twoslashShow type-insight balloons & custom @log, @error
Steps / Tabs / CalloutImport from nextra/components inside MDX:
import { Steps, Tabs, Callout } from 'nextra/components'
Rich layout helpers.
Static image with zoom![Alt](/public/foo.png)Next/Image wrapper & zoom by default; disable via custom img.
Live codingEmbed Sandpack / react-live like any React component.

Steps component example

Install

Run npm create latest

Develop

Start the local dev server with npm run dev.

Deploy

Push to Vercel / Netlify or any static host.


➍ Sidebar & navbar housekeeping (_meta.js)

  • Order / titles – Add or override keys in the folder’s _meta.js:

    export default { index: "Intro", advanced: "Advanced Guides", "###": { type: "separator", title: "Extra" }, faq: { title: "FAQ", type: "page" }, // moves into top navbar };
  • Hide a filedisplay: 'hidden'.

  • Per-page theme tweakstheme: { sidebar:false, layout:'full', typesetting:'article' }.


➎ Global features already on

  • Search → requires pagefind + postbuild script. (If you copied the starter, this is configured – otherwise add it.)
  • Static image optimisationstaticImage:true defaults.
  • Syntax highlightingcodeHighlight:true.
  • Image zoom – enabled; use <Image> to opt-out per image.

➏ Common pitfalls an LLM should avoid

PitfallHow to dodge it
Using Pages router examplesNextra v4 only supports App Router.
Forgetting mdx-components.jsFile must export useMDXComponents; leave starter intact.
Adding non-serialisable functions when Turbopack dev flag is onKeep remarkPlugins etc. out of nextra() when running next dev --turbopack.
KaTeX CSS missingImport katex/dist/katex.min.css or link CDN when latex:true.
Raw HTML table unstyledEither write GFM or whitelist tags with whiteListTagsStyling.

➐ End-to-end example: new page with table + diagram

## <!-- app/docs/performance/page.mdx --> title: Performance Tips sidebarTitle: ⚡️ Perf description: Practical tricks to speed things up. icon: LightningIcon --- import { Callout, Steps } from "nextra/components"; # Performance Tips <Callout type="tip">Start with measuring!</Callout> ## Benchmark table | Technique | Avg gain | | :--------- | -------: | | Memoize | 23 % | | Code-split | 15 % | ## Architecture <Mermaid chart={`graph LR A[User] --> B(CDN) --> C(Edge Fn) --> D(DB) `} />
<Steps>### Measure Explain how... ### Optimise Explain how...</Steps>

Save the file, run npm run dev, and the page auto-appears in the sidebar under ⚡️ Perf.


Live preview of the example

Start with measuring!

Benchmark table

TechniqueAvg gain
Memoize23 %
Code-split15 %

Architecture

Measure

Explain how…

Optimise

Explain how…


Last updated on