Slab
Slab

Selection

Select

A button that opens a list of Options to pick one or more from. It submits just like a <select>.

Element
<slab-select>
Built on
[role=combobox] + [role=listbox]

Example

Here's a styled version, <slab-styled-select>. 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
Broom Hard trowel Stamped Exposed aggregate Polished
HTML
<slab-styled-select label="Finish" placeholder="Pick a finish">
  <slab-styled-option value="broom">Broom</slab-styled-option>
  <slab-styled-option value="trowel">Hard trowel</slab-styled-option>
  <slab-styled-option value="stamped">Stamped</slab-styled-option>
  <slab-styled-option value="aggregate">Exposed aggregate</slab-styled-option>
  <slab-styled-option value="polished" disabled>Polished</slab-styled-option>
</slab-styled-select>
Broom Hard trowel Stamped Exposed aggregate Polished
HTML
<slab-select label="Finish" placeholder="Pick a finish">
  <slab-option value="broom">Broom</slab-option>
  <slab-option value="trowel">Hard trowel</slab-option>
  <slab-option value="stamped">Stamped</slab-option>
  <slab-option value="aggregate">Exposed aggregate</slab-option>
  <slab-option value="polished" disabled>Polished</slab-option>
</slab-select>

Usage

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

export function MySelect() {
  return (
    <slab-select label="Country" name="country" placeholder="Choose one">
      <slab-option value="ca">Canada</slab-option>
      <slab-option value="mx">Mexico</slab-option>
      <slab-option value="us">United States</slab-option>
    </slab-select>
  );
}

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

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

@customElement('my-select')
export class MySelect extends LitElement {
  render() {
    return html`
      <slab-select label="Country" name="country" placeholder="Choose one">
        <slab-option value="ca">Canada</slab-option>
        <slab-option value="mx">Mexico</slab-option>
        <slab-option value="us">United States</slab-option>
      </slab-select>
    `;
  }
}

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

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

<template>
  <slab-select label="Country" name="country" placeholder="Choose one">
    <slab-option value="ca">Canada</slab-option>
    <slab-option value="mx">Mexico</slab-option>
    <slab-option value="us">United States</slab-option>
  </slab-select>
</template>

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

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

<slab-select label="Country" name="country" placeholder="Choose one">
  <slab-option value="ca">Canada</slab-option>
  <slab-option value="mx">Mexico</slab-option>
  <slab-option value="us">United States</slab-option>
</slab-select>

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

import 'slab-elements/select.js';

export const MySelect = <template>
  <slab-select label="Country" name="country" placeholder="Choose one">
    <slab-option value="ca">Canada</slab-option>
    <slab-option value="mx">Mexico</slab-option>
    <slab-option value="us">United States</slab-option>
  </slab-select>
</template>;

MySelect.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/select.js';
</script>

<slab-select label="Country" name="country" placeholder="Choose one">
  <slab-option value="ca">Canada</slab-option>
  <slab-option value="mx">Mexico</slab-option>
  <slab-option value="us">United States</slab-option>
</slab-select>

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

Its Options, and Option Groups, are the same ones Listbox uses.

show(), hide() and toggle() open and close it from code, as open does. showPicker() opens it too, but like a native select’s, it only works from a user gesture, such as a click, and throws while it’s disabled.

Keyboard

Key What it does
Enter, Space, Up, Down, Home, End Closed, opens it.
Alt+Down Closed, opens it without moving the active Option.
A character Closed, selects the next Option whose label starts with what’s typed, without opening it.
Enter, Space Open, selects the active Option and closes, or toggles it and stays open when multiple is set.
Tab, Alt+Up Open, selects the active Option and closes. Alt+Up keeps focus where it is.
Escape Open, closes without selecting.

Once it’s open, the rest of the keys are Listbox’s.

Behavior

A select with no visual styles: a button that opens a list of Options, to select one or more from.

