Slab
Slab

Disclosure

Accordion

A group of Disclosures where opening one can close the others. Great for FAQs.

Element
<slab-accordion>
Built on
group of <details>

Example

Here's a styled version, <slab-styled-accordion>. It's not in the package — it's an example of what you can build with the headless element. Copy it and make it yours at the bottom of this page. Switch to "As it ships" to see the same markup with the headless element and no CSS at all. That's your starting point.

Styled example As it ships
Concrete is strong when it's squeezed and weak when it's stretched. The steel takes the stretching. Concrete cures by reacting with water, not by drying. A slab that dries too soon is weaker and cracks. Most crews wait three to seven days, until it's strong enough to carry the walls.
HTML
<slab-styled-accordion exclusive>
  <slab-styled-disclosure label="Why rebar?" open>
    Concrete is strong when it's squeezed and weak when it's stretched. The
    steel takes the stretching.
  </slab-styled-disclosure>
  <slab-styled-disclosure label="Why keep it wet?">
    Concrete cures by reacting with water, not by drying. A slab that dries
    too soon is weaker and cracks.
  </slab-styled-disclosure>
  <slab-styled-disclosure label="When can framing start?">
    Most crews wait three to seven days, until it's strong enough to carry
    the walls.
  </slab-styled-disclosure>
</slab-styled-accordion>
Concrete is strong when it's squeezed and weak when it's stretched. The steel takes the stretching. Concrete cures by reacting with water, not by drying. A slab that dries too soon is weaker and cracks. Most crews wait three to seven days, until it's strong enough to carry the walls.
HTML
<slab-accordion exclusive>
  <slab-disclosure label="Why rebar?" open>
    Concrete is strong when it's squeezed and weak when it's stretched. The
    steel takes the stretching.
  </slab-disclosure>
  <slab-disclosure label="Why keep it wet?">
    Concrete cures by reacting with water, not by drying. A slab that dries
    too soon is weaker and cracks.
  </slab-disclosure>
  <slab-disclosure label="When can framing start?">
    Most crews wait three to seven days, until it's strong enough to carry
    the walls.
  </slab-disclosure>
</slab-accordion>

Usage

Install
pnpm add slab-elements lit
ReactLitVueSvelteEmberHTML
import 'slab-elements/accordion.js';

export function MyAccordion() {
  return (
    <slab-accordion exclusive>
      <slab-disclosure label="Shipping">…</slab-disclosure>
      <slab-disclosure label="Returns">…</slab-disclosure>
    </slab-accordion>
  );
}

MyAccordion.jsx React 19 or later, which sets props on custom elements as properties.

import 'slab-elements/accordion.js';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';

@customElement('my-accordion')
export class MyAccordion extends LitElement {
  render() {
    return html`
      <slab-accordion exclusive>
        <slab-disclosure label="Shipping">…</slab-disclosure>
        <slab-disclosure label="Returns">…</slab-disclosure>
      </slab-accordion>
    `;
  }
}

my-accordion.ts Slab is built on Lit, so its elements are at home in Lit's templates.

<script setup>
import 'slab-elements/accordion.js';
</script>

<template>
  <slab-accordion exclusive>
    <slab-disclosure label="Shipping">…</slab-disclosure>
    <slab-disclosure label="Returns">…</slab-disclosure>
  </slab-accordion>
</template>

MyAccordion.vue Let Vue's compiler know slab- tags are custom elements with isCustomElement.

<script>
  import 'slab-elements/accordion.js';
</script>

<slab-accordion exclusive>
  <slab-disclosure label="Shipping">…</slab-disclosure>
  <slab-disclosure label="Returns">…</slab-disclosure>
</slab-accordion>

MyAccordion.svelte Svelte binds properties and events to custom elements like any other element.

import 'slab-elements/accordion.js';

export const MyAccordion = <template>
  <slab-accordion exclusive>
    <slab-disclosure label="Shipping">…</slab-disclosure>
    <slab-disclosure label="Returns">…</slab-disclosure>
  </slab-accordion>
</template>;

MyAccordion.gjs Ember sets attributes, and a dynamic value like {{this.max}} sets the property when the element has one. {{on}} listens for any event by its name.

<script type="module">
  import 'slab-elements/accordion.js';
</script>

<slab-accordion exclusive>
  <slab-disclosure label="Shipping">…</slab-disclosure>
  <slab-disclosure label="Returns">…</slab-disclosure>
</slab-accordion>

index.html Any bundler (or an import map) takes care of the imports.

Each item is a Disclosure, documented over there. The APG’s accordion puts each header in a heading, so give each Disclosure a heading-level that fits the page, such as 3 under an <h2>.

Keyboard

Key What it does
Tab Moves to the next summary, through any open content before it.
Enter, Space Opens or closes the focused Disclosure.

Behavior

A group of Disclosures with no visual styles, where opening one can close the others.

A name would do that for <details> in the same tree, but each Disclosure's is in a shadow root of its own. So Accordion does it instead, from the "toggle" each Disclosure dispatches. Disclosures are found by class rather than by tag name, so your subclass of Disclosure can be named anything.

Disclosures are independent unless exclusive is set. When it is and more than one is open, the first one open is kept, the way a <details> inserted open beside one of the same name is closed. So a Disclosure added later, open, is closed if one is already open.

There are no arrow keys. The APG makes them optional for an accordion, and each summary is already in the Tab order, with its content between it and the next. Arrows would be a second, less familiar way to do the same thing.

API

<slab-accordion>

Attributes
Name Type Default Description
exclusive boolean false Whether opening a Disclosure closes the others.
Slots
Name Type Description
(default) Disclosure

Copy and own it

<slab-styled-accordion> isn't in the package. It's an example — copy it into your project and change whatever you want. Keyboard, focus, ARIA, forms, and events all come from the headless element, and the styles only reach in through ::part() and :state(), same as yours would.

ReactLitVueSvelteEmber

The same styles, written from outside the element, so there's nothing to subclass. The CSS styles every <slab-accordion> on the page. Import tokens.css, the colors and fonts every styled example shares, once, wherever your global styles go.

Each component registers its headless element and imports its CSS. Use it like the element: its props are the element's attributes and properties.

Accordion.jsx
import 'slab-elements/accordion.js';
import './accordion.css';

export function Accordion(props) {
  return <slab-accordion {...props} />;
}
accordion.css
slab-accordion {
  border-block-start: 4px solid var(--ink);
}
tokens.css
:root {
  /* Secondary text. 6.8:1 and 6.9:1 on paper. */
  --ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
  --border: 2px solid var(--ink);

  /* Behind disabled and read-only controls, and hovered rows. */
  --chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));

  /*
    The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
    enough for borders, fills and large text, but not always for small text,
    which takes "--ember-deep".
  */
  --ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));

  /*
    Orange for small text on paper, and for paper text on it. 5.7:1 and
    7.4:1.
  */
  --ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
  --font-body: var(
    --slab-styled-font-body,
    'IBM Plex Sans',
    system-ui,
    sans-serif
  );
  --font-display: var(
    --slab-styled-font-display,
    'Zilla Slab',
    rockwell,
    'Roboto Slab',
    serif
  );
  --font-mono: var(
    --slab-styled-font-mono,
    'IBM Plex Mono',
    ui-monospace,
    monospace
  );
  --ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
  --paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));

  /* The hard, offset shadow a raised surface casts. */
  --shadow: 4px 4px 0 var(--ink);
}

/*
  Forced colors, such as Windows' contrast themes, replace every color that
  isn't a system color, so ember fills and paper marks all become the same
  background, and a checked Checkbox looks like an unchecked one. The palette
  becomes the user's system colors instead, which are kept. Ember is the
  highlight, the color of what's selected, and ember-deep, being for text and
  for paper text on it, is the text color.
*/
@media (forced-colors: active) {
  :host {
    --ash: GrayText;
    --chalk: Canvas;
    --ember: Highlight;
    --ember-deep: CanvasText;
    --ink: CanvasText;
    --paper: Canvas;
  }
}

Under the hood, it's just the headless element, subclassed, with styles set. That's it. To use it, copy these files, swap the tag in @customElement() for one of your own, and import it. tokens.styles.ts holds the colors and fonts every styled example shares, so you only need it once.

accordion.ts
import { customElement } from 'lit/decorators.js';
import Accordion from 'slab-elements/accordion.js';
import styles from './accordion.styles.js';
import tokens from './tokens.styles.js';

declare global {
  interface HTMLElementTagNameMap {
    'slab-styled-accordion': StyledAccordion;
  }
}

/**
 * Accordion, styled: a heavy ink rule over its Disclosures, which rule
 * themselves off from each other.
 */
@customElement('slab-styled-accordion')
export default class StyledAccordion extends Accordion {
  static override styles = [tokens, styles];
}
accordion.styles.ts
import { css } from 'lit';

export default css`
  :host {
    border-block-start: 4px solid var(--ink);
  }
`;
tokens.styles.ts
import { css } from 'lit';

/*
  The styled components' palette and type, taken from the logo: ink for the
  courses, ember for the base, paper behind them.

  Each is a short alias for a "--slab-styled-*" property, with the default as
  its fallback. Retheming is "--slab-styled-ember" and the rest on ":root",
  which every shadow root inherits. Were the defaults declared under those
  names here instead, each host's own declaration would shadow the page's.

  Each default is "light-dark()", so the components follow the page's
  "color-scheme": "dark" for dark, "light" for light, and "light dark" to
  follow the operating system. Ink and paper trade places in the dark, so
  ink is always the text and paper always what's behind it. Contrast is given
  as light, then dark.
*/
export default css`
  :host {
    /* Secondary text. 6.8:1 and 6.9:1 on paper. */
    --ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
    --border: 2px solid var(--ink);

    /* Behind disabled and read-only controls, and hovered rows. */
    --chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));

    /*
      The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
      enough for borders, fills and large text, but not always for small text,
      which takes "--ember-deep".
    */
    --ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));

    /*
      Orange for small text on paper, and for paper text on it. 5.7:1 and
      7.4:1.
    */
    --ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
    --font-body: var(
      --slab-styled-font-body,
      'IBM Plex Sans',
      system-ui,
      sans-serif
    );
    --font-display: var(
      --slab-styled-font-display,
      'Zilla Slab',
      rockwell,
      'Roboto Slab',
      serif
    );
    --font-mono: var(
      --slab-styled-font-mono,
      'IBM Plex Mono',
      ui-monospace,
      monospace
    );
    --ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
    --paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));

    /* The hard, offset shadow a raised surface casts. */
    --shadow: 4px 4px 0 var(--ink);
  }

  /*
    Forced colors, such as Windows' contrast themes, replace every color that
    isn't a system color, so ember fills and paper marks all become the same
    background, and a checked Checkbox looks like an unchecked one. The palette
    becomes the user's system colors instead, which are kept. Ember is the
    highlight, the color of what's selected, and ember-deep, being for text and
    for paper text on it, is the text color.
  */
  @media (forced-colors: active) {
    :host {
      --ash: GrayText;
      --chalk: Canvas;
      --ember: Highlight;
      --ember-deep: CanvasText;
      --ink: CanvasText;
      --paper: Canvas;
    }
  }
`;

The same styles, written from outside the element, so there's nothing to subclass. The CSS styles every <slab-accordion> on the page. Import tokens.css, the colors and fonts every styled example shares, once, wherever your global styles go.

Each component registers its headless element and imports its CSS. Use it like the element: its props are the element's attributes and properties.

Accordion.vue
<script setup>
import 'slab-elements/accordion.js';
import './accordion.css';
</script>

<template>
  <slab-accordion><slot /></slab-accordion>
</template>
accordion.css
slab-accordion {
  border-block-start: 4px solid var(--ink);
}
tokens.css
:root {
  /* Secondary text. 6.8:1 and 6.9:1 on paper. */
  --ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
  --border: 2px solid var(--ink);

  /* Behind disabled and read-only controls, and hovered rows. */
  --chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));

  /*
    The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
    enough for borders, fills and large text, but not always for small text,
    which takes "--ember-deep".
  */
  --ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));

  /*
    Orange for small text on paper, and for paper text on it. 5.7:1 and
    7.4:1.
  */
  --ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
  --font-body: var(
    --slab-styled-font-body,
    'IBM Plex Sans',
    system-ui,
    sans-serif
  );
  --font-display: var(
    --slab-styled-font-display,
    'Zilla Slab',
    rockwell,
    'Roboto Slab',
    serif
  );
  --font-mono: var(
    --slab-styled-font-mono,
    'IBM Plex Mono',
    ui-monospace,
    monospace
  );
  --ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
  --paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));

  /* The hard, offset shadow a raised surface casts. */
  --shadow: 4px 4px 0 var(--ink);
}

/*
  Forced colors, such as Windows' contrast themes, replace every color that
  isn't a system color, so ember fills and paper marks all become the same
  background, and a checked Checkbox looks like an unchecked one. The palette
  becomes the user's system colors instead, which are kept. Ember is the
  highlight, the color of what's selected, and ember-deep, being for text and
  for paper text on it, is the text color.
*/
@media (forced-colors: active) {
  :host {
    --ash: GrayText;
    --chalk: Canvas;
    --ember: Highlight;
    --ember-deep: CanvasText;
    --ink: CanvasText;
    --paper: Canvas;
  }
}

The same styles, written from outside the element, so there's nothing to subclass. The CSS styles every <slab-accordion> on the page. Import tokens.css, the colors and fonts every styled example shares, once, wherever your global styles go.

Import accordion.js once, such as in your root layout, and use <slab-accordion> as is. A Svelte component around it would take slot="…" content as its own slot and drop it.

accordion.js
import 'slab-elements/accordion.js';
import './accordion.css';
accordion.css
slab-accordion {
  border-block-start: 4px solid var(--ink);
}
tokens.css
:root {
  /* Secondary text. 6.8:1 and 6.9:1 on paper. */
  --ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
  --border: 2px solid var(--ink);

  /* Behind disabled and read-only controls, and hovered rows. */
  --chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));

  /*
    The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
    enough for borders, fills and large text, but not always for small text,
    which takes "--ember-deep".
  */
  --ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));

  /*
    Orange for small text on paper, and for paper text on it. 5.7:1 and
    7.4:1.
  */
  --ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
  --font-body: var(
    --slab-styled-font-body,
    'IBM Plex Sans',
    system-ui,
    sans-serif
  );
  --font-display: var(
    --slab-styled-font-display,
    'Zilla Slab',
    rockwell,
    'Roboto Slab',
    serif
  );
  --font-mono: var(
    --slab-styled-font-mono,
    'IBM Plex Mono',
    ui-monospace,
    monospace
  );
  --ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
  --paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));

  /* The hard, offset shadow a raised surface casts. */
  --shadow: 4px 4px 0 var(--ink);
}

/*
  Forced colors, such as Windows' contrast themes, replace every color that
  isn't a system color, so ember fills and paper marks all become the same
  background, and a checked Checkbox looks like an unchecked one. The palette
  becomes the user's system colors instead, which are kept. Ember is the
  highlight, the color of what's selected, and ember-deep, being for text and
  for paper text on it, is the text color.
*/
@media (forced-colors: active) {
  :host {
    --ash: GrayText;
    --chalk: Canvas;
    --ember: Highlight;
    --ember-deep: CanvasText;
    --ink: CanvasText;
    --paper: Canvas;
  }
}

The same styles, written from outside the element, so there's nothing to subclass. The CSS styles every <slab-accordion> on the page. Import tokens.css, the colors and fonts every styled example shares, once, wherever your global styles go.

Each component registers its headless element and imports its CSS. Use it like the element: its attributes and its content go to the element.

Accordion.gjs
import 'slab-elements/accordion.js';
import './accordion.css';

export const Accordion = <template>
  <slab-accordion ...attributes>{{yield}}</slab-accordion>
</template>;
accordion.css
slab-accordion {
  border-block-start: 4px solid var(--ink);
}
tokens.css
:root {
  /* Secondary text. 6.8:1 and 6.9:1 on paper. */
  --ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
  --border: 2px solid var(--ink);

  /* Behind disabled and read-only controls, and hovered rows. */
  --chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));

  /*
    The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
    enough for borders, fills and large text, but not always for small text,
    which takes "--ember-deep".
  */
  --ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));

  /*
    Orange for small text on paper, and for paper text on it. 5.7:1 and
    7.4:1.
  */
  --ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
  --font-body: var(
    --slab-styled-font-body,
    'IBM Plex Sans',
    system-ui,
    sans-serif
  );
  --font-display: var(
    --slab-styled-font-display,
    'Zilla Slab',
    rockwell,
    'Roboto Slab',
    serif
  );
  --font-mono: var(
    --slab-styled-font-mono,
    'IBM Plex Mono',
    ui-monospace,
    monospace
  );
  --ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
  --paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));

  /* The hard, offset shadow a raised surface casts. */
  --shadow: 4px 4px 0 var(--ink);
}

/*
  Forced colors, such as Windows' contrast themes, replace every color that
  isn't a system color, so ember fills and paper marks all become the same
  background, and a checked Checkbox looks like an unchecked one. The palette
  becomes the user's system colors instead, which are kept. Ember is the
  highlight, the color of what's selected, and ember-deep, being for text and
  for paper text on it, is the text color.
*/
@media (forced-colors: active) {
  :host {
    --ash: GrayText;
    --chalk: Canvas;
    --ember: Highlight;
    --ember-deep: CanvasText;
    --ink: CanvasText;
    --paper: Canvas;
  }
}