Slab
Slab

Form

Copy Button

Copy text to the clipboard with a button, and say so once it has.

Element
<slab-copy-button>
Built on
<button>

Example

Here's a styled version, <slab-styled-copy-button>. 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
pnpm add slab-elements
HTML
<div class="stack">
  <pre id="install-command">pnpm add slab-elements</pre>
  <slab-styled-copy-button label="Copy" from="install-command"></slab-styled-copy-button>
</div>
pnpm add slab-elements
HTML
<div class="stack">
  <pre id="install-command-as-it-ships">pnpm add slab-elements</pre>
  <slab-copy-button label="Copy" from="install-command"></slab-copy-button>
</div>

Usage

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

export function MyCopyButton() {
  return (
    <div>
      <code id="api-key">sk-live-8f2c</code>
      <slab-copy-button label="Copy key" from="api-key"></slab-copy-button>
    </div>
  );
}

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

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

@customElement('my-copy-button')
export class MyCopyButton extends LitElement {
  render() {
    return html`
      <div>
        <code id="api-key">sk-live-8f2c</code>
        <slab-copy-button label="Copy key" from="api-key"></slab-copy-button>
      </div>
    `;
  }
}

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

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

<template>
  <div>
    <code id="api-key">sk-live-8f2c</code>
    <slab-copy-button label="Copy key" from="api-key"></slab-copy-button>
  </div>
</template>

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

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

<div>
  <code id="api-key">sk-live-8f2c</code>
  <slab-copy-button label="Copy key" from="api-key"></slab-copy-button>
</div>

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

import 'slab-elements/copy-button.js';

export const MyCopyButton = <template>
  <div>
    <code id="api-key">sk-live-8f2c</code>
    <slab-copy-button label="Copy key" from="api-key"></slab-copy-button>
  </div>
</template>;

MyCopyButton.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/copy-button.js';
</script>

<div>
  <code id="api-key">sk-live-8f2c</code>
  <slab-copy-button label="Copy key" from="api-key"></slab-copy-button>
</div>

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

Use value for text that isn’t on the page, and from for text that is, such as a code block or an input. Either way, it’s read when the button is pressed. The clipboard is only there in a page served over HTTPS or from localhost, so a copy elsewhere fails, and says so, rather than doing nothing.

The button’s name stays its label throughout. “Copied” is announced from a status beside it, so a screenreader user hears it without the button changing under them. Show it to everyone else through :state(copied).

Keyboard

Key What it does
Enter, Space Copies the text, as on a <button>.

Behavior

A copy button with no visual styles, around a native <button>, that writes text to the clipboard when it's pressed.

What it copies is value, or, when from is set, what's in the element with that id at the moment it's pressed: the value of an <input>, <textarea> or anything else with a string value, and the text of anything without one, as it's rendered. So a <pre> keeps its line breaks. The element is looked up in the button's own tree, as a <label>'s for is.

Once the text is copied, copied-label is announced and the host matches :state(copied) for feedback-duration, which is when a design shows it. The clipboard can refuse, in a page that isn't served securely or in a frame without permission. Then failed-label is announced, the host matches :state(failed), and "copy-error" is dispatched instead of "copied".

The label is text rather than a slot, as Disclosure's is: a button's name is flattened to text regardless. An icon goes on through ::part(button).

API

<slab-copy-button>

Attributes
Name Type Default Description
copied-label string Announced once the text is copied. "Copied" in English when unset.
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.
failed-label string Announced when the clipboard refuses. "Couldn't copy" in English when unset.
feedback-duration number 2000 Milliseconds the host matches :state(copied) or :state(failed) for.
from string The id of an element to copy from, instead of value.
label Required string Names it. It's the accessible name, and the visible label where there is one.
value string '' The text to copy.
Methods
Signature Description
click(): void Clicks it, as a native element's click() does.
focus(options?: FocusOptions): void Focuses it, or the part of it that takes focus.
Events
Name Type Description
copied Event When the text is copied.
copy-error Event When the text can't be copied, such as when the browser doesn't allow it.
CSS parts
Name Description
button The button
CSS states
Name Description
:state(copied) For feedback-duration after the text is copied.
:state(disabled) While it's disabled.
:state(failed) For feedback-duration after the clipboard refuses.

Copy and own it

