StartFoundationsComponentsContent

Collapsible

A collapsible shows or hides one block of content when its trigger is clicked.

Stable
OverviewUsageAPIAccessibility
Show delivery details

Standard shipping arrives in 3 to 5 business days.

<tk-collapsible>
  <span slot="trigger">Show delivery details</span>
  <p>Standard shipping arrives in 3 to 5 business days.</p>
</tk-collapsible>

Anatomy

Part What it is
tk-collapsible the element
trigger slot the trigger's label, required; it is the accessible name
default slot the content, shown when open
trigger part the trigger <button>, with a chevron after the label; one Tab stop
panel part the content

The trigger is only as wide as its label. The content sits under it, aligned with the element's edge; you lay out the content yourself.

States

Advanced options

Proxy and cache settings.

Audit log

Sign-ins and exports.

<tk-collapsible open><span slot="trigger">Advanced options</span><p>Proxy and cache settings.</p></tk-collapsible>
<tk-collapsible disabled><span slot="trigger">Audit log</span><p>Sign-ins and exports.</p></tk-collapsible>

Hover and press shade the trigger. Keyboard focus shows a ring around it.

  • open: starts open. The collapsible toggles it from then on; read or set the open property from code.
  • disabled: can't be opened or closed, and the trigger leaves the Tab order.

Controlling it yourself

To load content first or guard a toggle, listen for tk-toggle and call preventDefault(), then set open when you're ready. event.detail.open is the state it is moving to. The content is always in the page, so use this to fill heavy content on first open.

<tk-collapsible id="report"><span slot="trigger">Full report</span><div id="report-body"></div></tk-collapsible>
<script>
  const el = document.getElementById('report');
  el.addEventListener('tk-toggle', async (e) => {
    if (!e.detail.open) return;
    e.preventDefault();
    await loadReport();
    el.open = true;
  });
</script>

Show more, show less

The label is yours. To swap it, change it on tk-toggle:

<tk-collapsible id="more"><span slot="trigger">Show more</span><p>The rest of the description.</p></tk-collapsible>
<script>
  const el = document.getElementById('more');
  el.addEventListener('tk-toggle', (e) => {
    el.querySelector('[slot="trigger"]').textContent = e.detail.open ? 'Show less' : 'Show more';
  });
</script>