Copy Button
Button that copies text to the clipboard — the element it sits in, another element by id, or a literal string.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | string | undefined | undefined | Literal text to copy. Takes precedence over for and over the parent element. |
for | string | undefined | undefined | id of the element to copy, looked up in the containing document or shadow root. Overrides the parent element. |
disabled | boolean | false | Disables the button: no pointer events, no focus, reduced opacity. |
copied | boolean | false | True for copied-duration after a successful copy. Reflected, so c2-copy-button[copied] is styleable. |
copied-duration | number | 2000 | How long the copied state lasts, in ms. |
label | string | Copy | Accessible name of the button while idle. |
copied-label | string | Copied | Accessible name (and copied-label fallback) after a successful copy. |
reveal | 'hover' | 'always' | hover |
The |
pin | CopyButtonPin | '' | undefined | undefined | Pins the button to a corner of its containing block, staying put while the source scrolls under it. The bare attribute means |
Slots
| Name | Description |
|---|---|
(default) | Optional label beside the icon. Empty by default, which gives an icon-only button. |
copy-icon | Replaces the default copy icon. |
copied-icon | Replaces the default check icon shown after a copy. |
copied-label | Replaces the default slot's text while in the copied state. |
Events
| Name | Type | Description |
|---|---|---|
copy-error | CustomEvent<{ error: unknown }> | Fired when the clipboard write failed (denied permission, or no clipboard at all). |
copied | CustomEvent<{ text: string }> | Fired after the text reached the clipboard. detail.text is what was copied. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
button | The native button that performs the copy action. |
icon | Wrapper that switches between the copy and copied icons. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-copy-button--transition-duration | time | 150ms | Fade of the hover reveal. |
--c2-copy-button__container--background-color | color | — | |
--c2-copy-button__container--color | color | rgb(34, 34, 34) | |
--c2-copy-button__container--border | border | none | |
--c2-copy-button__container--border-radius | border-radius | 6px | |
--c2-copy-button__container--height | pixel | 28px | |
--c2-copy-button__container--min-width | pixel | 28px | |
--c2-copy-button__container--padding-left | padding | 6px | |
--c2-copy-button__container--padding-right | padding | 6px | |
--c2-copy-button__container--gap | pixel | 6px | |
--c2-copy-button__container--font-size | font-size | 12px | |
--c2-copy-button__container--font-weight | font-weight | 500 | |
--c2-copy-button__container--font-family | font-family | — | |
--c2-copy-button__container__hover--background-color | color | rgb(230, 230, 230) | |
--c2-copy-button__container__hover--color | color | — | |
--c2-copy-button__container__hover--border | border | — | |
--c2-copy-button__container__active--background-color | color | rgb(213, 213, 213) | |
--c2-copy-button__container__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-copy-button__container__focus--outline-offset | pixel | 2px | |
--c2-copy-button__container__disabled--opacity | opacity | 0.38 | |
--c2-copy-button__container__copied--color | color | rgb(0, 122, 77) | Applied for copied-duration after a successful copy. |
--c2-copy-button__container__copied--background-color | color | — | |
--c2-copy-button__container__copied--border | border | — | |
--c2-copy-button__icon--size | pixel | 16px | |
--c2-copy-button__icon--color | color | — | Defaults to the button's text colour. |
--c2-copy-button__icon__copied--color | color | — | |
--c2-copy-button__pin--offset-x | pixel | 6px | Inset from the pinned corner, horizontally. |
--c2-copy-button__pin--offset-y | pixel | 6px | Inset from the pinned corner, vertically. |