Building Documentation Sites with Docusaurus
You need a documentation site for your library, framework, or SaaS product. You want it static, fast, and maintainable without building everything from scratch. Docusaurus v3 handles this well—it’s a mature React-based static site generator that ships with versioning, search integration, and MDX support out of the box.
This guide covers the architecture and practical setup of a Docusaurus documentation site, focusing on concepts that remain stable across minor releases.
Key Takeaways
- Docusaurus organizes content into three types: docs, blog posts, and standalone pages, each with distinct purposes and directory structures.
- The classic preset provides docs, blog, and theme plugins—sufficient for most documentation sites without additional configuration.
- MDX v3 in Docusaurus v3 enforces stricter JSX syntax, catching errors that earlier versions ignored silently.
- Swizzling allows deep theme customization, but ejected components require manual maintenance during upgrades.
Core Architecture of a Docusaurus Documentation Site
Docusaurus organizes content into three distinct content types:
Docs live in the /docs directory. These are your primary documentation pages, rendered with automatic sidebar navigation and versioning support. Each Markdown or MDX file becomes a page.
Blog posts go in /blog. These work well for changelogs, release announcements, or tutorials that are time-sensitive.
Pages in /src/pages are standalone React components or MDX files for custom landing pages, about sections, or anything outside the docs/blog structure.
The sidebar and versioning model deserves attention. Docusaurus auto-generates sidebars from your folder structure, or you can define them explicitly in sidebars.js. When you cut a version, it snapshots your current docs into versioned_docs/, letting users access documentation for older releases.
Docusaurus v3 Setup: Getting Started
Modern scaffolding supports npm, Yarn, pnpm, and Bun. Pick whichever your team uses:
npx create-docusaurus@latest my-docs classic
The classic preset bundles the docs plugin, blog plugin, and default theme—enough for most developer documentation sites. Docusaurus v3 requires Node.js 20 or later for local development and CI.
After scaffolding, your project structure looks like this:
my-docs/
├── docs/
├── blog/
├── src/
│ ├── components/
│ ├── css/
│ └── pages/
├── static/
├── docusaurus.config.js
└── sidebars.js
The docusaurus.config.js file controls site metadata, theme configuration, navbar, footer, and plugin options. This single file handles most customization without touching React code.
MDX Documentation: Writing Content
Docusaurus v3 uses MDX v3, which is stricter than earlier versions. This matters if you’re migrating from v2—MDX v3 enforces proper JSX syntax and won’t silently ignore malformed components.
Each doc file supports frontmatter for metadata:
---
id: getting-started
title: Getting Started
sidebar_position: 1
---
# Getting Started
Your content here. You can import React components directly.
You can embed React components, use Mermaid diagrams, and include interactive code blocks. The @site alias points to your project root for imports.
For diagrams, enable the Mermaid plugin in your config:
// docusaurus.config.js
module.exports = {
markdown: {
mermaid: true,
},
themes: ['@docusaurus/theme-mermaid'],
}
Discover how at OpenReplay.com.
Theming and Customization
The plugin system lets you extend functionality without forking the theme. Common plugins handle analytics, sitemaps, PWA support, and redirects.
For visual customization, override CSS variables in src/css/custom.css. The theme uses Infima under the hood, so you’re adjusting design tokens rather than writing component styles:
:root {
--ifm-color-primary: #2e8555;
--ifm-code-font-size: 95%;
}
Deeper customization uses “swizzling”—ejecting theme components to modify them. Run npx docusaurus swizzle to see available components. Swizzle only what you need, as ejected components require manual updates when upgrading Docusaurus.
Search Integration
Most production Docusaurus sites use Algolia DocSearch. Apply for the free program if your docs are public, or self-host the crawler for private documentation.
Configuration lives in themeConfig:
// docusaurus.config.js
module.exports = {
themeConfig: {
algolia: {
appId: 'YOUR_APP_ID',
apiKey: 'YOUR_SEARCH_API_KEY',
indexName: 'YOUR_INDEX_NAME',
},
},
}
DocSearch v4 also supports Algolia AskAI, which adds optional conversational search on top of the standard search experience and is configured as part of the same Algolia integration.
Deployment
Docusaurus builds to static HTML, CSS, and JavaScript in the /build directory. Any static hosting works: Vercel, Netlify, GitHub Pages, Cloudflare Pages, or your own CDN.
npm run build
The output is a standard static site with no server runtime required. Configure your hosting provider to handle client-side routing by serving index.html for unknown paths.
What to Know for Production
A few practical notes for maintaining a developer documentation site:
- Versioning adds complexity. Only version when users genuinely need access to old docs. Many projects do fine with a single “current” version.
- MDX strictness catches real bugs. If migration from v2 breaks pages, the errors usually point to actual JSX issues worth fixing.
- Build times scale with content. Large sites benefit from incremental builds in CI and caching
node_modules.
Conclusion
Docusaurus handles the infrastructure so you can focus on writing good documentation. The React foundation means frontend teams can customize deeply when needed, while the defaults work well enough that many sites ship without touching React code at all. Start with the classic preset, add plugins as requirements emerge, and resist the urge to over-customize before your documentation content is solid.
FAQs
Yes. Docusaurus generates static files you can host anywhere, including behind authentication. For search on private docs, self-host the Algolia crawler or use local search plugins like docusaurus-search-local instead of the free DocSearch program.
Run the upgrade command and address MDX v3 compatibility issues. Most breaking changes involve stricter JSX syntax in MDX files. The official migration guide documents specific changes, and error messages typically point directly to the problematic code.
Version only when users actively need access to documentation for older releases. If most users stay on the latest version, a single unversioned docs folder is simpler to maintain. Versioning adds build time and maintenance overhead for each snapshot you create.
Yes. Start with CSS variable overrides in custom.css for colors and spacing. Use the plugin system for functionality changes. Only swizzle components when CSS and plugins cannot achieve what you need, since ejected components require manual updates during upgrades.
Gain Debugging Superpowers
Unleash the power of session replay to reproduce bugs, track slowdowns and uncover frustrations in your app. Get complete visibility into your frontend with OpenReplay — the most advanced open-source session replay tool for developers. Check our GitHub repo and join the thousands of developers in our community.