--- layout: layouts/page.njk title: Tabs description: A set of layered sections of content—known as tab panels—that are displayed one at a time. toc: - label: Usage id: usage children: - label: HTML + JavaScript id: usage-default children: - label: "Step 1: Include the JavaScript files" id: usage-html-js-1 - label: "Step 2: Add your select HTML" id: usage-html-js-2 - label: HTML structure id: usage-html-js-3 - label: JavaScript events id: usage-html-js-4 - label: Jinja and Nunjucks id: usage-macro --- {% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %} {% from "tabs.njk" import tabs %} {% set code_html %} {% set account_panel %}

Account

Make changes to your account here. Click save when you're done.

{% endset %} {% set password_panel %}

Password

Change your password here. After saving, you'll be logged out.

{% endset %} {% set tabsets_demo = [ { tab: "Account", panel: account_panel }, { tab: "Password", panel: password_panel } ] %} {{ tabs( id='demo-tabs-with-panels', tabsets=tabsets_demo, main_attrs={ "class": "w-full" }, tablist_attrs={ "class": "w-full" } ) }} {% endset %} {{ code_preview("tabs", code_html | prettyHtml, "max-w-[300px] w-full") }}

Usage

Step 1: Include the JavaScript files

You can either include the JavaScript file for all the components, or just the one for this component by adding this to the <head> of your page:

{% set code_script %}{% endset %} {{ code_block(code_script | prettyHtml, "html") }}
Components with JavaScript {% lucide "arrow-right" %} Use the CLI {% lucide "arrow-right" %} tabs.js {% lucide "arrow-right" %}

Step 2: Add your select HTML

{{ code_block(code_html | prettyHtml, "html") }}

HTML structure

<div class="tabs">
Wraps around the entire component.
<nav role="tablist" aria-orientation="horizontal">
The tablist containing the tab buttons
<button role="tab" id="{ TAB_ID }" aria-controls="{ PANEL_ID }" aria-selected="false" tabindex="0">
The tab button. When active, the aria-selected attribute is set to true. tabindex="0" is required for keyboard navigation.
<div role="tabpanel" id="{ PANEL_ID }" aria-labelledby="{ TAB_ID }" tabindex="-1" aria-selected="false">
The tab panel. When active, the aria-selected attribute is set to true.

JavaScript events

basecoat:initialized
Once the component is fully initialized, it dispatches a custom (non-bubbling) basecoat:initialized event on itself.

Jinja and Nunjucks

You can use the tabs() Nunjucks or Jinja macro for this component.

Use Nunjucks or Jinja macros {% lucide "arrow-right" %} Jinja macro {% lucide "arrow-right" %} Nunjucks macro {% lucide "arrow-right" %}
{% set raw_code %}{% raw %}{% set account_panel %}

Account

Make changes to your account here. Click save when you're done.

{% endset %} {% set password_panel %}

Password

Change your password here. After saving, you'll be logged out.

{% endset %} {% set tabsets_demo = [ { tab: "Account", panel: account_panel }, { tab: "Password", panel: password_panel } ] %} {{ tabs( id='demo-tabs-with-panels', tabsets=tabsets_demo, main_attrs={ "class": "w-full" }, tablist_attrs={ "class": "w-full" } ) }}{% endraw %}{% endset%} {{ code_block(raw_code, "jinja") }}