Extending the Default Theme
The VitePress default theme is highly customizable through CSS variables, component registration, and layout slots. This allows you to build on top of the default theme without creating a theme from scratch.Before proceeding, make sure you understand how custom themes work.
Basic Setup
Theme Entry File
Create.vitepress/theme/index.js or .vitepress/theme/index.ts:
Customizing CSS
CSS Variables
The default theme uses CSS custom properties for styling. Override them to customize colors, fonts, spacing, and more.- Colors
- Typography
- Layout
- Components
.vitepress/theme/custom.css
Custom Styles
Add custom CSS rules:.vitepress/theme/custom.css
Using Custom Fonts
Web Fonts
By default, VitePress includes Inter font. To use different fonts:.vitepress/theme/index.js
.vitepress/theme/fonts.css
Local Fonts
.vitepress/theme/fonts.css
.vitepress/config.ts
Registering Components
Global Components
- Single Component
- Multiple Components
- Auto-Register
.vitepress/theme/index.js
Layout Slots
The default theme provides layout slots to inject custom content at specific locations.Available Slots
- Doc Layout
- Home Layout
- Page Layout
- Global Slots
When
layout: 'doc' (default):doc-top- Before doc contentdoc-bottom- After doc contentdoc-footer-before- Before doc footerdoc-before- Before doc containerdoc-after- After doc containersidebar-nav-before- Before sidebar navsidebar-nav-after- After sidebar navaside-top- Top of asideaside-bottom- Bottom of asideaside-outline-before- Before outlineaside-outline-after- After outlineaside-ads-before- Before adsaside-ads-after- After ads
Using Slots with Components
- With Layout Wrapper
- With Render Function
.vitepress/theme/index.js
.vitepress/theme/MyLayout.vue
Slot Examples
Add Banner to All Docs
.vitepress/theme/MyLayout.vue
Add Contributors List
.vitepress/theme/MyLayout.vue
Custom Sidebar Footer
.vitepress/theme/MyLayout.vue
Overriding Components
Replace default theme components using Vite aliases:.vitepress/config.ts
View Transitions
On Appearance Toggle
Add smooth transitions when toggling dark mode:.vitepress/theme/Layout.vue
Complete Example
.vitepress/theme/index.js
Next Steps
Theme Configuration
Configure default theme options
Custom Theme
Create a completely custom theme