<content-tabs>
Accessible tabs: a tablist of buttons and the panels they show, with arrow key support.
import '@content-blocks/js/components/content-tabs';Examples
Tabs
The tabs follow the WAI-ARIA pattern, so the arrow keys move between them.
<content-tabs>
<div role="tablist" aria-label="The foes">
<button role="tab" id="example-tab-monthly" aria-selected="true" aria-controls="example-panel-monthly">The serpent</button>
<button role="tab" id="example-tab-yearly" aria-selected="false" aria-controls="example-panel-yearly" tabindex="-1">The wolf</button>
</div>
<div role="tabpanel" id="example-panel-monthly" aria-labelledby="example-tab-monthly" tabindex="0">
<content-line tag="p" padding="1rem 0 0">Coiled around the world, and rising from the sea.</content-line>
</div>
<div role="tabpanel" id="example-panel-yearly" aria-labelledby="example-tab-yearly" tabindex="0" hidden>
<content-line tag="p" padding="1rem 0 0">Bound for an age, and straining at the chain.</content-line>
</div>
</content-tabs>[role='tablist'] {
display: flex;
gap: 1.25rem;
border-bottom: 1px solid #cbd5e1;
}
[role='tab'] {
padding: 0.5rem 0;
font-weight: 600;
}
[role='tab'][aria-selected='true'] {
color: #1d4ed8;
border-bottom: 2px solid #1d4ed8;
}// $ npm install @content-blocks/js
import '@content-blocks/js/components/content-tabs';
import '@content-blocks/js/components/content-line';<script type="module"
src="https://cdn.jsdelivr.net/npm/@content-blocks/js/dist/content-blocks/content-blocks.esm.js"></script>Anatomy
Content goes into the component's slots, chosen with the slot attribute on each child.
flowchart LR root["#lt;content-tabs#gt;"]:::component root --> s0["<b>no slot (default)</b><br/>Default slot, same as content slot."] root --> s1["<b>slot=#quot;content#quot;</b><br/>This slot will usually serve specific markup to ensure tabs are acces…"] classDef component fill:#141413,color:#faf9f5,stroke:#141413
| Slot | What goes in it |
|---|---|
(default) | Default slot, same as content slot. |
slot="content" | This slot will usually serve specific markup to ensure tabs are accessible. |
Properties
Set them as attributes. Those marked responsive take a value per breakpoint, separated by pipes and named or in order: 1|tablet=2 or 1|2. Seeresponsive values.
| Attribute | Type | Default | Description |
|---|---|---|---|
classesresponsive | String | – | Classes to add to the component. Use pipes for different classes per breakpoint, by name or in order: classes="stacked|laptop=side-by-side". |
paddingresponsive | String | – | Padding around the component, written as CSS padding. Use pipes for different padding per breakpoint, by name or in order: padding="1rem|tablet=2rem 4rem" or padding="1rem|2rem 4rem|3rem 5rem 4rem". |