<slab-styled-copy-button> 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-copy-button> 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.

CopyButton.jsx
import 'slab-elements/copy-button.js';
import './copy-button.css';

export function CopyButton(props) {
  return <slab-copy-button {...props} />;
}
copy-button.css
slab-copy-button::part(button) {
  align-items: center;
  background-color: var(--paper);
  border: var(--border);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  gap: 0.5rem;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.875rem;
  text-transform: uppercase;
  transition:
    background-color 100ms,
    color 100ms;
}

/*
  The mark. Its text is decorative, so it's given empty alternative text:
  the status beside the button already says the text was copied.
*/
slab-copy-button::part(button)::after {
  content: '⧉' / '';
  font-family: var(--font-mono);
  font-weight: 400;
}

slab-copy-button::part(button):hover {
  background-color: var(--chalk);
}

slab-copy-button::part(button):focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: 2px;
}

slab-copy-button::part(button):disabled {
  border-color: var(--ash);
  color: var(--ash);
  cursor: not-allowed;
}

/*
  Paper text on "--ember-deep" is 5.7:1 and 7.4:1, where on "--ember" it
  would fall short for small text.
*/
slab-copy-button:state(copied)::part(button) {
  background-color: var(--ember-deep);
  border-color: var(--ember-deep);
  color: var(--paper);
}

slab-copy-button:state(copied)::part(button)::after {
  content: '✓' / '';
}

slab-copy-button:state(failed)::part(button)::after {
  content: '✕' / '';
}

