The quickest way to create a new Starlight site is using `create astro` as shown in the [Getting Started guide](/guides/start-here-getting-started#create-a-new-project).
If you want to add Starlight to an existing Astro project, this guide will explain how.

## Set up Starlight

To follow this guide, you’ll need an [existing Astro project](https://docs.astro.build/en/install-and-setup/).

### Add the Starlight integration

Starlight is an [Astro integration](https://docs.astro.build/en/guides/integrations-guide/). Add it to your site by running the `astro add` command in your project’s root directory:

::::tabs{sync="pkg"}
:::tab{title="npm"}
```sh
npx astro add starlight
```
:::

:::tab{title="pnpm"}
```sh
pnpm astro add starlight
```
:::

:::tab{title="Yarn"}
```sh
yarn astro add starlight
```
:::
::::

This will install the required dependencies and add Starlight to the `integrations` array in your Astro config file.

### Configure the integration

The Starlight integration is configured in your `astro.config.mjs` file.

Add a `title` to get started:

```js ins={8}
// astro.config.mjs
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';

export default defineConfig({
	integrations: [
		starlight({
			title: 'My delightful docs site',
		}),
	],
});
```

Find all available options in the [Starlight configuration reference](/guides/reference-configuration).

### Configure content collections

Starlight is built on top of Astro’s [content collections](https://docs.astro.build/en/guides/content-collections/), which are configured in the `src/content.config.ts` file.

Create or update the content config file, adding a `docs` collection that uses Starlight’s [`docsLoader`](/guides/reference-configuration#docsloader) and [`docsSchema`](/guides/reference-configuration#docsschema):

```js ins={3-4,7}
// 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() }),
};
```

Starlight also supports the [`legacy.collectionsBackwardsCompat` flag](https://docs.astro.build/en/reference/legacy-flags/#collectionsbackwardscompat) which preserves some legacy v4 content collections features.
This is useful if you have an existing Astro project and are unable to make any changes to collections at this time to migrate to the Content Layer API introduced in v5.0.

### Add content

Starlight is now configured and it’s time to add some content!

Create a `src/content/docs/` directory and start by adding an `index.md` file.
This will be the homepage of your new site:

```md
---
# src/content/docs/index.md
title: My docs
description: Learn more about my project in this docs site built with Starlight.
---

Welcome to my project!
```

Starlight uses file-based routing, which means every Markdown, MDX, or Markdoc file in `src/content/docs/` will turn into a page on your site. Frontmatter metadata (the `title` and `description` fields in the example above) can change how each page is displayed.
See all the available options in the [frontmatter reference](/guides/reference-frontmatter).

## Tips for existing sites

If you have an existing Astro project, you can use Starlight to quickly add a documentation section to your site.

### Use Starlight at a subpath

To add all Starlight pages at a subpath, place all your docs content inside a subdirectory of `src/content/docs/`.

For example, if Starlight pages should all start with `/guides/`, add your content in the `src/content/docs/guides/` directory:

- src/
  - content/
    - docs/
      - **guides/**
        - guide.md
        - index.md
  - pages/
- astro.config.mjs

In the future, we plan to support this use case better to avoid the need for the extra nested directory in `src/content/docs/`.

### Use Starlight with SSR

To enable SSR, follow the [“On-demand Rendering Adapters”](https://docs.astro.build/en/guides/on-demand-rendering/) guide in Astro’s docs to add a server adapter to your Starlight project.

Documentation pages generated by Starlight are pre-rendered by default regardless of your project's output mode. To opt out of pre-rendering your Starlight pages, set the [`prerender` config option](/guides/reference-configuration#prerender) to `false`.

If you are using the [Cloudflare adapter](https://docs.astro.build/en/guides/integrations-guide/cloudflare/) to enable server-rendering in your documentation project, make sure to also [add the `nodejs_compat` compatibility flag to your Wrangler configuration file](https://developers.cloudflare.com/workers/runtime-apis/nodejs/#get-started).

## Related pages

- [Starlight](../index.md)
- [Using Components](./components-using-components.md)
- [Pages](./guides-pages.md)
- [Not found](./more-404.md)
- [Configuration Reference](./reference-configuration.md)
- [Plugins and Integrations](./resources-plugins.md)
- [Start Here](./start-here-index.md)
- [Getting Started](./start-here-getting-started.md)
- [Cards](./components-cards.md)
- [Guides](./guides-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