It isn't a native <select>. A customizable one, with appearance: base-select, can hold rich options, but Firefox doesn't support it yet. And in any browser a <select> only counts the <option> elements in its own tree, so neither an Option nor anything slotted into it from the light DOM would ever be one of its options. So this is the APG's select-only combobox: an element with role="combobox" that opens a role="listbox" element in a popover. It submits, resets, restores and validates the way a <select> does.

Focus stays on the combobox the whole time. Its aria-activedescendant points at the active Option, so the user hears each Option as they move through them.

Closed, Enter, Space, the arrow keys, Home and End open it, and Alt with the Down arrow opens it without moving. Typing selects the next Option whose label starts with what was typed, without opening it, as a native <select> does. Open, the keys are a Listbox's, range selection with multiple included. Enter, Space and a click select an Option and close it, unless multiple is set, where they toggle the Option and leave it open. Tab selects the active Option and closes it, and Escape closes it without selecting anything. Alt with the Up arrow does what Tab does, without moving focus.

The popover is anchored to the combobox with CSS anchor positioning, the way Popover's is. placement picks the side and nothing else.

Style it through its parts and through :state(disabled), :state(error), :state(open), :state(placeholder-shown), and :state(required), and each Option through the states Option sets.

API

<slab-select>

Attributes
Name Type Default Description
label Required string Names it. It's the accessible name, and the visible label where there is one.
disabled boolean false Disables it, as disabled does a native control: the user can't focus or use it, and a form control's value isn't submitted.
hide-label boolean false Hides the label visually and leaves it as the accessible name, for a design that shows the label some other way.
multiple boolean false Lets more than one be selected at a time.
name string '' The name its value is submitted under, as a native control's name.
open boolean false Whether it's open. Set it to open or close it.
placeholder string Shown in place of a value when no Option is selected.
placement 'bottom' | 'left' | 'right' | 'top' 'bottom' The side of the combobox it opens on, when there's room. It flips when there isn't.
required boolean false Makes it invalid while it has no value, as required does a native control.
value string '' The value of the first selected and enabled Option. Setting it selects the Option with that value, and only that one. Not reflected, to match a native control.
custom-validity string Makes it invalid with this message, as setCustomValidity() does, and shows the message at once rather than once validity is reported, for an error the page already knows about, such as one from a server. Removing it, or setting it to an empty string, makes it valid again, unless something else makes it invalid.
Properties
Name Type Description
defaultValue string The value it selects when none of its Options has selected, and goes back to when its form resets. It's the value attribute, so setting it sets the attribute, and value with it.
form Read-only HTMLFormElement | null The form it belongs to, or null.
labels Read-only NodeList The <label> elements associated with it, as a native control's labels: each <label for> that names its id, and a <label> around it.
options Read-only Option[] Its Options, in order.
selectedOptions Read-only Option[] Selected and enabled Options, in the order they appear.
validationMessage Read-only string What's wrong, as the validity message says it: the message given to setCustomValidity() or setValidity(), or else the browser's own. Empty while it's valid.
validity Read-only ValidityState Its ValidityState, as a native control's.
willValidate Read-only boolean Whether its validity is checked when its form submits. It isn't while it's disabled or read-only.
values string[] The value of every selected and enabled Option, in the order they appear. Setting it selects the Options with those values, and only those.
Methods
Signature Description
checkValidity(): boolean Whether its value is valid. Dispatches "invalid" when it isn't, as a native control's does.
focus(options?: FocusOptions): void Focuses it, or the part of it that takes focus.
hide(): void Closes it.
reportValidity(): boolean Whether its value is valid. When it isn't, dispatches "invalid" and shows the validity message, as a native control's does.
resetValidityFeedback(): void Clears the validity feedback without changing validity.
setCustomValidity(message: string): void Makes it invalid with a message of your own, or valid again with an empty one, as a native control's does.
setValidity(flags?: ValidityStateFlags, message?: string): void Sets its validity and message, as ElementInternals.setValidity() does, for checks of your own beyond setCustomValidity().
show(): void Opens it.
showPicker(): void Opens it, as show() does. As a native select's, it throws without a user gesture, or while it's disabled.
toggle(force?: boolean): boolean Opens it when it's closed, and closes it when it's open, as a native popover's togglePopover() does. true only opens it and false only closes it. Returns whether it's open.
Events
Name Type Description
toggle ToggleEvent When it opens or closes, as a ToggleEvent with oldState and newState that doesn't bubble, as a popover's does.
input Event As the user changes its value, as a native control's does. Setting it from code doesn't dispatch it.
change Event When the user changes its value, as a native control's does. Setting it from code doesn't dispatch it.
invalid Event When a check finds its value invalid, as a native control's does. Cancel it to leave the validity message unshown, after a blur, a submit or reportValidity(), and focus where it is.
beforetoggle ToggleEvent Before it opens or closes, as a ToggleEvent that doesn't bubble. Cancel it while it's opening to keep it closed.
Slots
Name Type Description
(default) Option | OptionGroup
description Element | string Text that describes it, such as a hint or what the validity message means. It's its accessible description.
validity-message Element | string Shown in place of the validity message's text while it's invalid and the message shows, for wording of your own, a translation, or a link. It's part of its accessible description, and validationMessage stays the browser's or setCustomValidity()'s.
CSS parts
Name Description
combobox What opens the Options and shows what's selected
description Text about the Select, and its validity message when it has one
label The label
listbox The Options
popover What the Options open in
validity-message The validity message, which says why the value is invalid
value The selected Options' labels, or the placeholder when there are none
CSS states
Name Description
:state(disabled) While it's disabled.
:state(error) While it's invalid and its validity message shows, which is once its validity is reported, as when its form is submitted.
:state(open) While it's open.
:state(placeholder-shown) While nothing is selected and its placeholder shows, as :placeholder-shown matches a native input's.
:state(required) While it's required, for styles such as an asterisk.

