Skip to main content

Creating a Custom Theme

VitePress allows you to create completely custom themes to match your specific design requirements. A custom theme gives you full control over the layout, styling, and functionality of your documentation site.

Theme Structure

Theme Entry File

Create a theme entry file at .vitepress/theme/index.js or .vitepress/theme/index.ts:
When VitePress detects a theme entry file, it will use your custom theme instead of the default theme.

Theme Interface

A VitePress theme must implement this interface:

Basic Custom Theme

Minimal Setup

The simplest possible theme:
The <Content /> component renders the compiled Markdown content.

With Type Safety

.vitepress/theme/index.ts

Building a Layout Component

Basic Layout

A layout needs at minimum the <Content /> component:
.vitepress/theme/Layout.vue

Handling 404 Pages

Use the useData() composable to detect 404 pages:

Multiple Layout Types

Support different layouts via frontmatter:
Then in your Markdown:

Using Runtime Data

Available Composables

VitePress provides several composables for accessing runtime data:

Accessing Page Data

Enhancing the App

Registering Global Components

.vitepress/theme/index.js
Now use them in Markdown:

Auto-Registering Components

Use Vite’s glob import:
.vitepress/theme/index.js

Installing Vue Plugins

.vitepress/theme/index.js

Adding Global State

.vitepress/theme/index.js

SSR Compatibility

Your theme must be SSR-compatible. Avoid accessing browser-only APIs during SSR.

Conditional Browser Code

Import Guards

Theme Styling

Scoped Styles

Global Styles

.vitepress/theme/index.js

CSS Variables

Distributing Your Theme

As npm Package

  1. Structure your package:
  1. Export the theme:
src/index.ts
  1. Package.json:
  1. Document usage:
README.md

As GitHub Template

Create a template repository with:
Users can then use “Use this template” to create their own repository.

Advanced Examples

Blog Theme

.vitepress/theme/Layout.vue

Documentation Theme with Sidebar

.vitepress/theme/Layout.vue

Complete Theme Example

.vitepress/theme/index.ts

Next Steps

Extending Default Theme

Build on top of the default theme instead

Runtime API

Explore available composables and utilities