Copy Button
One-click clipboard copy with customizable labels and feedback duration.
<rhx-copy-button>
Examples
Copy Static Value
dotnet add package htmxRazor
<code>dotnet add package htmxRazor</code>
<rhx-copy-button rhx-value="dotnet add package htmxRazor" />
Copy from Element
npm install htmxRazor-client
<pre id="install-cmd"><code>npm install htmxRazor-client</code></pre>
<rhx-copy-button rhx-from="#install-cmd code" />
Custom Labels
https://example.com
<rhx-copy-button rhx-value="https://example.com"
rhx-copy-label="Copy URL"
rhx-success-label="URL Copied!" />
Long Feedback Duration
sk-1234567890abcdef
<rhx-copy-button rhx-value="sk-1234567890abcdef"
rhx-feedback-duration="5000" />
Disabled
No copying allowed
<rhx-copy-button rhx-value="No copying allowed"
rhx-disabled="true" />
Properties
| Property | Type | Default | Description |
|---|---|---|---|
rhx-value |
string |
- |
Static text to copy to clipboard |
rhx-from |
string |
- |
CSS selector of element whose text content to copy |
rhx-copy-label |
string |
Copy |
Button label before copy |
rhx-success-label |
string |
Copied! |
Button label after successful copy |
rhx-feedback-duration |
int |
2000 |
Milliseconds to show success label |
rhx-disabled |
bool |
false |
Whether the button is disabled |
Accessibility
- Renders a native
<button>element witharia-labeldescribing the copy action. - A live region announces the copy success to screen readers.
- Disabled state sets
aria-disabled="true"and prevents interaction. - Focus is fully keyboard-accessible with visible focus ring.