Copy and own it

<slab-styled-select> 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-select> 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.

Select.jsx
import 'slab-elements/select.js';
import './select.css';

export function Select(props) {
  return <slab-select {...props} />;
}
select.css
slab-select {
  color: var(--ink);
  display: grid;
  font-family: var(--font-body);
}

slab-select::part(label) {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  margin-block-end: 0.375rem;
}

slab-select:state(required)::part(label)::after {
  color: var(--ember-deep);
  content: ' *' / '';
}

slab-select::part(combobox) {
  align-items: center;
  background-color: var(--paper);
  border: var(--border);
  box-sizing: border-box;
  cursor: pointer;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  /*
    A fixed height, shared with Text Field, so fields and the controls
    beside them line up whatever the font.
  */
  min-block-size: 3rem;
  padding: 0 0.75rem;
  transition:
    border-color 100ms,
    box-shadow 100ms;
}

/* The chevron: a corner of border, turned. */
slab-select::part(combobox)::after {
  block-size: 0.5rem;
  border-block-end: 2px solid currentcolor;
  border-inline-end: 2px solid currentcolor;
  content: '';
  flex-shrink: 0;
  inline-size: 0.5rem;
  rotate: 45deg;
  transition: rotate 150ms;
  translate: 0 -0.125rem;
}

/*
  Shadows only, without Text Field's lift. The combobox anchors the
  popover, and the popover would move with it.
*/
slab-select::part(combobox):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
  outline: 2px solid transparent;
}

slab-select:state(open)::part(combobox) {
  box-shadow: var(--shadow);
}

slab-select:state(open)::part(combobox)::after {
  rotate: 225deg;
  translate: 0 0.125rem;
}

slab-select:state(open)::part(combobox):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
}

slab-select:state(placeholder-shown)::part(value) {
  color: var(--ash);
}

