A Docusaurus site is a pre-rendered single-page React application, so you can style it using any approach that works in a React project. This guide covers the three most common patterns: global CSS, CSS Modules, and Infima CSS variable overrides. All three can be combined freely.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.
Global CSS
Global CSS is the simplest approach. Create a stylesheet and register it through the classic theme’scustomCss option:
docusaurus.config.js
src/css/custom.css
CSS class name types
When inspecting the DOM, you will encounter three categories of class names:Theme class names
Theme class names
Stable, theme-agnostic class names like
main-wrapper and docSidebarContainer. These are the safest to target in custom CSS because they are guaranteed not to change. Prefer these over Infima or CSS Module class names.Infima class names
Infima class names
BEM-style names like
navbar__item or button--primary. These are relatively stable but are considered implementation details. Prefer overriding Infima CSS variables rather than targeting these class names directly.CSS Module class names
CSS Module class names
Hashed class names like
codeBlockContainer_RIuc. These are implementation details that may change between releases. Avoid targeting them. If necessary, use an attribute selector that ignores the hash: [class*='codeBlockContainer'].Infima CSS variables
@docusaurus/preset-classic is built on Infima, a CSS framework that exposes design tokens as CSS custom properties. Override them in src/css/custom.css to change colors, typography, and spacing site-wide:
src/css/custom.css
Dark mode
The<html> element carries a data-theme attribute that switches between "light" and "dark". Scope your CSS to a specific mode using attribute selectors:
src/css/custom.css
?docusaurus-theme=dark or ?docusaurus-theme=light to any page URL.
CSS Modules
CSS Modules scope styles to the component that imports them, preventing class name collisions across your site. Name your stylesheet with the.module.css suffix:
src/components/Widget/styles.module.css
src/components/Widget/index.jsx
.main becomes something like .main_aB3Kd. You import the transformed name through the styles object — the mapping is handled automatically.
Sass/SCSS
Sass is not built in, but the community plugindocusaurus-plugin-sass adds support for both global and module Sass stylesheets:
Responsive design
Docusaurus uses996px as the breakpoint between mobile and desktop views. Use media queries to adapt your custom styles:
src/css/custom.css
CSS-in-JS
Data attributes for conditional styles
You can inject customdata-* attributes onto the <html> element via query string parameters following the docusaurus-data-<key> pattern. This makes it possible to style a page differently based on the URL, which is useful for embedding Docusaurus pages in iframes:
src/css/custom.css
?docusaurus-data-navbar=false to any page URL to activate the style.