MDX Notes
How to set up sidebars in Docusaurus — autogenerated, manual, categories, links, ordering, and running multiple sidebars at once
Sidebars are how your readers navigate docs. They sit on the left, show a tree of pages, and you get two approaches: let Docusaurus generate one from your folder structure, or hand-craft every item yourself.
Sidebar Types
Autogenerated Sidebars
Easiest option. Point Docusaurus at your docs/ folder and it builds the sidebar for you:
Your folder structure *becomes* your sidebar structure:
| ├── intro.mdx | "Introduction" (from title) |
| │ ├── _category_.json | Category metadata |
| │ ├── installation.mdx | "Installation" |
| │ └── quick-start.mdx | "Quick Start" |
| │ ├── basics.mdx | "Basics" |
| │ └── advanced.mdx | "Advanced" |
| ├── overview.mdx | "API Overview" |
| └── reference.mdx | "API Reference" |
Visual Result: The sidebar displays a hierarchical tree matching your folder structure. Each folder becomes a collapsible category, and each.mdxfile becomes a clickable nav item. Items are ordered bysidebar_positionfrontmatter or alphabetically.
Category Metadata with _category_.json
You can control how each folder shows up as a category:
| Field | Description |
|---|---|
label | Display name in the sidebar |
position | Sort order among siblings |
collapsed | Whether the category starts collapsed |
collapsible | Whether the category can be collapsed |
link | Makes the category label itself clickable |
Manual Sidebars
When you want full control over what shows up and in what order, define every item yourself:
Sidebar Item Types
Doc Items
The most common type — it links to a document:
// Short form (just the doc ID)
'intro'
// Long form (with options)
{
type: 'doc',
id: 'intro',
label: 'Introduction', // Override the doc's title
className: 'sidebar-intro-item', // Custom CSS class
}Doc IDs come from the file path relative to docs/:
docs/intro.mdx→ ID:introdocs/guides/advanced.mdx→ ID:guides/advanced- Or override with
idfrontmatter
Category Items
Group related docs under a collapsible section:
Category Links
Categories can link to a page, or just expand/collapse:
// Option 1: Link to an existing doc
link: {
type: 'doc',
id: 'tutorials/overview',
}
// Option 2: Auto-generated index page
link: {
type: 'generated-index',
title: 'Tutorials',
slug: '/tutorials',
}
// Option 3: No link (default) — just expands/collapses
// Omit the link property entirelyVisual Result: With generated-index, clicking the category name shows an auto-generated page listing all items in that category as cards with their descriptions.Link Items
For external URLs or internal links that aren't docs:
{
type: 'link',
label: 'GitHub Repository',
href: 'https://github.com/my-org/my-project',
}
// Internal link (non-doc page)
{
type: 'link',
label: 'Blog',
href: '/blog',
}HTML Items
Arbitrary HTML — great for separators, section headers, or badges:
// Separator line
{
type: 'html',
value: '<hr/>',
className: 'sidebar-separator',
}
// Section header
{
type: 'html',
value: '<span class="sidebar-section-header">RESOURCES</span>',
className: 'sidebar-section',
defaultStyle: true,
}
// Badge/label
{
type: 'html',
value: '<span class="badge badge--primary">NEW</span> What\'s New',
}.sidebar-section-header {
font-size: 0.7rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--ifm-color-emphasis-600);
padding: 8px 16px 4px;
}
.sidebar-separator hr {
margin: 12px 16px;
border-color: var(--ifm-color-emphasis-200);
}Collapsible Categories
You can control expand/collapse behavior globally and per-category:
module.exports = {
themeConfig: {
docs: {
sidebar: {
hideable: true, // Allow hiding the entire sidebar
autoCollapseCategories: true, // Only one category open at a time
},
},
},
};Per-category override in sidebars.js:
:::tip[Sidebar UX] Use autoCollapseCategories: true for large sidebars with many categories. This keeps the sidebar compact by only showing one expanded category at a time — similar to an accordion pattern. :::
Sidebar Position via Frontmatter
The easiest way to order items in autogenerated sidebars — just add sidebar_position to your frontmatter:
Frontmatter Sidebar Fields
| Field | Purpose |
|---|---|
sidebar_position | Numeric position (lower = higher in sidebar) |
sidebar_label | Override display text in sidebar |
sidebar_class_name | CSS class for styling |
sidebar_custom_props | Custom data accessible in theme |
displayed_sidebar | Which sidebar to show on this page |
Numbering Strategy
| ├── intro.mdx (sidebar_position | 1) |
| │ ├── installation.mdx (sidebar_position | 1) |
| │ ├── configuration.mdx (sidebar_position | 2) |
| │ └── first-page.mdx (sidebar_position | 3) |
| │ ├── basics.mdx (sidebar_position | 1) |
| │ └── advanced.mdx (sidebar_position | 2) |
:::note[Position Gaps] Leave gaps in your numbering (10, 20, 30) to make it easy to insert new pages later without renumbering everything:
sidebar_position: 10 # Installation
sidebar_position: 20 # Configuration
sidebar_position: 30 # First Page
# Easy to add "sidebar_position: 15" between Installation and Configuration:::
Number Prefixes (Alternative)
Instead of frontmatter, you can prefix your file names with numbers:
Docusaurus strips the numeric prefix from the URL slug, so 01-intro.mdx becomes /docs/intro.
Custom Sidebar Items
Conditional Items Based on Environment
Want something to only show in dev mode? Since sidebars.js is plain JavaScript, you can do this:
Dynamic Sidebar Generation
You can also read the filesystem at build time and generate sidebar entries automatically:
Multiple Sidebars
Got a big site? You can define separate sidebars for different sections:
Linking to Different Sidebars from Navbar
Wire each sidebar to a navbar item:
Visual Result: The navbar shows separate "Docs", "API", and "Community" links. Clicking each one displays that section with its own sidebar navigation. The left sidebar completely changes based on which section is active.
Controlling Which Sidebar a Doc Shows
Use displayed_sidebar frontmatter to override:
---
title: "API Overview"
displayed_sidebar: api
---Complete sidebars.js Example
Here's a production-ready config that combines multiple techniques:
Best Practices
:::tip[Sidebar Guidelines]
- Start with autogenerated — Switch to manual only when you need more control
- Use
sidebar_position— Easier to maintain than manual sidebar ordering - Keep depth ≤ 3 levels — Deeply nested sidebars are hard to navigate
- Use generated index pages — They create useful overview pages for free
- Add HTML separators — Visual sections make large sidebars scannable
- Multiple sidebars for large sites — Don't force everything into one sidebar
- Test on mobile — Sidebars become hamburger menus; keep labels short
- Leave position gaps — Use 10, 20, 30 instead of 1, 2, 3 for future flexibility
:::
A well-structured sidebar is the difference between docs people love and docs people fight with. Spend time on it — it's the map your readers use to find things.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Sidebar Configuration in Docusaurus.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this MDX Tutorial topic.
Search Terms
mdx-tutorial, mdx tutorial, mdx, tutorial, docusaurus, sidebar, configuration, sidebar configuration in docusaurus
Related MDX Tutorial Topics