Swizzling is the mechanism Docusaurus uses to let you replace or extend any React component provided by a theme. Instead of forking an entire theme, you surgically override just the component you need — keeping the rest of the theme intact and upgradeable. There are two approaches: wrapping adds behavior around the original component, while ejecting replaces it entirely with your own copy.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/facebook/docusaurus/llms.txt
Use this file to discover all available pages before exploring further.
How swizzling works
Docusaurus resolves theme components through a set of theme aliases. When you place a component atsrc/theme/SomeComponent.js, Docusaurus routes the @theme/SomeComponent alias to your file instead of the theme’s original file. The swizzle CLI automates this process for you.
- Wrapping
- Ejecting
A wrapper imports the original component via
@theme-original/SomeComponent and renders it alongside any additions you want. This is the safer approach because you maintain a thin layer of code and the original component continues to do its work.The swizzle CLI
Docusaurus ships an interactive CLI that handles the file creation for you. In most cases you only need one command:Listing available components
To see every component exposed by@docusaurus/theme-classic, run:
Wrapping a component
Wrapping is the recommended approach for most customizations. It keeps your diff small and survives theme upgrades more reliably.Edit the generated file
The CLI writes
src/theme/Footer/index.js. Open it and add your customizations around the original component:src/theme/Footer/index.js
The @theme-original alias
When wrapping, you import the original component via @theme-original/SomeComponent. This alias bypasses your wrapper and points directly at the theme’s file, preventing an infinite import loop.
Ejecting a component
Ejecting creates a full copy of the component’s source in your project. Use this only when wrapping is genuinely insufficient — for instance, when you need to restructure the component’s JSX from scratch.Safety levels
Not every component is equally stable. The swizzle CLI reports one of three safety levels for each component and action combination:Safe
Safe
The component’s public API is considered stable. No breaking changes should occur within a major theme version. You can wrap or eject these components with confidence.
Unsafe
Unsafe
This component is an internal implementation detail. Breaking changes may occur in minor theme versions. Swizzling is allowed but you may need to update your customization after upgrades.
Forbidden
Forbidden
The CLI prevents swizzling this component entirely. It is not designed to be overridden.
A component may be safe to wrap but unsafe to eject. The safety level is reported per action.
@docusaurus/theme-classic include Footer, Navbar, DocSidebar, TOC, CodeBlock, Admonition, and ColorModeToggle. Run --list to see the full table with current safety ratings.
Finding the right component to swizzle
@docusaurus/theme-classic has around 100 components. Use these strategies to identify the one you need:
Search by name
Run the interactive CLI and type part of a component name to filter the list. For example, typing
Doc narrows the results to documentation-related components.Start from a top-level route component
Every route has a top-level component such as
BlogPostPage or DocItem. Swizzle it temporarily, inspect the output, then drill down to the specific sub-component you want to change. Delete the top-level swizzle once you’ve identified your target.Read the theme source
Browse the theme source on GitHub and use search to trace where specific HTML is rendered.
TypeScript support
All official Docusaurus themes support TypeScript theme components. Add the--typescript flag to generate .tsx source instead of .js:
src/theme/Footer/index.tsx along with styles.module.css where applicable.
Wrapping the entire React tree with <Root>
The <Root> component sits at the very top of the React tree, above the theme <Layout>, and never unmounts. It is the right place for global state such as user authentication or a shopping cart. Create it manually at src/theme/Root.js:
src/theme/Root.js
When not to swizzle
Before reaching for swizzling, consider lighter alternatives:CSS customization
CSS rules and selectors cover a large portion of visual customizations. See the styling and layout guide for details.
Translations
The
yarn write-translations command lets you edit any text label in the theme without touching React components.