Skip to content

Sidebar Navigation

Learn how to set up and customize your Starlight site’s sidebar navigation links.

A well-organized sidebar is key to a good documentation as it is one of the main ways users will navigate your site. Starlight provides a complete set of options to customize your sidebar layout and content.

By default, Starlight will automatically generate a sidebar based on the filesystem structure of your documentation, using each file’s title property as the sidebar entry.

For example, given the following file structure:

The following sidebar will be automatically generated:

Learn more about autogenerated sidebars in the autogenerated links section.

To configure your sidebar links and groups of links (within a collapsible header), use the starlight.sidebar property in astro.config.mjs.

By combining links and groups, you can create a wide variety of sidebar layouts.

Add a link to a page in src/content/docs/ using an object with the slug property. The linked page’s title will be used as the label by default.

For example, with the following configuration:

starlight({
sidebar: [
{ slug: 'constellations/andromeda' },
{ slug: 'constellations/orion' },
],
});

And the following file structure:

The following sidebar will be generated:

To override the values inferred from a linked page’s frontmatter, you can add label, translations, and attrs properties.

See “Customizing autogenerated links” for more details about controlling the sidebar appearance from page frontmatter.

Internal links can also be specified by providing only a string for the page slug as a shorthand.

For example, the following configuration is equivalent to the configuration above, which used slug:

starlight({
sidebar: ['constellations/andromeda', 'constellations/orion'],
});

Add a link to an external or non-docs page using an object with label and link properties.

starlight({
sidebar: [
// A link to a non-docs page on this site.
{ label: 'Meteor Store', link: '/shop/' },
// An external link to the NASA website.
{ label: 'NASA', link: 'https://www.nasa.gov/' },
],
});

The configuration above generates the following sidebar:

You can add structure to your sidebar by grouping related links together under a collapsible heading. Groups can contain both links and other sub-groups.

Add a group using an object with label and items properties. The label will be used as the heading for the group. Add links or subgroups to the items array.

starlight({
sidebar: [
// A group of links labelled "Constellations".
{
label: 'Constellations',
items: [
'constellations/carina',
'constellations/centaurus',
// A nested group of links for seasonal constellations.
{
label: 'Seasonal',
items: [
'constellations/andromeda',
'constellations/orion',
'constellations/ursa-minor',
],
},
],
},
],
});

The configuration above generates the following sidebar:

Starlight can automatically generate links in your sidebar based on a directory of your docs. This is helpful when you do not want to manually enter each sidebar item in a group.

By default, pages are sorted in alphabetical order according to the file id.

Add autogenerated links using an object with the autogenerate property. Your autogenerate configuration must specify the directory to use for sidebar entries. For example, with the following configuration:

starlight({
sidebar: [
{
label: 'Constellations',
// Autogenerate links for the 'constellations' directory.
items: [{ autogenerate: { directory: 'constellations' } }],
},
],
});

And the following file structure:

The following sidebar will be generated:

Section titled “Customizing autogenerated links in frontmatter”

Use the sidebar frontmatter field in individual pages to customize autogenerated links.

Sidebar frontmatter options allow you to set a custom label, use custom attributes, add a badge to a link, hide a link from the sidebar, or define a custom sort weighting.

src/content/docs/example.md
---
title: My page
sidebar:
# Set a custom label for the link
label: Custom sidebar label
# Set a custom order for the link (lower numbers are displayed higher up)
order: 2
# Add a badge to the link
badge:
text: New
variant: tip
---

A group with autogenerated links including a page with the frontmatter above will generate the following sidebar: