--- layout: layouts/component.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 - label: Jinja or Nunjucks id: usage-jinja --- {% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %} {% from "components/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" }, register_on=["alpine:init", "htmx:afterSwap"] ) }} {% endset %} {% set code_script %} {% include "components/tabs-script.njk" %} {% endset %} {{ code_preview("tabs", code_script | prettyHtml ~ code_html | prettyHtml, "max-w-[300px] w-full") }}

Usage

HTML + Javascript

{% lucide "circle-alert" %}

This component requires Javascript.

You will need to include the Javascript (Alpine.js) code provided below before the HTML code for this component. As with all interactive components, you will need to add some Alpine.js properties to certain elements (e.g. x-bind, x-data, @click).

The component is structured as such:

{% from "components/tabs.njk" import tabs %} {% set tabsets = [ { tab: "HTML", panel: code_block(code_html | prettyHtml) }, { tab: "Javascipt (Alpine.js)", panel: code_block(code_script | prettyHtml) } ] %} {{ tabs(id="combobox", tabsets=tabsets) }}

Jinja or Nunjucks

If you use Jinja (or Nunjucks), you can use the tabs() macro directly. Read more about using Basecoat with Jinja and Nunjucks.

{% 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" }, register_on=["alpine:init", "htmx:afterSwap"] ) }}{% endraw %}{% endset%} {{ code_block(raw_code, "jinja") }}