Copy button
Uses command="--copy" / commandfor (Invoker Commands)
and navigator.clipboard (Async Clipboard).
1. Code block
.card {
container-type: inline-size;
display: grid;
gap: 1rem;
@container (width > 40rem) {
grid-template-columns: 1fr 2fr;
}
}
2. Inline value
Install with:
npm install @acme/design-tokens
3. Read-only field
4. Copy on selection
Select any text below with a pointer and a copy button appears. Ctrl/Cmd+C still works as normal.
Progressive enhancement means starting with HTML that works everywhere, then layering on richer behavior where the platform supports it. Native features like popovers, invoker commands and the async clipboard let us do far more without reaching for a framework.
5. Button shown on hover or focus
The button appears when you hover the block or Tab to it. On touch devices it is always visible.
const dialog = document.querySelector('dialog');
dialog.showModal();