---
title: Autogenerated sidebars
description: Build the sidebar from your docs folder with sidebar auto or autogenerate, order pages with sidebar_position, and control labels and collapsing with _category.json.
tag: Writing
readtime: 5 min read
---
> For AI agents: the complete documentation index is at [llms.txt](https://docs.docslit.com/0.3/llms.txt). This page as Markdown: [writing-content/autogenerated-sidebars.md](https://docs.docslit.com/0.3/writing-content/autogenerated-sidebars.md).


# Autogenerated sidebars

An explicit sidebar lists every page by hand. For large or fast-changing docs, let DocsLit build it from the folders in `docs/`. New pages appear automatically, which suits teams and AI agents that add pages often.

You can generate the whole sidebar, or only some groups.

## Generate the whole sidebar

Set `sidebar` to the string `"auto"`:

```json filename="docslit.json"
{
  "name": "Acme",
  "sidebar": "auto"
}
```

- Pages directly in `docs/` go into one group named after your site `name`.
- Each top-level folder becomes a group. Its label is the folder name in title case, so `getting-started` becomes "Getting Started".
- Deeper folders become nested subgroups.
- Folders with no pages, and any file or folder that starts with `_` or `.`, are skipped.

## Start without a config file

When a project has no `docslit.json`, DocsLit uses an automatic sidebar, the same as `"sidebar": "auto"`, and takes the site name from the folder name. Add a `docslit.json` later to set a name or an explicit sidebar. Commands that edit the config, such as `docslit new` and `docslit theme use`, need a real `docslit.json`.

## Generate one group

Add `autogenerate` to a group in an otherwise explicit sidebar. Explicit pages come first, then the generated ones:

```json filename="docslit.json"
{
  "sidebar": [
    { "group": "Start here", "pages": ["index"] },
    { "group": "Guides", "autogenerate": "guides" },
    { "group": "Reference", "autogenerate": { "directory": "reference", "collapsed": true } }
  ]
}
```

`autogenerate` takes a folder under `docs/`, or an object with `directory` and `collapsed`. A page that you list explicitly anywhere in the sidebar is not generated a second time. A bad folder, or one with no pages, produces a warning at build time.

## Order pages

Within a folder, DocsLit sorts like this:

1. Items with `sidebar_position` come first, lowest number first. Pages and subfolders share the same numbers.
2. Then `index`, `introduction` and `overview` pages.
3. Then other pages by file name.
4. Then subgroups by folder name.

Set the position in a page's frontmatter:

```yaml
---
title: Set up
sidebar_position: 1
---
```

## Labels and hiding

A page's sidebar label is its frontmatter `title`. Hide a page from a generated sidebar with `sidebar: false`:

```yaml
---
title: Internal notes
sidebar: false
---
```

A hidden page still builds and is reachable by URL. `validate` does not report it as an orphan.

## Configure a folder with _category.json

Put a `_category.json` file in a folder to set its group label, position and collapsed state:

```json filename="docs/guides/advanced/_category.json"
{
  "label": "Advanced topics",
  "position": 9,
  "collapsed": false
}
```

<wc-fields header="_category.json keys">
<wc-field name="label" type="string">
The group heading. Default: the folder name in title case.
</wc-field>
<wc-field name="position" type="number">
Sort position among its siblings, like `sidebar_position` on a page.
</wc-field>
<wc-field name="collapsed" type="boolean">
Render the group collapsed or expanded. Overrides the `collapsed` value of the parent `autogenerate`.
</wc-field>
</wc-fields>

Invalid JSON in a `_category.json` file is ignored with a warning. The file is read for subfolders. To label the top-level folder of an `autogenerate` source, use the `group` name in `docslit.json`.

## Collapsible groups

Any sidebar group, explicit or generated, can collapse. Add a boolean `collapsed`:

```json filename="docslit.json"
{
  "sidebar": [
    {
      "group": "API reference",
      "collapsed": true,
      "pages": ["api/overview", "api/users"]
    }
  ]
}
```

`collapsed: true` starts the group closed and `collapsed: false` starts it open. Groups without the key stay plain, always-open headings.

The group that contains the current page always opens, and a search filter opens matching groups. When a reader opens or closes a group, DocsLit remembers the choice in their browser.

## Add pages to an autogenerated sidebar

`docslit new` does not edit the sidebar when the page falls under an autogenerated source. It reports `"autogenerated": true` and the page appears on its own. `docslit dev` rebuilds the sidebar when you add, remove or rename pages, change `sidebar_position`, or edit a `_category.json`.

Autogeneration also works with [versions](../customization/versioning) and with per-locale sidebars in `sidebars`.