slab-select:state(error)::part(combobox) {
  border-color: var(--ember-deep);
}

slab-select:state(disabled)::part(combobox) {
  background-color: var(--chalk);
  border-style: dashed;
  color: var(--ash);
  cursor: not-allowed;
}

/* A closed popover isn't displayed, so this runs each time it opens. */
slab-select::part(popover) {
  animation: slab-select-drop 150ms ease-out;
  background-color: var(--paper);
  border: var(--border);
  box-shadow: var(--shadow);
  box-sizing: border-box;
  color: var(--ink);
  margin-block: 0.5rem;
  max-block-size: 18rem;
  min-inline-size: anchor-size(inline);
  overflow-y: auto;
  padding: 0.25rem 0;
}

/*
  Spaced by what's in it rather than by a gap, so a description with
  nothing in it takes no room, and a control beside the field lines up
  with its bottom edge.
*/
slab-select::part(description) {
  color: var(--ash);
  display: grid;
  font-size: 0.875rem;
}

slab-select > [slot='description'] {
  margin-block-start: 0.375rem;
}

slab-select::part(validity-message) {
  color: var(--ember-deep);
  font-weight: 600;
  margin-block-start: 0.375rem;
}

slab-select::part(validity-message)::before {
  content: '■ ' / '';
}

