Tabs and accordions

Components•4 min read|
|

Use tabs to organize alternative content (like platform-specific instructions) and accordions for expandable sections (like FAQs).

Tabs

Style tabs with ::part(): tab-bar, tab and panel. Accordions and expandables have summary and content. See Custom CSS.

Tabs let readers switch between related content panels without leaving the page:

<wc-tabs> <wc-tab label="macOS"> Install with Homebrew: ```bash brew install node ``` </wc-tab> <wc-tab label="Linux"> Install with your package manager: ```bash sudo apt install nodejs ``` </wc-tab> <wc-tab label="Windows"> Download the installer from [nodejs.org](https://nodejs.org). </wc-tab> </wc-tabs>

Install with Homebrew:

brew install node

Install with your package manager:

sudo apt install nodejs

Download the installer from nodejs.org.

The zero-based index of the tab shown first. Add a bottom border and spacing below the tabs, to separate them from the content that follows. A key shared by groups that should switch together. See Synced tabs. Pin the tabs to dark or light. The text on the tab button. Inline Markdown works. It is also the deep-link id: its slug opens the tab. An icon before the label.

Arrow keys, Home and End move between tabs, and a # fragment in the URL that matches a tab's slug opens that tab. For example, #windows opens the Windows tab above. Tabs with icons and a default tab:

<wc-tabs default-tab="1"> <wc-tab label="npm" icon="box"> Install with npm. </wc-tab> <wc-tab label="Docker" icon="fa-brands fa-docker"> Run the image. This tab is open first. </wc-tab> </wc-tabs>

Install with npm.

Run the image. This tab is open first.

Synced tabs

Give several tab groups the same sync key and they switch together. A reader who picks "pnpm" in one place sees "pnpm" everywhere on the site. Tabs match by label, so the label text must be identical, and a group without a matching label stays as it is.

<wc-tabs sync="pkg"> <wc-tab label="npm"> ```bash npm install docslit ``` </wc-tab> <wc-tab label="pnpm"> ```bash pnpm add docslit ``` </wc-tab> </wc-tabs>

sync works on wc-tabs and on wc-code-group, and a wc-tabs can sync with a wc-code-group that uses the same key and labels. The choice is saved in the reader's browser. Try it here: switch either group and the other follows.

Use Homebrew on macOS.

Use your distribution's package manager.

brew install node sudo apt install nodejs

When to use tabs

  • Platform-specific instructions (macOS, Linux, Windows)
  • Package manager alternatives (npm, pnpm, yarn)
  • Language variants (JavaScript, Python, Go)
  • Framework-specific examples (React, Vue, Angular)

Accordions

Accordions hide content behind a clickable title. Readers expand only the sections they need:

<wc-accordion-group> <wc-accordion title="How do I install DocsLit?"> Run `npm install -g docslit` or use `npx` to run it without installing. </wc-accordion> <wc-accordion title="What Node.js version do I need?"> DocsLit requires Node.js 22.22.0 or later. </wc-accordion> </wc-accordion-group>

Run npm install -g docslit or use npx to run it without installing.

DocsLit requires Node.js 22.22.0 or later.

The clickable heading text that toggles the section. Inline Markdown works. Smaller text under the title. A leading icon. Expand the item by default. The anchor id. A URL that ends in #id opens the item. Without it, the slug of the title is used.

An accordion is a real button with aria-expanded, so it works from the keyboard and with screen readers, and the in-page search can find text inside a closed item. Here is one with a description, an icon and a deep link:

<wc-accordion-group> <wc-accordion title="Which Node.js version do I need?" description="Short answer: 22.22 or later" icon="circle-help" id="node-version"> DocsLit requires Node.js 22.22.0 or later. </wc-accordion> </wc-accordion-group>

DocsLit requires Node.js 22.22.0 or later.

Accordion groups

Wrap accordions in wc-accordion-group for a visually connected set with continuous borders:

<wc-accordion-group> <wc-accordion title="Can I use custom components?"> Yes. Place `.js` files in the `components/` directory and they load automatically. </wc-accordion> <wc-accordion title="Does DocsLit support versioning?"> Yes. Configure `versions` in `docslit.json` to maintain docs for multiple releases. </wc-accordion> <wc-accordion title="Can I deploy to any hosting provider?"> Yes. The `docslit build` output is a standard static site that works anywhere. </wc-accordion> </wc-accordion-group>

Yes. Place .js files in the components/ directory and they load automatically.

Yes. Configure versions in docslit.json to maintain docs for multiple releases.

Yes. The docslit build output is a standard static site that works anywhere.

Expandable sections

Use wc-expandable for a simpler collapsible section:

<wc-expandable title="Show advanced options"> These options are for advanced users who need fine-grained control over the build output. - `--offline` — Build a self-contained offline site - `--out <dir>` — Custom output directory </wc-expandable>

These options are for advanced users who need fine-grained control over the build output.

  • --offline — Build a self-contained offline site
  • --out <dir> — Custom output directory
The clickable heading that toggles the section. Smaller text under the title. A leading icon. Expand the section by default.

wc-expandable behaves like wc-accordion. It is meant for nested content, such as the properties of an object in an API field list.

Views

wc-view is a switcher for alternative views of the same content, such as a language or a platform. Its panels are wc-view-panel elements with a label and an optional icon. Give several view groups the same sync key, and they switch together.

<wc-view sync="api-style"> <wc-view-panel label="REST" icon="globe"> Call the HTTP API directly. ```bash curl https://api.example.com/events ``` </wc-view-panel> <wc-view-panel label="SDK" icon="package"> Use the client library. ```js await client.events.list(); ``` </wc-view-panel> </wc-view>

Call the HTTP API directly.

curl https://api.example.com/events

Use the client library.

await client.events.list();
A key shared by view groups that switch together. Panels match by label. The text on the toggle button. An icon before the label.

Use tabs for content that readers pick once, and views when the choice is a preference that applies across the page.