Nextra is 100% compatible with the built-in CSS support of Next.js, including plainDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/shuding/nextra/llms.txt
Use this file to discover all available pages before exploring further.
.css, CSS Modules (.module.css), and Sass files (.scss, .sass, .module.scss, .module.sass). You can add a global stylesheet, override theme variables, and integrate Sass with no extra configuration beyond the Nextra setup.
Adding a Global CSS File
To apply custom styles across your entire Nextra site, create a CSS file and import it in your root layout.body {
font-family:
'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', 'Helvetica', 'Arial',
sans-serif;
padding: 20px 20px 60px;
max-width: 680px;
margin: 0 auto;
}
Import the CSS file at the top of your
app/layout.tsx (or app/layout.jsx). Next.js will
bundle and inject it on every page:Global CSS files must be imported from a layout or page file inside the
app/ directory.
Importing global CSS from a component that is not a layout or page is not supported by Next.js.Overriding nextra-theme-docs CSS Variables
nextra-theme-docs is built with Tailwind CSS v4 and exposes its design tokens as CSS custom properties (variables). You can override these in your global CSS to customize colors, fonts, spacing, and more without modifying any theme source code.
app/globals.css
Cascade Layers
nextra-theme-docs uses CSS @layer declarations internally, which means its styles participate in the CSS cascade layer order. Understanding this helps you write overrides that always win without needing high specificity or !important.
How layers work
Styles inside a@layer always have lower precedence than styles outside any layer, regardless of specificity. This means a simple un-layered rule in your CSS will override a theme rule — even a highly specific one — as long as yours is not also inside a lower-priority layer.
app/globals.css
Explicit layer ordering with postcss-import
When you need full control over the layer stack — for example, to integrate multiple third-party style libraries — use postcss-import to wrap imports in named layers:
export default {
plugins: {
'postcss-import': {}
// add other PostCSS plugins here (e.g., autoprefixer, cssnano)
}
}
Declare the layer order explicitly, then import each stylesheet into its named layer.
Layers listed later in
@layer have higher priority:/* Layers listed here establish priority: my-overrides wins over nextra */
@layer nextra, base, my-overrides;
@import 'nextra-theme-docs/dist/style.css' layer(nextra);
@layer base {
/* base styles here */
}
@layer my-overrides {
/* These always win over nextra-theme-docs */
:root {
--nextra-primary-hue: 270deg;
}
}
Using Sass
Nextra supports Sass out of the box through Next.js. The only prerequisite is installing thesass package.
Rename
globals.css to globals.scss (or create a new .scss file). Sass is a superset
of CSS, so existing CSS is valid SCSS:$primary-font: 'SF Pro Text', 'Helvetica Neue', sans-serif;
$max-content-width: 680px;
body {
font-family: $primary-font;
max-width: $max-content-width;
margin: 0 auto;
&:has(.nextra-sidebar) {
max-width: 100%;
}
}
Sass variables and mixins are scoped to their own compilation step and are separate from
Tailwind’s CSS variable system. You can use both simultaneously.
CSS Isolation with style-prefixed.css
By default, nextra-theme-docs/style.css uses the standard Tailwind v4 layer names (@layer base, @layer utilities). If you need stronger CSS layer isolation — for example, to embed a Nextra-powered section inside a larger app that also uses Tailwind — use the style-prefixed.css variant, which renames those layers to v4-base and v4-utilities:
app/globals.css
base and utilities layers carry unique names, preventing them from merging with layers of the same name defined elsewhere in your CSS.
Quick Reference
Supported CSS file types
Supported CSS file types
Next.js (and therefore Nextra) supports all of the following out of the box:
| File type | Usage |
|---|---|
.css | Global styles, imported from layouts/pages |
.module.css | Component-scoped CSS Modules |
.scss / .sass | Sass/SCSS (requires sass package) |
.module.scss / .module.sass | Sass CSS Modules |
Common nextra-theme-docs CSS variables
Common nextra-theme-docs CSS variables