Extending Default Theme

Customize CSS variables, use layout slots, register global components, and override theme fonts

Customize the default theme through CSS, slots, and Vue components.

Theme Entry File

Create .vitepress/theme/index.ts to extend the default theme:

// .vitepress/theme/index.ts
import DefaultTheme from 'vitepress/theme'
import './custom.css'

export default DefaultTheme

CSS Variables

Override root CSS variables:

/* .vitepress/theme/custom.css */
:root {
  /* Brand colors */
  --vp-c-brand-1: #646cff;
  --vp-c-brand-2: #747bff;
  --vp-c-brand-3: #9499ff;
  
  /* Backgrounds */
  --vp-c-bg: #ffffff;
  --vp-c-bg-soft: #f6f6f7;
  
  /* Text */
  --vp-c-text-1: #213547;
  --vp-c-text-2: #476582;
}

.dark {
  --vp-c-brand-1: #747bff;
  --vp-c-bg: #1a1a1a;
}

See all CSS variablesarrow-up-right.

Home Hero Customization

Custom Fonts

Remove Inter font and use your own:

Preload fonts in config:

Global Components

Register components available in all markdown:

Use in markdown:

Layout Slots

Inject content into specific locations:

Available Slots

Doc layout (layout: doc):

  • doc-top, doc-bottom

  • doc-before, doc-after

  • doc-footer-before

  • sidebar-nav-before, sidebar-nav-after

  • aside-top, aside-bottom

  • aside-outline-before, aside-outline-after

  • aside-ads-before, aside-ads-after

Home layout (layout: home):

  • home-hero-before, home-hero-after

  • home-hero-info-before, home-hero-info, home-hero-info-after

  • home-hero-actions-after, home-hero-image

  • home-features-before, home-features-after

Page layout (layout: page):

  • page-top, page-bottom

Always available:

  • layout-top, layout-bottom

  • nav-bar-title-before, nav-bar-title-after

  • nav-bar-content-before, nav-bar-content-after

  • not-found (404 page)

Using Render Functions

Alternative to template slots:

Override Internal Components

Replace default theme components with Vite aliases:

View Transitions

Custom dark mode toggle animation:

Key Points

  • Import vitepress/theme-without-fonts to use custom fonts

  • Use layout slots to inject content without overriding components

  • Global components are registered in enhanceApp

  • Override CSS variables for theming

  • Use Vite aliases to replace internal components

Last updated

Was this helpful?