Skip to content

Custom Theme ​

VitePress allows you to extend and customize the default theme with your own Vue components, styles, and layouts. This chapter covers everything you need to create a professional-looking custom theme.

Theme Architecture ​

VitePress themes are built with Vue 3 and use a slot-based architecture. The default theme provides a complete layout that you can extend without rewriting everything from scratch.

Theme Directory Structure ​

docs/.vitepress/theme/
├── index.js          # Theme entry point
├── components/       # Custom Vue components
│   ├── AskAI.vue    # AI chatbot component
│   └── ...
└── styles/
    └── custom.css    # Custom styles

Extending the Default Theme ​

Basic Extension ​

Create docs/.vitepress/theme/index.js:

js
import DefaultTheme from 'vitepress/theme'
import './styles/custom.css'

export default DefaultTheme

Adding Custom Components ​

Register global components:

js
import DefaultTheme from 'vitepress/theme'
import CustomComponent from './components/CustomComponent.vue'

export default {
  extends: DefaultTheme,
  enhanceApp({ app }) {
    app.component('CustomComponent', CustomComponent)
  },
}

Using Layout Slots ​

The default theme provides slots for injecting content at specific positions:

js
import DefaultTheme from 'vitepress/theme'
import AskAI from './components/AskAI.vue'
import { h } from 'vue'

export default {
  extends: DefaultTheme,
  Layout: () => {
    return h(DefaultTheme.Layout, null, {
      'nav-bar-content-after': () => h(AskAI),
    })
  },
}

Available slots include:

Slot NameLocation
layout-topTop of the layout
layout-bottomBottom of the layout
nav-bar-title-beforeBefore nav title
nav-bar-title-afterAfter nav title
nav-bar-content-beforeBefore nav content
nav-bar-content-afterAfter nav content
nav-screen-content-beforeBefore mobile nav
nav-screen-content-afterAfter mobile nav
aside-topBefore sidebar
aside-bottomAfter sidebar
aside-outline-beforeBefore outline
aside-outline-afterAfter outline
doc-topBefore content
doc-bottomAfter content
doc-footer-beforeBefore footer

Custom CSS ​

CSS Variables ​

VitePress uses CSS variables extensively. Override them in your custom CSS:

css
:root {
  /* Brand colors */
  --vp-c-brand-1: #5f67ee;
  --vp-c-brand-2: #747bff;
  --vp-c-brand-3: #8b5cf6;

  /* Font family */
  --vp-font-family-base: 'Inter', sans-serif;
  --vp-font-family-mono: 'Fira Code', monospace;
}

Dark Mode Variables ​

Use the .dark class for dark mode overrides:

css
.dark {
  --vp-c-brand-1: #a78bfa;
  --vp-c-brand-2: #818cf8;
}

Using Components in Markdown ​

Once registered, use your custom components directly in markdown:

md
<MyComponent title="Hello" />

<AskAI />

TIP

VitePress automatically registers any .vue file placed in docs/.vitepress/theme/components/ — no manual import needed.

VitePress Course — Complete Tutorial