Tabs and anchors

Customization•6 min read|
|

A single sidebar works for a small site. When your docs have distinct sections, such as guides, an API reference and a blog, tabs give each section its own sidebar. Anchors pin a few important links, such as a changelog or a community chat, to the top of the sidebar.

Tabs

Add a tabs array to docslit.json. Each tab has a name, an optional icon and its own sidebar, which uses the same groups as the top-level sidebar:

{ "tabs": [ { "tab": "Guides", "icon": "book-open", "sidebar": [ { "group": "Start", "pages": ["index", "guides/install"] }, { "group": "Operate", "pages": ["guides/deploy", "guides/webhooks"] } ] }, { "tab": "Reference", "icon": "terminal", "sidebar": [ { "group": "API", "pages": ["reference/api", "reference/cli"] } ] }, { "tab": "Blog", "href": "https://example.com/blog" } ] }

The active tab follows the page the reader is on, so the sidebar always shows the right section. When tabs is set, the top-level sidebar is ignored, and docslit validate tells you with tabs-sidebar-ignored.

The tab label. Aliases: label, title, name. A stable id for the tab. Defaults to a slug of the label. Use it in the tab frontmatter key. An icon before the label. See Icons. A small badge shown next to the label, such as New. The tab's sidebar groups, or "auto" to generate them from the folder in path, or from all of docs/ when path is absent. See Autogenerated sidebars. A folder under docs/ that belongs to the tab. It is the source for "sidebar": "auto", and it decides the tab of pages that no tab lists. The page id the tab opens. Defaults to the first visible page in its sidebar. Makes the tab a link to a URL, such as a blog on another domain. A link tab owns no pages and cannot have a sidebar. Add target to control how it opens. Keep the tab out of the tab bar. Its pages still work and still show their sidebar. Anchors that appear only while this tab is active. See Anchors. Marks the tab that holds the generated OpenAPI sidebar. If you use tabs and an OpenAPI spec but do not mark one, DocsLit adds an API Reference tab for those pages. Translated labels by locale, such as { "fr": "Guides" }.

Generate a tab from a folder

A tab with a path and "sidebar": "auto" builds its sidebar from the folder, so new pages appear without editing docslit.json:

{ "tabs": [ { "tab": "Guides", "path": "guides", "sidebar": "auto" }, { "tab": "Reference", "path": "reference", "sidebar": "auto" } ] }

A tab with only a path still claims the pages in that folder that no tab lists.

Place a page in a tab

A page belongs to the tab that lists it in its sidebar. Hidden pages and pages that no tab lists use the tab frontmatter key, naming the tab by label or id:

--- title: Runbook hidden: true tab: Reference ---

Without tab, an unlisted page joins the tab whose path covers it, and otherwise the first tab.

Where tabs appear

By default tabs sit in a bar under the header. Set layout.tabsPlacement to "sidebar" to put them at the top of the sidebar instead, which saves vertical space:

{ "layout": { "tabsPlacement": "sidebar" } } header for a bar under the header, or sidebar for tabs at the top of the sidebar. underline or pill. When set, it overrides a theme's own tab styling. See Themes. left or center, for the header placement.

On screens narrower than 1024 pixels the tab bar is hidden, and the tabs and the navbar links move into the navigation drawer, so every section stays reachable on a phone.

Tabs are styled with the --tab-* tokens, so you can change their spacing, colors and indicator in your own stylesheet.

Anchors

An anchor is a pinned link at the top of the sidebar, above the page groups. It is a good fit for destinations that are not part of the page tree.

{ "anchors": [ { "label": "Changelog", "href": "/changelog", "icon": "history", "tag": "New" }, { "label": "Community", "href": "https://example.com/community", "icon": "fa-brands fa-discord" } ] } The anchor text. A page path such as /changelog, or an external URL. External anchors open in a new tab. An icon shown before the label. A badge shown after the label.

Anchors in the top-level anchors array show in every sidebar. A tab can have its own anchors array, whose entries show only while that tab is active:

{ "tabs": [ { "tab": "Guides", "anchors": [{ "label": "Changelog", "href": "/changelog", "icon": "history" }], "sidebar": [{ "group": "Start", "pages": ["index"] }] } ] }

Check your navigation

docslit validate checks tabs and anchors. It reports an error for an unusable tabs array (tabs-invalid) and warns about a duplicate tab name (tab-duplicate-name), a page listed in two tabs (tab-duplicate-page), an empty tab (tab-empty), a missing landing page or path folder (tab-landing-missing, tab-path-missing), a link tab that also has pages (tab-href-with-pages), a bad anchor (anchor-invalid) and a frontmatter tab that matches no tab (frontmatter-unknown-tab).

Next steps

  • Add links, buttons and a GitHub star count to the header in Site chrome
  • Control column widths and the table of contents in Page layout
  • Move a Mintlify or Fern navigation with the importer