🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Astro Themes••By Komal Nakrani

Starlight Tutorial: Build a Docs Site with Astro

A step-by-step Starlight tutorial: create the project, write pages, configure the sidebar, add components, search, i18n and custom styles, then deploy your docs site.

#Astro#Starlight#Documentation#Tutorial

This Starlight tutorial takes you from an empty folder to a deployed documentation site in about an hour. Starlight is Astro’s official docs framework: you run npm create astro@latest -- --template starlight, write Markdown or MDX pages in src/content/docs/, configure the sidebar in astro.config.mjs, and get search, dark mode, navigation and accessible components without building them yourself.

Key Takeaways

  • Starlight is an Astro integration, so every Astro feature (components, islands, Content Collections) still works.
  • Pages are files in src/content/docs/; the URL follows the file path.
  • The sidebar can be written by hand, generated from a folder, or both.
  • Search (Pagefind), dark mode, a table of contents and edit links come built in.
  • The output is static HTML, so any static host can serve it.

What you will build

By the end you will have a docs site with a splash home page, a “Guides” section with ordered pages, a “Reference” section generated from a folder, callouts and tabs, full-text search, a custom accent color, and a production build deployed to a static host. The same structure scales from a five-page README replacement to hundreds of pages.

You need Node.js 22.23.4 or newer (required by Astro 7) and a code editor. Familiarity with Markdown is enough; you don’t need to know Astro yet.

Step 1: Create the Starlight project

Run the create command with the Starlight template:

npm create astro@latest -- --template starlight my-docs
cd my-docs
npm run dev

Open http://localhost:4321. You’ll see the starter splash page and a sample guide. The parts that matter:

my-docs/
├── astro.config.mjs        # Starlight config lives here
├── src/
│   ├── assets/             # images used in docs
│   ├── content/
│   │   └── docs/           # every docs page
│   │       ├── index.mdx
│   │       ├── guides/
│   │       └── reference/
│   └── content.config.ts   # registers the docs collection
└── public/                 # favicon and static files

The collection config is already set up for you:

// src/content.config.ts
import { defineCollection } from 'astro:content';
import { docsLoader } from '@astrojs/starlight/loaders';
import { docsSchema } from '@astrojs/starlight/schema';

export const collections = {
  docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }),
};

docsLoader() reads every Markdown, MDX and Markdoc file in src/content/docs/, and docsSchema() validates Starlight’s frontmatter. If you already have an Astro project, npx astro add starlight adds the integration instead.

Step 2: Configure the site

Open astro.config.mjs and set your title, social links and sidebar:

// astro.config.mjs
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';

export default defineConfig({
  site: 'https://docs.example.com',
  integrations: [
    starlight({
      title: 'Acme Docs',
      description: 'Install, configure and extend Acme.',
      social: [
        { icon: 'github', label: 'GitHub', href: 'https://github.com/acme/acme' },
      ],
      editLink: {
        baseUrl: 'https://github.com/acme/docs/edit/main/',
      },
      sidebar: [
        {
          label: 'Guides',
          items: [
            { label: 'Getting started', slug: 'guides/getting-started' },
            { label: 'Configuration', slug: 'guides/configuration' },
          ],
        },
        {
          label: 'Reference',
          autogenerate: { directory: 'reference' },
        },
      ],
    }),
  ],
});

site gives Starlight absolute URLs for canonical tags and the sitemap it generates. editLink adds an “Edit page” link to every page, which is the easiest way to get contributions. The “Guides” group is written by hand, so you control order. The “Reference” group lists every page in src/content/docs/reference/ automatically.

Step 3: Write your first pages

Create src/content/docs/guides/getting-started.md:

---
# src/content/docs/guides/getting-started.md
title: Getting started
description: Install Acme and run your first build in five minutes.
---

Acme turns a folder of YAML files into a typed API client.

## Install

Run the installer in your project:

    npm install acme

## First build

Create `acme.config.yaml` at the project root, then run `npx acme build`.

Only title is required. The file path sets the URL, so this page is served at /guides/getting-started/. Each ## heading appears in the right-hand table of contents automatically.

For autogenerated groups, control order with frontmatter:

---
# src/content/docs/reference/cli.md
title: CLI commands
sidebar:
  order: 1
  badge: New
---

Lower order numbers appear first. Our Starlight frontmatter cheatsheet lists every field, including template, hero, banner, prev/next and pagefind.

Step 4: Build the home page

The starter index.mdx uses the splash template, which removes sidebars, and a hero block:

---
# src/content/docs/index.mdx
title: Acme
description: A typed API client generated from YAML.
template: splash
hero:
  tagline: Write YAML, get a typed client.
  actions:
    - text: Get started
      link: /guides/getting-started/
      icon: right-arrow
    - text: View on GitHub
      link: https://github.com/acme/acme
      icon: external
      variant: minimal
---

import { Card, CardGrid } from '@astrojs/starlight/components';

<CardGrid>
  <Card title="Typed" icon="seti:typescript">Every endpoint returns typed data.</Card>
  <Card title="Fast" icon="rocket">Builds in milliseconds on every save.</Card>
</CardGrid>

Starlight components are imported from @astrojs/starlight/components and work in any .mdx page.