@keyframes slab-select-drop {
  from {
    opacity: 0;
    translate: 0 -0.375rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  slab-select::part(combobox),
  slab-select::part(combobox)::after {
    transition: none;
  }

  slab-select::part(popover) {
    animation: none;
  }
}
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.

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

declare global {
  interface HTMLElementTagNameMap {
    'slab-styled-select': StyledSelect;
  }
}

/**
 * Select, styled: Text Field's box with a chevron that turns over when it
 * opens, and its Options in a panel that casts a hard shadow.
 */
@customElement('slab-styled-select')
export default class StyledSelect extends Select {
  static override styles = [tokens, styles];
}
select.styles.ts
import { css } from 'lit';

export default css`
  :host {
    color: var(--ink);
    display: grid;
    font-family: var(--font-body);
  }

  [part~='label'] {
    font-family: var(--font-display);
    font-size: 1.0625rem;
    font-weight: 600;
    margin-block-end: 0.375rem;
  }

  :host(:state(required)) [part~='label']::after {
    color: var(--ember-deep);
    content: ' *' / '';
  }

  [part~='combobox'] {
    align-items: center;
    background-color: var(--paper);
    border: var(--border);
    box-sizing: border-box;
    cursor: pointer;
    display: flex;
    gap: 0.75rem;
    justify-content: space-between;

    /*
      A fixed height, shared with Text Field, so fields and the controls
      beside them line up whatever the font.
    */
    min-block-size: 3rem;
    padding: 0 0.75rem;
    transition:
      border-color 100ms,
      box-shadow 100ms;

    /* The chevron: a corner of border, turned. */
    &::after {
      block-size: 0.5rem;
      border-block-end: 2px solid currentcolor;
      border-inline-end: 2px solid currentcolor;
      content: '';
      flex-shrink: 0;
      inline-size: 0.5rem;
      rotate: 45deg;
      transition: rotate 150ms;
      translate: 0 -0.125rem;
    }

    /*
      Shadows only, without Text Field's lift. The combobox anchors the
      popover, and the popover would move with it.
    */
    &:focus-visible {
      box-shadow: 4px 4px 0 var(--ember);
      outline: 2px solid transparent;
    }
  }

  :host(:state(open)) [part~='combobox'] {
    box-shadow: var(--shadow);

    &::after {
      rotate: 225deg;
      translate: 0 0.125rem;
    }

    &:focus-visible {
      box-shadow: 4px 4px 0 var(--ember);
    }
  }

  :host(:state(placeholder-shown)) [part~='value'] {
    color: var(--ash);
  }

  :host(:state(error)) [part~='combobox'] {
    border-color: var(--ember-deep);
  }

  :host(:state(disabled)) [part~='combobox'] {
    background-color: var(--chalk);
    border-style: dashed;
    color: var(--ash);
    cursor: not-allowed;
  }

  /* A closed popover isn't displayed, so this runs each time it opens. */
  [part~='popover'] {
    animation: drop 150ms ease-out;
    background-color: var(--paper);
    border: var(--border);
    box-shadow: var(--shadow);
    box-sizing: border-box;
    color: var(--ink);
    margin-block: 0.5rem;
    max-block-size: 18rem;
    min-inline-size: anchor-size(inline);
    overflow-y: auto;
    padding: 0.25rem 0;
  }

  /*
    Spaced by what's in it rather than by a gap, so a description with
    nothing in it takes no room, and a control beside the field lines up
    with its bottom edge.
  */
  [part~='description'] {
    color: var(--ash);
    display: grid;
    font-size: 0.875rem;
  }

  ::slotted([slot='description']) {
    margin-block-start: 0.375rem;
  }

  [part~='validity-message'] {
    color: var(--ember-deep);
    font-weight: 600;
    margin-block-start: 0.375rem;

    &::before {
      content: '■ ' / '';
    }
  }

  @keyframes drop {
    from {
      opacity: 0;
      translate: 0 -0.375rem;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    [part~='combobox'],
    [part~='combobox']::after {
      transition: none;
    }

    [part~='popover'] {
      animation: none;
    }
  }
`;
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-select> 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.

Select.vue
<script setup>
import 'slab-elements/select.js';
import './select.css';
</script>

<template>
  <slab-select><slot /></slab-select>
</template>
select.css
slab-select {
  color: var(--ink);
  display: grid;
  font-family: var(--font-body);
}

slab-select::part(label) {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  margin-block-end: 0.375rem;
}

slab-select:state(required)::part(label)::after {
  color: var(--ember-deep);
  content: ' *' / '';
}

slab-select::part(combobox) {
  align-items: center;
  background-color: var(--paper);
  border: var(--border);
  box-sizing: border-box;
  cursor: pointer;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  /*
    A fixed height, shared with Text Field, so fields and the controls
    beside them line up whatever the font.
  */
  min-block-size: 3rem;
  padding: 0 0.75rem;
  transition:
    border-color 100ms,
    box-shadow 100ms;
}

/* The chevron: a corner of border, turned. */
slab-select::part(combobox)::after {
  block-size: 0.5rem;
  border-block-end: 2px solid currentcolor;
  border-inline-end: 2px solid currentcolor;
  content: '';
  flex-shrink: 0;
  inline-size: 0.5rem;
  rotate: 45deg;
  transition: rotate 150ms;
  translate: 0 -0.125rem;
}

/*
  Shadows only, without Text Field's lift. The combobox anchors the
  popover, and the popover would move with it.
*/
slab-select::part(combobox):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
  outline: 2px solid transparent;
}

slab-select:state(open)::part(combobox) {
  box-shadow: var(--shadow);
}

slab-select:state(open)::part(combobox)::after {
  rotate: 225deg;
  translate: 0 0.125rem;
}

slab-select:state(open)::part(combobox):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
}

slab-select:state(placeholder-shown)::part(value) {
  color: var(--ash);
}

slab-select:state(error)::part(combobox) {
  border-color: var(--ember-deep);
}

slab-select:state(disabled)::part(combobox) {
  background-color: var(--chalk);
  border-style: dashed;
  color: var(--ash);
  cursor: not-allowed;
}

/* A closed popover isn't displayed, so this runs each time it opens. */
slab-select::part(popover) {
  animation: slab-select-drop 150ms ease-out;
  background-color: var(--paper);
  border: var(--border);
  box-shadow: var(--shadow);
  box-sizing: border-box;
  color: var(--ink);
  margin-block: 0.5rem;
  max-block-size: 18rem;
  min-inline-size: anchor-size(inline);
  overflow-y: auto;
  padding: 0.25rem 0;
}