@media (prefers-reduced-motion: reduce) {
  slab-copy-button::part(button) {
    transition: 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.

copy-button.ts
import { customElement } from 'lit/decorators.js';
import CopyButton from 'slab-elements/copy-button.js';
import styles from './copy-button.styles.js';
import tokens from './tokens.styles.js';

declare global {
  interface HTMLElementTagNameMap {
    'slab-styled-copy-button': StyledCopyButton;
  }
}

/**
 * Copy Button, styled: a slab-serif label in an ink border that fills with
 * ember and gains a check once the text is copied.
 */
@customElement('slab-styled-copy-button')
export default class StyledCopyButton extends CopyButton {
  static override styles = [tokens, styles];
}
copy-button.styles.ts
import { css } from 'lit';

export default css`
  [part~='button'] {
    align-items: center;
    background-color: var(--paper);
    border: var(--border);
    color: var(--ink);
    cursor: pointer;
    display: inline-flex;
    font-family: var(--font-display);
    font-size: 0.9375rem;
    font-weight: 600;
    gap: 0.5rem;
    letter-spacing: 0.04em;
    padding: 0.5rem 0.875rem;
    text-transform: uppercase;
    transition:
      background-color 100ms,
      color 100ms;

    /*
      The mark. Its text is decorative, so it's given empty alternative text:
      the status beside the button already says the text was copied.
    */
    &::after {
      content: '⧉' / '';
      font-family: var(--font-mono);
      font-weight: 400;
    }

    &:hover {
      background-color: var(--chalk);
    }

    &:focus-visible {
      outline: 3px solid var(--ember);
      outline-offset: 2px;
    }

    &:disabled {
      border-color: var(--ash);
      color: var(--ash);
      cursor: not-allowed;
    }
  }

  /*
    Paper text on "--ember-deep" is 5.7:1 and 7.4:1, where on "--ember" it
    would fall short for small text.
  */
  :host(:state(copied)) [part~='button'] {
    background-color: var(--ember-deep);
    border-color: var(--ember-deep);
    color: var(--paper);

    &::after {
      content: '✓' / '';
    }
  }

  :host(:state(failed)) [part~='button']::after {
    content: '✕' / '';
  }

  @media (prefers-reduced-motion: reduce) {
    [part~='button'] {
      transition: 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-copy-button> 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.

CopyButton.vue
<script setup>
import 'slab-elements/copy-button.js';
import './copy-button.css';
</script>

<template>
  <slab-copy-button><slot /></slab-copy-button>
</template>
copy-button.css
slab-copy-button::part(button) {
  align-items: center;
  background-color: var(--paper);
  border: var(--border);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  gap: 0.5rem;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.875rem;
  text-transform: uppercase;
  transition:
    background-color 100ms,
    color 100ms;
}

/*
  The mark. Its text is decorative, so it's given empty alternative text:
  the status beside the button already says the text was copied.
*/
slab-copy-button::part(button)::after {
  content: '⧉' / '';
  font-family: var(--font-mono);
  font-weight: 400;
}

slab-copy-button::part(button):hover {
  background-color: var(--chalk);
}

slab-copy-button::part(button):focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: 2px;
}

slab-copy-button::part(button):disabled {
  border-color: var(--ash);
  color: var(--ash);
  cursor: not-allowed;
}

/*
  Paper text on "--ember-deep" is 5.7:1 and 7.4:1, where on "--ember" it
  would fall short for small text.
*/
slab-copy-button:state(copied)::part(button) {
  background-color: var(--ember-deep);
  border-color: var(--ember-deep);
  color: var(--paper);
}

slab-copy-button:state(copied)::part(button)::after {
  content: '✓' / '';
}

slab-copy-button:state(failed)::part(button)::after {
  content: '✕' / '';
}

@media (prefers-reduced-motion: reduce) {
  slab-copy-button::part(button) {
    transition: 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-copy-button> on the page. Import tokens.css, the colors and fonts every styled example shares, once, wherever your global styles go.

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

copy-button.js
import 'slab-elements/copy-button.js';
import './copy-button.css';
copy-button.css
slab-copy-button::part(button) {
  align-items: center;
  background-color: var(--paper);
  border: var(--border);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  gap: 0.5rem;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.875rem;
  text-transform: uppercase;
  transition:
    background-color 100ms,
    color 100ms;
}

/*
  The mark. Its text is decorative, so it's given empty alternative text:
  the status beside the button already says the text was copied.
*/
slab-copy-button::part(button)::after {
  content: '⧉' / '';
  font-family: var(--font-mono);
  font-weight: 400;
}

slab-copy-button::part(button):hover {
  background-color: var(--chalk);
}

slab-copy-button::part(button):focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: 2px;
}

slab-copy-button::part(button):disabled {
  border-color: var(--ash);
  color: var(--ash);
  cursor: not-allowed;
}

/*
  Paper text on "--ember-deep" is 5.7:1 and 7.4:1, where on "--ember" it
  would fall short for small text.
*/
slab-copy-button:state(copied)::part(button) {
  background-color: var(--ember-deep);
  border-color: var(--ember-deep);
  color: var(--paper);
}

slab-copy-button:state(copied)::part(button)::after {
  content: '✓' / '';
}

slab-copy-button:state(failed)::part(button)::after {
  content: '✕' / '';
}

@media (prefers-reduced-motion: reduce) {
  slab-copy-button::part(button) {
    transition: 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-copy-button> 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.

CopyButton.gjs
import 'slab-elements/copy-button.js';
import './copy-button.css';

export const CopyButton = <template>
  <slab-copy-button ...attributes>{{yield}}</slab-copy-button>
</template>;
copy-button.css
slab-copy-button::part(button) {
  align-items: center;
  background-color: var(--paper);
  border: var(--border);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  gap: 0.5rem;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.875rem;
  text-transform: uppercase;
  transition:
    background-color 100ms,
    color 100ms;
}

/*
  The mark. Its text is decorative, so it's given empty alternative text:
  the status beside the button already says the text was copied.
*/
slab-copy-button::part(button)::after {
  content: '⧉' / '';
  font-family: var(--font-mono);
  font-weight: 400;
}

slab-copy-button::part(button):hover {
  background-color: var(--chalk);
}

slab-copy-button::part(button):focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: 2px;
}

slab-copy-button::part(button):disabled {
  border-color: var(--ash);
  color: var(--ash);
  cursor: not-allowed;
}

/*
  Paper text on "--ember-deep" is 5.7:1 and 7.4:1, where on "--ember" it
  would fall short for small text.
*/
slab-copy-button:state(copied)::part(button) {
  background-color: var(--ember-deep);
  border-color: var(--ember-deep);
  color: var(--paper);
}

slab-copy-button:state(copied)::part(button)::after {
  content: '✓' / '';
}

slab-copy-button:state(failed)::part(button)::after {
  content: '✕' / '';
}

@media (prefers-reduced-motion: reduce) {
  slab-copy-button::part(button) {
    transition: 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;
  }
}