Step 5: Use callouts, tabs and steps

Starlight supports “asides” with a Markdown shorthand, so writers don’t need components for the most common case:

:::note
Acme reads `acme.config.yaml` from the project root.
:::

:::caution[Breaking change]
The `--legacy` flag was removed in version 3.
:::

The types are note, tip, caution and danger. In MDX pages you can also use tabs and numbered steps:

{/* src/content/docs/guides/configuration.mdx */}
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';

<Tabs syncKey="pkg">
  <TabItem label="npm">`npm install acme`</TabItem>
  <TabItem label="pnpm">`pnpm add acme`</TabItem>
</Tabs>

<Steps>
1. Create `acme.config.yaml`.
2. Add your first endpoint.
3. Run `npx acme build`.
</Steps>

syncKey keeps every tab group with the same key in sync, so a reader who picks pnpm once sees pnpm everywhere. Code blocks get syntax highlighting, copy buttons, titles and line markers through Expressive Code, configured with meta strings such as title="acme.config.yaml".

Step 6: Search, dark mode and navigation

You don’t add these; they work out of the box.

  • Search uses Pagefind, which indexes your built pages. It runs during npm run build, so test it with npm run preview rather than the dev server. Exclude a page with pagefind: false in frontmatter.
  • Dark mode follows the reader’s system setting, with a toggle in the header.
  • Navigation: previous and next links, a mobile menu, a skip link and a table of contents on each page.

If you are weighing Pagefind against a hosted service for larger docs, the Pagefind vs Algolia comparison covers the trade-offs. Starlight also has an official DocSearch plugin if your project qualifies for Algolia DocSearch.

Step 7: Brand it with custom CSS

Starlight exposes its design as CSS custom properties. Create a stylesheet and register it:

/* src/styles/custom.css */
:root {
  --sl-color-accent-low: #1e1b4b;
  --sl-color-accent: #6366f1;
  --sl-color-accent-high: #e0e7ff;
  --sl-font: 'Inter', system-ui, sans-serif;
}

:root[data-theme='light'] {
  --sl-color-accent: #4f46e5;
}
// astro.config.mjs (inside starlight({ ... }))
customCss: ['./src/styles/custom.css'],
logo: { src: './src/assets/logo.svg' },

For bigger changes, Starlight lets you override individual UI components (header, footer, page title and others) with your own Astro components through the components option, without forking the framework. Tailwind CSS is also supported through an official compatibility package.

Step 8: Add another language

Starlight has built-in i18n. Add locales to the config and put translated pages in matching folders:

// astro.config.mjs (inside starlight({ ... }))
defaultLocale: 'root',
locales: {
  root: { label: 'English', lang: 'en' },
  fr: { label: 'Français', lang: 'fr' },
},

With root as the default, English pages stay at src/content/docs/guides/... and French ones go in src/content/docs/fr/guides/.... A language picker appears in the header, and pages that aren’t translated yet fall back to the default language with a notice. UI strings such as “Search” and “On this page” are translated for many languages already.

Step 9: Build and deploy the docs site

npm run build
npm run preview

astro build writes static HTML to dist/, runs Pagefind, and generates a sitemap when site is set. Deploy that folder anywhere:

  • Cloudflare Pages, Netlify, Vercel: connect the repository, set the build command to npm run build and the output directory to dist.
  • GitHub Pages: use the official withastro/action GitHub Action, and set base in astro.config.mjs if the site lives at /repo-name/.

The deploy guide walks through each host, and the custom domains docs cover pointing docs.example.com at your build.

When Starlight is not the right fit

Starlight is built for documentation: sidebars, reference pages and long technical content. If your docs live inside a heavily branded marketing site, or the “docs” are really a knowledge base for customers, plain Astro with Content Collections may suit you better. The Astro or Starlight decision guide compares the two. Komal Nakrani’s documentation category holds only a small number of themes, and most are styled marketing and whitepaper sites rather than full docs frameworks, so for a pure docs site Starlight is usually the better starting point. The official Starlight docs are themselves built with Starlight.

FAQ

What is Starlight in Astro?

Starlight is Astro’s official framework for documentation sites, installed as an Astro integration. It provides a sidebar, full-text search with Pagefind, dark mode, i18n, accessible components and SEO defaults, while still letting you use any Astro component or UI framework island.

How do I start a Starlight project?

Run npm create astro@latest -- --template starlight and follow the prompts, then npm run dev. To add Starlight to an existing Astro project, run npx astro add starlight and create a docs collection with docsLoader() and docsSchema() in src/content.config.ts.

Is Starlight free?

Yes. Starlight is open source under the MIT license and maintained by the Astro team. It builds a static site, so you can host it for free on Cloudflare Pages, Netlify, Vercel or GitHub Pages.

How do I change the order of pages in the Starlight sidebar?

List pages in the order you want in the sidebar config, or use autogenerate for a folder and set sidebar.order in each page’s frontmatter. Lower numbers appear first. Pages without an order are sorted alphabetically after ordered ones.

Can I use React or Vue components in Starlight?

Yes. Starlight is an Astro integration, so you can add @astrojs/react, @astrojs/vue or another framework and use those components in MDX pages, hydrated with a client:* directive when they need interactivity.