/*
  Spaced by what's in it rather than by a gap, so a description with
  nothing in it takes no room, and a control beside the field lines up
  with its bottom edge.
*/
slab-select::part(description) {
  color: var(--ash);
  display: grid;
  font-size: 0.875rem;
}

slab-select > [slot='description'] {
  margin-block-start: 0.375rem;
}

slab-select::part(validity-message) {
  color: var(--ember-deep);
  font-weight: 600;
  margin-block-start: 0.375rem;
}

slab-select::part(validity-message)::before {
  content: '■ ' / '';
}

@keyframes slab-select-drop {
  from {
    opacity: 0;
    translate: 0 -0.375rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  slab-select::part(combobox),
  slab-select::part(combobox)::after {
    transition: none;
  }

  slab-select::part(popover) {
    animation: none;
  }
}
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-select> on the page. Import tokens.css, the colors and fonts every styled example shares, once, wherever your global styles go.

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

select.js
import 'slab-elements/select.js';
import './select.css';
select.css
slab-select {
  color: var(--ink);
  display: grid;
  font-family: var(--font-body);
}

slab-select::part(label) {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  margin-block-end: 0.375rem;
}

slab-select:state(required)::part(label)::after {
  color: var(--ember-deep);
  content: ' *' / '';
}

slab-select::part(combobox) {
  align-items: center;
  background-color: var(--paper);
  border: var(--border);
  box-sizing: border-box;
  cursor: pointer;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  /*
    A fixed height, shared with Text Field, so fields and the controls
    beside them line up whatever the font.
  */
  min-block-size: 3rem;
  padding: 0 0.75rem;
  transition:
    border-color 100ms,
    box-shadow 100ms;
}

/* The chevron: a corner of border, turned. */
slab-select::part(combobox)::after {
  block-size: 0.5rem;
  border-block-end: 2px solid currentcolor;
  border-inline-end: 2px solid currentcolor;
  content: '';
  flex-shrink: 0;
  inline-size: 0.5rem;
  rotate: 45deg;
  transition: rotate 150ms;
  translate: 0 -0.125rem;
}

/*
  Shadows only, without Text Field's lift. The combobox anchors the
  popover, and the popover would move with it.
*/
slab-select::part(combobox):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
  outline: 2px solid transparent;
}

slab-select:state(open)::part(combobox) {
  box-shadow: var(--shadow);
}

slab-select:state(open)::part(combobox)::after {
  rotate: 225deg;
  translate: 0 0.125rem;
}

slab-select:state(open)::part(combobox):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
}

slab-select:state(placeholder-shown)::part(value) {
  color: var(--ash);
}

slab-select:state(error)::part(combobox) {
  border-color: var(--ember-deep);
}

slab-select:state(disabled)::part(combobox) {
  background-color: var(--chalk);
  border-style: dashed;
  color: var(--ash);
  cursor: not-allowed;
}

/* A closed popover isn't displayed, so this runs each time it opens. */
slab-select::part(popover) {
  animation: slab-select-drop 150ms ease-out;
  background-color: var(--paper);
  border: var(--border);
  box-shadow: var(--shadow);
  box-sizing: border-box;
  color: var(--ink);
  margin-block: 0.5rem;
  max-block-size: 18rem;
  min-inline-size: anchor-size(inline);
  overflow-y: auto;
  padding: 0.25rem 0;
}

/*
  Spaced by what's in it rather than by a gap, so a description with
  nothing in it takes no room, and a control beside the field lines up
  with its bottom edge.
*/
slab-select::part(description) {
  color: var(--ash);
  display: grid;
  font-size: 0.875rem;
}

slab-select > [slot='description'] {
  margin-block-start: 0.375rem;
}

