1. Home
  2. ChevronRightAdvanced
  3. ChevronRightCustom Layout

Custom Layout

Override the default docs layout with your own React component using docs/layout.tsx.

Boltdocs wraps every MDX page in a layout. By default, it uses DocsLayout which includes the navbar, sidebar, content area, and on-this-page navigation. You can override this by creating a custom layout.


Creating a Custom LayoutLink

Create docs/layout.tsx in your docs folder:

docs/layout.tsx
import { DocsLayout } from 'boltdocs/client'

export default function Layout({ children }: { children: React.ReactNode }) {
  return <DocsLayout>{children}</DocsLayout>
}

This replaces the default layout for all pages in your docs.


Full Custom LayoutLink

For complete control, build your own layout from primitives:

docs/layout.tsx
import { Navbar, Sidebar, OnThisPage, Breadcrumbs, PageNav } from 'boltdocs/client'

export default function CustomLayout({
  children,
  frontmatter,
  headings,
}: {
  children: React.ReactNode
  frontmatter: Record<string, any>
  headings: { id: string; text: string; level: number }[]
}) {
  return (
    <div className="min-h-screen">
      <Navbar />
      <div className="flex">
        <Sidebar />
        <div className="flex-1 max-w-4xl mx-auto px-8 py-12">
          <Breadcrumbs />
          <article className="prose dark:prose-invert max-w-none">
            {children}
          </article>
          <OnThisPage headings={headings} />
          <PageNav />
        </div>
      </div>
    </div>
  )
}

Layout PropsLink

Your custom layout receives these props:

PropTypeDescription
childrenReactNodeThe rendered MDX content
frontmatterRecord<string, any>The current page's frontmatter fields
headingsHeading[]Extracted headings for on-this-page

Heading TypeLink

interface Heading {
  id: string
  text: string
  level: number // 1-6 (h1-h6)
}

Using DocsLayout ComponentsLink

Boltdocs exports layout primitives you can mix and match:

ComponentPurpose
DocsLayoutDefault layout with navbar, sidebar, content, on-this-page
NavbarTop navigation bar with tabs and search
SidebarLeft sidebar with groups and collapsible sections
OnThisPageRight-side table of contents
BreadcrumbsPath navigation below navbar
PageNavPrevious/next page navigation at bottom
SearchDialogGlobal search modal

Layout Example: Landing Page StyleLink

import { Navbar, SearchDialog } from 'boltdocs/client'

export default function LandingLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <div className="min-h-screen bg-linear-to-b from-white to-zinc-50 dark:from-zinc-900 dark:to-zinc-950">
      <Navbar />
      <SearchDialog />
      <main className="max-w-5xl mx-auto px-6 py-20">
        {children}
      </main>
    </div>
  )
}

Conditional LayoutsLink

Use frontmatter to select different layouts:

// docs/layout.tsx
import { DocsLayout } from 'boltdocs/client'

export default function Layout(props: any) {
  if (props.frontmatter?.layout === 'landing') {
    return <LandingLayout {...props} />
  }
  return <DocsLayout>{props.children}</DocsLayout>
}

Then in your MDX:

---
title: Welcome
layout: landing
---

Combining with External PagesLink

External pages (pages-external/) have their own layout export. Use the same approach for consistency:

// docs/pages-external/index.tsx
import { Navbar } from 'boltdocs/client'
import CustomPage from './CustomPage'

export const pages = {
  '/custom': CustomPage,
}

export const layout = ({ children }: { children: React.ReactNode }) => (
  <div className="custom-wrapper">
    <Navbar />
    {children}
  </div>
)

Performance NotesLink

  • Custom layouts are rendered server-side during SSG
  • In dev mode, layout changes trigger hot reload
  • Heavy custom layouts may slow initial page load — keep them lean
Last updated on July 27, 2026

Was this page helpful?