Skip to content

Starlight Docs Sites

Starlight is a full-featured documentation theme built on Astro. It provides:

  • Sidebar navigation with auto-generation
  • Search (powered by Pagefind)
  • i18n support
  • Dark/light mode
  • Built-in components (cards, tabs, asides)
Terminal window
npm create astro@latest -- --template starlight
astro.config.mjs
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
export default defineConfig({
integrations: [
starlight({
title: 'My Docs',
social: [
{ icon: 'github', label: 'GitHub', href: 'https://github.com/...' },
],
sidebar: [
{
label: 'Getting Started',
items: [
{ label: 'Installation', slug: 'getting-started/installation' },
{ label: 'Quick Start', slug: 'getting-started/quick-start' },
],
},
{
label: 'Reference',
autogenerate: { directory: 'reference' },
},
],
}),
],
});
src/content/docs/
index.mdx # Home page
getting-started/
installation.md
quick-start.md
guides/
routing.md
deployment.md
reference/
api.md # Auto-generated sidebar picks these up
config.md
sidebar: [
{
label: 'Guides',
items: [
{ label: 'Getting Started', slug: 'guides/getting-started' },
{ label: 'Advanced', slug: 'guides/advanced' },
],
},
]
sidebar: [
{
label: 'Reference',
autogenerate: { directory: 'reference' },
},
]
sidebar: [
{
label: 'Advanced',
collapsed: true,
items: [/* ... */],
},
]
sidebar: [
{
label: 'Resources',
items: [
{ label: 'Astro Docs', link: 'https://docs.astro.build' },
],
},
]
sidebar: [
{
label: 'Guides',
// WRONG: Cannot combine link + items
// link: '/guides/',
// items: [...]
// CORRECT: Use index page as first item
items: [
{ label: 'Overview', slug: 'guides' }, // points to guides/index.md
{ label: 'Getting Started', slug: 'guides/getting-started' },
],
},
]
  • autogenerate doesn’t create index pages: If you use autogenerate: { directory: 'guides' }, it picks up files in that directory but won’t generate an overview page. Create an index.md manually.
  • Ordering in autogenerated groups: Use sidebar.order in page frontmatter to control the order within autogenerated groups.
---
title: My Page Title
description: A description for SEO and social sharing.
sidebar:
order: 2 # Manual ordering within auto-generated groups
label: Custom Label # Override the title in sidebar
badge:
text: New
variant: tip # tip | note | danger | caution | success
hidden: false # Hide from sidebar but keep accessible
tableOfContents:
minHeadingLevel: 2
maxHeadingLevel: 4
---
import { Card, CardGrid, LinkCard } from '@astrojs/starlight/components';
{/* Card = display-only, does NOT support href */}
<CardGrid>
<Card title="Feature One" icon="rocket">
Description as children content.
</Card>
<Card title="Feature Two" icon="puzzle">
Description as children content.
</Card>
</CardGrid>
{/* LinkCard = clickable, takes href + description as PROPS (not children) */}
<CardGrid>
<LinkCard title="Getting Started" href="/guides/getting-started/" description="Learn setup" />
<LinkCard title="Configuration" href="/reference/configuration/" description="Config options" />
</CardGrid>
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs>
<TabItem label="npm">
```bash
npm install astro
```
</TabItem>
<TabItem label="pnpm">
```bash
pnpm add astro
```
</TabItem>
</Tabs>
:::note
This is a note.
:::
:::tip
This is a helpful tip.
:::
:::caution
Be careful with this.
:::
:::danger
This could break things!
:::
import { Steps } from '@astrojs/starlight/components';
<Steps>
1. Install the package
2. Configure the settings
3. Deploy your site
</Steps>
starlight({
title: 'My Docs',
defaultLocale: 'en',
locales: {
en: { label: 'English' },
es: { label: 'Español', lang: 'es' },
fr: { label: 'Français', lang: 'fr' },
},
}),

Content structure for i18n:

src/content/docs/
en/
index.md
guides/...
es/
index.md
guides/...
starlight({
customCss: ['./src/styles/custom.css'],
}),
starlight({
components: {
Header: './src/components/CustomHeader.astro',
Footer: './src/components/CustomFooter.astro',
},
}),
Terminal window
npx @astrojs/upgrade