slab-select::part(validity-message) {
  color: var(--ember-deep);
  font-weight: 600;
  margin-block-start: 0.375rem;
}

slab-select::part(validity-message)::before {
  content: '■ ' / '';
}

@keyframes slab-select-drop {
  from {
    opacity: 0;
    translate: 0 -0.375rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  slab-select::part(combobox),
  slab-select::part(combobox)::after {
    transition: none;
  }

  slab-select::part(popover) {
    animation: none;
  }
}
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-select> 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.

Select.gjs
import 'slab-elements/select.js';
import './select.css';

export const Select = <template>
  <slab-select ...attributes>{{yield}}</slab-select>
</template>;
select.css
slab-select {
  color: var(--ink);
  display: grid;
  font-family: var(--font-body);
}

slab-select::part(label) {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  margin-block-end: 0.375rem;
}

slab-select:state(required)::part(label)::after {
  color: var(--ember-deep);
  content: ' *' / '';
}

slab-select::part(combobox) {
  align-items: center;
  background-color: var(--paper);
  border: var(--border);
  box-sizing: border-box;
  cursor: pointer;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  /*
    A fixed height, shared with Text Field, so fields and the controls
    beside them line up whatever the font.
  */
  min-block-size: 3rem;
  padding: 0 0.75rem;
  transition:
    border-color 100ms,
    box-shadow 100ms;
}

/* The chevron: a corner of border, turned. */
slab-select::part(combobox)::after {
  block-size: 0.5rem;
  border-block-end: 2px solid currentcolor;
  border-inline-end: 2px solid currentcolor;
  content: '';
  flex-shrink: 0;
  inline-size: 0.5rem;
  rotate: 45deg;
  transition: rotate 150ms;
  translate: 0 -0.125rem;
}

/*
  Shadows only, without Text Field's lift. The combobox anchors the
  popover, and the popover would move with it.
*/
slab-select::part(combobox):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
  outline: 2px solid transparent;
}

slab-select:state(open)::part(combobox) {
  box-shadow: var(--shadow);
}

slab-select:state(open)::part(combobox)::after {
  rotate: 225deg;
  translate: 0 0.125rem;
}

slab-select:state(open)::part(combobox):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
}

slab-select:state(placeholder-shown)::part(value) {
  color: var(--ash);
}

slab-select:state(error)::part(combobox) {
  border-color: var(--ember-deep);
}

slab-select:state(disabled)::part(combobox) {
  background-color: var(--chalk);
  border-style: dashed;
  color: var(--ash);
  cursor: not-allowed;
}

/* A closed popover isn't displayed, so this runs each time it opens. */
slab-select::part(popover) {
  animation: slab-select-drop 150ms ease-out;
  background-color: var(--paper);
  border: var(--border);
  box-shadow: var(--shadow);
  box-sizing: border-box;
  color: var(--ink);
  margin-block: 0.5rem;
  max-block-size: 18rem;
  min-inline-size: anchor-size(inline);
  overflow-y: auto;
  padding: 0.25rem 0;
}

/*
  Spaced by what's in it rather than by a gap, so a description with
  nothing in it takes no room, and a control beside the field lines up
  with its bottom edge.
*/
slab-select::part(description) {
  color: var(--ash);
  display: grid;
  font-size: 0.875rem;
}

slab-select > [slot='description'] {
  margin-block-start: 0.375rem;
}

slab-select::part(validity-message) {
  color: var(--ember-deep);
  font-weight: 600;
  margin-block-start: 0.375rem;
}

slab-select::part(validity-message)::before {
  content: '■ ' / '';
}

@keyframes slab-select-drop {
  from {
    opacity: 0;
    translate: 0 -0.375rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  slab-select::part(combobox),
  slab-select::part(combobox)::after {
    transition: none;
  }

  slab-select::part(popover) {
    animation: none;
  }
}
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;
  }
}