npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vitepress-plugin-outline-depth

v1.2.2

Published

VitePress plugin that controls the heading level depth of the sidebar (outline / table of contents)

Readme

vitepress-plugin-outline-depth

npm GitHub License: MIT

A VitePress plugin that adds controls to the documentation sidebar (outline / table of contents), allowing readers to control how many heading levels are displayed in the page outline.

When the depth is set to 2, only <h2> headings are shown; set it to 6 and all heading levels from <h2> through <h6> are visible. The Auto Expand toggle controls whether the outline automatically expands to reveal the section the reader is currently viewing. For example, with depth set to 2, all other <h2> groups stay collapsed while the currently active section expands from its ancestor <h2> all the way down to the current heading.

Note: When the outline depth is set to 6, the Auto Expand toggle has no effect — since every heading level is already visible, expanding or collapsing makes no difference.

Important: The maximum depth is subject to the default theme configuration themeConfig.outline.level. It is recommended to set it to the "deep" value.

Screenshot

Installation

# npm
npm install vitepress-plugin-outline-depth

# yarn
yarn add vitepress-plugin-outline-depth

# pnpm
pnpm add vitepress-plugin-outline-depth

Usage

Import the plugin in your VitePress config file (.vitepress/config.ts) and add it to the vite.plugins array:

import { defineConfig } from "vitepress";
import outlineDepthPlugin from "vitepress-plugin-outline-depth";

export default defineConfig({
  vite: {
    plugins: [outlineDepthPlugin(/* options */)],
  },
});

That's it. The plugin automatically injects its controls into the default VitePress theme and applies the necessary CSS.

Configuration

The plugin accepts an optional OutlineDepthPluginOptions object. All properties are optional.

defaultDepth

  • Type: 2 | 3 | 4 | 5 | 6
  • Default: 2

Sets the initial value of the outline depth slider — the number of heading levels visible in the outline.

If set to 6, note that the Auto Expand toggle becomes effectively a no-op (all heading levels are visible regardless).

defaultAutoExpand

  • Type: boolean
  • Default: true

Sets the initial state of the Auto Expand toggle. When enabled, the outline automatically expands to show the heading hierarchy around the currently active heading. When disabled, all headings beyond the set depth remain collapsed regardless of which section is being read.

minDepth

  • Type: 2 | 3 | 4 | 5 | 6
  • Default: 2

The minimum value the outline depth slider can be set to. Must be less than maxDepth.

maxDepth

  • Type: 2 | 3 | 4 | 5 | 6
  • Default: 6

The maximum value the outline depth slider can be set to. Must be greater than minDepth.

Note that the maximum depth is subject to the default theme configuration themeConfig.outline.level. It is recommended to set it to the "deep" value.

locales

  • Type: Record<string, { depth: string; autoExpand: string }>
  • Default: {}

Custom translations for the UI labels. The plugin resolves the locale by matching against the VitePress site's lang setting. Built-in translations are provided for:

| Language | depth label | autoExpand label | |----------|---------------|---------------------| | English (en) | Outline depth | Auto expand | | Simplified Chinese (zh) | 目录层级 | 自动展开 |

To add or override translations, pass a locale key:

outlineDepthPlugin({
  locales: {
    ja: {
      depth: "アウトラインの深さ",
      autoExpand: "自動展開",
    },
  },
});

The locale matching follows standard Intl.Locale fallback logic. For example, zh-CN falls back to zh, which is built-in. An unrecognized language falls back to English.

saveToLocalStorage

  • Type: boolean
  • Default: true

When enabled, the reader's outline depth and auto-expand preferences are saved to localStorage and restored on subsequent page visits.

stickAtTop

  • Type: boolean
  • Default: true

When enabled, the outline depth controls stick to the top of the sidebar outline area as the reader scrolls, so they remain accessible without scrolling back up.

scrollActiveOutlineLinkIntoView

  • Type: boolean
  • Default: true

When enabled, the active outline link (the marker indicating the current heading) is automatically scrolled into view as the reader scrolls through the page content.

setConfigOutlineLevelToDeep

  • Type: boolean
  • Default: true

When enabled, the .vitepress.config.js/ts user config themeConfig.outline.level will set to the "deep" value in every locales.

Full Example

import { defineConfig } from "vitepress";
import outlineDepthPlugin from "vitepress-plugin-outline-depth";

export default defineConfig({
  lang: "en",
  vite: {
    plugins: [
      outlineDepthPlugin({
        defaultDepth: 2,
        defaultAutoExpand: true,
        minDepth: 2,
        maxDepth: 6,
        saveToLocalStorage: true,
        stickAtTop: true,
        scrollActiveOutlineLinkIntoView: true,
        locales: {
          ja: {
            depth: "アウトラインの深さ",
            autoExpand: "自動展開",
          },
        },
      }),
    ],
  },
});

License

MIT