If you've ever deployed a VitePress site and noticed the browser tab still shows the default VitePress logo, you're not alone. Many developers assume that placing a favicon.ico in the public folder is enough, but VitePress requires a bit more configuration to properly link your icon. This guide walks you through the exact steps to set a custom favicon for your VitePress site, from file placement to verifying the result.

Prerequisites

Before you start, make sure you have:

Step 1: Place Your Favicon File in the Public Directory

VitePress uses Vite under the hood, so static assets should go into the public directory at the root of your project. Files in public are served at the root path and copied to the build output unchanged. For example, if you place favicon.ico in public, it will be accessible at /favicon.ico after building.

Create the public folder if it doesn't exist, and place your favicon file inside. You can also use a PNG or SVG file; just remember the filename.

your-project/
├── docs/
│   └── .vitepress/
│       └── config.js
├── public/
│   └── favicon.ico
└── package.json

Note: The public directory is relative to your VitePress project root (where package.json is). If you use the default structure with a docs folder, the public folder should be at the project root, not inside docs.

Step 2: Configure the Favicon in VitePress Config

VitePress allows you to define the <head> tags for your site via the head option in your config file. This is where you add the <link rel="icon"> tag.

Open your .vitepress/config.js (or .ts) and add the following:

import { defineConfig } from 'vitepress'

export default defineConfig({
  head: [
    ['link', { rel: 'icon', href: '/favicon.ico' }]
  ],
  // other config...
})

If you're using an SVG favicon, you can specify the type:

head: [
  ['link', { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }]
]

This tells VitePress to inject the link tag into the <head> of every page. The href should start with a slash (/) because the file is served from the root.

Step 3: Verify Your Favicon

After configuring, run your development server (npm run docs:dev or yarn docs:dev) and open your site in a browser. Check the tab—your favicon should appear. If it doesn't, try a hard refresh (Ctrl+F5 or Cmd+Shift+R) to bypass cache.

For production, build your site (npm run docs:build) and inspect the generated HTML in .vitepress/dist. Look for your <link rel="icon"> tag in the <head> section.

Common Pitfalls

Conclusion

Setting a favicon in VitePress is straightforward once you know where to place the file and how to configure the head tags. By following these steps, you ensure your site has a professional look in browser tabs, bookmarks, and search results. Remember to test in different browsers and clear caches when making changes. For a complete favicon solution, consider using Mzu favicondl to generate all necessary sizes and formats.

Check the documented requirements

Vite's public directory documentation explains how root-path assets are copied without transformation.