Starlight Docs Sites
What is Starlight?
Section titled “What is Starlight?”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)
Quick Setup
Section titled “Quick Setup”npm create astro@latest -- --template starlightConfiguration
Section titled “Configuration”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' }, }, ], }), ],});Content Structure
Section titled “Content Structure”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.mdSidebar Configuration
Section titled “Sidebar Configuration”Manual Items
Section titled “Manual Items”sidebar: [ { label: 'Guides', items: [ { label: 'Getting Started', slug: 'guides/getting-started' }, { label: 'Advanced', slug: 'guides/advanced' }, ], },]Auto-Generated from Directory
Section titled “Auto-Generated from Directory”sidebar: [ { label: 'Reference', autogenerate: { directory: 'reference' }, },]Collapsed Groups
Section titled “Collapsed Groups”sidebar: [ { label: 'Advanced', collapsed: true, items: [/* ... */], },]External Links
Section titled “External Links”sidebar: [ { label: 'Resources', items: [ { label: 'Astro Docs', link: 'https://docs.astro.build' }, ], },]Gotchas
Section titled “Gotchas”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' }, ], },]autogeneratedoesn’t create index pages: If you useautogenerate: { directory: 'guides' }, it picks up files in that directory but won’t generate an overview page. Create anindex.mdmanually.- Ordering in autogenerated groups: Use
sidebar.orderin page frontmatter to control the order within autogenerated groups.
Page Frontmatter
Section titled “Page Frontmatter”---title: My Page Titledescription: 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 accessibletableOfContents: minHeadingLevel: 2 maxHeadingLevel: 4---Built-in Components
Section titled “Built-in Components”Cards and LinkCards
Section titled “Cards and LinkCards”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>Asides (Callouts)
Section titled “Asides (Callouts)”:::noteThis is a note.:::
:::tipThis is a helpful tip.:::
:::cautionBe careful with this.:::
:::dangerThis could break things!:::import { Steps } from '@astrojs/starlight/components';
<Steps>1. Install the package2. Configure the settings3. 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/...Customization
Section titled “Customization”Custom CSS
Section titled “Custom CSS”starlight({ customCss: ['./src/styles/custom.css'],}),Override Components
Section titled “Override Components”starlight({ components: { Header: './src/components/CustomHeader.astro', Footer: './src/components/CustomFooter.astro', },}),Updating Starlight
Section titled “Updating Starlight”npx @astrojs/upgrade