Skip to Content
🎉 Nextra 4.0 is released. Dima Machina is looking for a new job or consulting.

Layout Component

The theme is configured with the <Layout> component. You should pass your config options as Layout’s props, for example:

app/layout.jsx
import { Layout } from 'nextra-theme-docs' export default function MyLayout({ children, ...props }) { return ( <html lang="en"> <body> <Layout sidebar={{ autoCollapse: true }} docsRepositoryBase="https://github.com/shuding/nextra/tree/main/docs" > {children} </Layout> </body> </html> ) }

Detailed information for each option is listed below.

Docs Repository

Set the repository URL of the documentation. It’s used to generate the “Edit this page” link, the “Feedback” link and “Report of broken link” on not found page.

OptionTypeDefault ValueDescription
docsRepositoryBasestring'https://github.com/shuding/nextra'URL of the documentation repository.

Specify a Path

If the documentation is inside a monorepo, a subfolder, or a different branch of the repository, you can simply set the docsRepositoryBase to the root path of the app/ (App Router) folder of your docs. For example:

app/layout.jsx
<Layout docsRepositoryBase="https://github.com/shuding/nextra/tree/main/docs"> {children} </Layout>

Then Nextra will automatically generate the correct file path for all pages.

Dark Mode and Themes

Customize the theme behavior of the website.

OptionTypeDefault ValueDescription
darkModebooleantrueShow or hide the dark mode select button.
nextThemesobject{ attribute: 'class', defaultTheme: 'system', disableTransitionOnChange: true, storageKey: 'theme' }Configuration for the next-themes package.

MDX Components [!TODO]

Provide custom MDX components to render the content. For example, you can use a custom pre component to render code blocks.

OptionTypeDefault ValueDescription
componentsRecord<string, React.FC>Custom MDX components.

Show an “Edit this page” link on the page that points to the file URL on GitHub (or other places).

OptionTypeDefault ValueDescription
editLinkstring | ReactElement | null'Edit this page'Content of the edit link.
💡
Tip

To disable it, you can set editLink to null.

The built-in feedback link provides a way for users to submit feedback about the documentation. By default, it’s a link that points to the issue creation form of the docs repository, with the current website title prefilled: example.

OptionTypeDefault ValueDescription
feedback.contentstring | ReactElement | null'Question? Give us feedback'Content of the feedback link.
feedback.labelsstring'feedback'Labels that can be added to the new created issue.
💡
Tip

To disable it, you can set feedback.content to null.

I18n

Options to configure the language dropdown for the i18n docs website.

OptionTypeDefault ValueDescription
i18n[number].localestringLocale from i18n.locales field in next.config file.
i18n[number].namestringLocale name in dropdown.

Last Updated Date

Show the last updated date of a page. It’s useful for showing the freshness of the content.

OptionTypeDefault ValueDescription
lastUpdatedReactElement | null<LastUpdated />Component to render the last updated info.

Toggle Visibility

You can toggle visibility of the last update date on the specific pages by setting theme.timestamp property in the _meta.js file:

_meta.js
export default { 'my-page': { theme: { timestamp: false // Hide timestamp on this page } } }

Show previous and next page links on the bottom of the content. It’s useful for navigating between pages.

OptionTypeDefault ValueDescription
navigationboolean | objecttrueEnable or disable navigation link.
navigation.prevbooleanEnable or disable the previous page link.
navigation.nextbooleanEnable or disable the next page link.

Navigation

app/layout.jsx
<Layout navigation={{ prev: true, next: true }} > {children} </Layout>

The above is also equivalent to navigation: true.

Toggle Visibility

You can toggle visibility of the navigation on the specific pages by setting theme.pagination property in the _meta.js file:

_meta.js
export default { 'my-page': { theme: { pagination: false // Hide pagination on this page } } }

Page Map [!TODO]

OptionTypeDefault ValueDescription
sidebar.autoCollapsebooleanIf true, automatically collapse inactive folders above defaultMenuCollapseLevel.
sidebar.defaultMenuCollapseLevelnumber2Specifies the folder level at which the menu on the left is collapsed by default.
sidebar.toggleButtonbooleantrueHide/show sidebar toggle button.
sidebar.defaultOpenbooleantrueHide/show sidebar by default.

By default, the sidebar menu is collapsed at level 2. You can change it by setting sidebar.defaultMenuCollapseLevel to a different number. For example, when set to 1, every folder will be collapsed by default and when set to Infinity, all nested folders will be expanded by default.

If sidebar.autoCollapse is set to true, then all folders that do not contain an active/focused route will automatically collapse up to the level set by sidebar.defaultMenuCollapseLevel. e.g. if defaultMenuCollapseLevel is 2, then top-level folders will not auto-collapse.

Customize Sidebar Content

Together with the Separators item, you can customize how the sidebar content is rendered by using JSX elements:

_meta.jsx
export default { index: 'Intro', '--': { type: 'separator', title: ( <div className="flex items-center gap-2"> <MyLogo /> {children} </div> ) }, frameworks: 'JS Frameworks & Libs', about: 'About' }

Customized Sidebar

Toggle Visibility

You can toggle visibility of the <Sidebar> on the specific pages by setting theme.sidebar property in the _meta.js file:

_meta.js
export default { 'my-page': { theme: { sidebar: false // Hide sidebar on this page } } }

Customize Sidebar with Front Matter

In addition, you can customize the sidebar title using the sidebarTitle property in your front matter:

getting-started.mdx
--- sidebarTitle: Getting Started 🚀 ---

The priority of the sidebar title is as follows:

  1. A non-empty title from the _meta file.
  2. sidebarTitle in the front matter.
  3. title in the front matter.
  4. The title derived from the first h1 Markdown heading (e.g. # Dima Machina).
  5. If none of the above are available, it falls back to the filename of the page, formatted according to The Chicago Manual of Style.

Theme Switch

OptionTypeDefault ValueDescription
themeSwitch{ light: string; dark: string; system: string }{ light: 'Light', dark: 'Dark', system: 'System' }Translation of options in the theme switch.

You are able to customize the option names for localization or other purposes:

app/layout.jsx
<Layout themeSwitch={{ dark: 'Темный', light: 'Светлый', system: 'Системный' }} > {children} </Layout>

Table of Contents (TOC) Sidebar

Show a table of contents on the right side of the page. It’s useful for navigating between headings.

OptionTypeDefault ValueDescription
toc.backToTopstring | ReactElement | null'Scroll to top'Text of back to top button.
toc.extraContentstring | ReactElement | nullDisplay extra content below the TOC content.
toc.floatbooleantrueFloat the TOC next to the content.
toc.titlestring | ReactElement | null'On This Page'Title of the TOC sidebar.

Floating TOC

When enabled, the TOC will be displayed on the right side of the page, and it will be sticky when scrolling. If it’s disabled, the TOC will be displayed directly on the page sidebar.

Toggle Visibility

You can toggle visibility of the <TOC> on the specific pages by setting theme.toc property in the _meta.js file:

_meta.js
export default { 'my-page': { theme: { toc: false // Hide toc on this page } } }
Last updated on