Literal Value
Set data-copy on a .nds-copy to copy the exact string. Use this for phone numbers, emails, tokens, codes, or any value already known at render time.
- Phone
- 9200343222
- help@company.sa
- API Token
- sk-prod-9f3a8c2e
<dl class="nds-definition-list" style="max-width: 360px;">
<div class="nds-definition-item">
<dt>
<i class="hgi hgi-stroke hgi-smart-phone-01"></i>
<span class="nds-label">Phone</span>
</dt>
<dd>
<span class="nds-label">9200343222</span>
<button type="button" class="nds-btn nds-subtle nds-sm nds-icon-only nds-copy"
data-copy="9200343222" aria-label="Copy phone number">
<i class="nds-icon nds-hgi-copy-01"></i>
</button>
</dd>
</div>
<div class="nds-definition-item">
<dt>
<i class="hgi hgi-stroke hgi-mail-01"></i>
<span class="nds-label">Email</span>
</dt>
<dd>
<span class="nds-label">help@company.sa</span>
<button type="button" class="nds-btn nds-subtle nds-sm nds-icon-only nds-copy"
data-copy="help@company.sa" aria-label="Copy email">
<i class="nds-icon nds-hgi-copy-01"></i>
</button>
</dd>
</div>
<div class="nds-definition-item">
<dt>
<i class="hgi hgi-stroke hgi-key-01"></i>
<span class="nds-label">API Token</span>
</dt>
<dd>
<span class="nds-label">sk-prod-9f3a8c2e</span>
<button type="button" class="nds-btn nds-subtle nds-sm nds-icon-only nds-copy"
data-copy="sk-prod-9f3a8c2e" aria-label="Copy API token">
<i class="nds-icon nds-hgi-copy-01"></i>
</button>
</dd>
</div>
</dl>
Copy From Target
Set data-copy-target to a CSS selector. The button copies the target element's text content at click time, which is useful when the value is rendered dynamically or sits inside a styled wrapper.
Application reference
REF-2026-04-19-7A3F
<div class="nds-card nds-stroke" style="max-width: 480px;">
<div class="nds-card-content">
<div class="nds-card-text">
<p class="nds-card-description">Application reference</p>
<h3 class="nds-card-title" id="copy-target-ref">REF-2026-04-19-7A3F</h3>
</div>
<div class="nds-card-actions">
<button type="button" class="nds-btn nds-secondary-outline nds-sm nds-copy"
data-copy-target="#copy-target-ref" aria-label="Copy reference">
<i class="nds-icon nds-hgi-copy-01"></i>
<span class="nds-label">Copy reference</span>
</button>
</div>
</div>
</div>
Code Block
Place a .nds-copy inside an nds-code wrapper and the button copies the nested code automatically. No data-copy needed.
npm install @nds/core --save
<div class="nds-code" style="width: 100%;">
<div class="nds-code-action">
<button class="nds-btn nds-subtle nds-copy" aria-label="Copy code">
<i class="nds-icon nds-hgi-copy-01"></i>
</button>
</div>
<code class="lang-bash code">npm install @nds/core --save</code>
</div>
Label and Message
Add data-label to swap the visible button text during the success window, and data-message to set the screen reader announcement. Both restore automatically after 2 seconds.
<button type="button" class="nds-btn nds-secondary-outline nds-copy"
data-copy="https://nds.sa/components/copy"
data-label="Link copied!"
data-message="Page link copied to clipboard"
aria-label="Copy page link">
<i class="nds-icon nds-hgi-link-04"></i>
<span class="nds-label">Copy link</span>
</button>
Built-in Features
Every .nds-copy on the page is wired up automatically. No setup, no per-button event listeners to manage.
The button copies its data-copy literal, the text of its data-copy-target selector, or the nested <code> when placed inside an .nds-code block.
The icon flips to a checkmark and the optional data-label text swaps in for two seconds, then everything restores.
A shared aria-live region announces data-message on every successful copy so assistive tech users get the same confirmation as sighted users.
When the modern Clipboard API is unavailable (HTTP, older browsers, sandboxed iframes), the utility falls back to a temporary textarea + execCommand so copy still works in development.
Call NDS.Copy.writeText, NDS.Copy.flash, or NDS.Copy.copyFrom from your own JS to integrate copy into custom flows.
Usage Guidelines
Best Practices
- Use literal copy (
data-copy) for values you already know at render time: phone numbers, emails, reference IDs, API tokens, emergency numbers - Use copy from target (
data-copy-target) when the value lives inside another element you have already styled, so you don't have to duplicate the string into an attribute - Place a copy button inside an nds-code wrapper for any code snippet developers may want to run locally. The button copies the raw code automatically
- Always set a meaningful
aria-labelthat names what is being copied ("Copy phone number", "Copy reference ID"). Generic labels like "Copy" leave screen reader users without context - Use
data-labelwhen the button has visible text and the text swap reinforces the action ("Copy link" → "Link copied!"). Skip it for icon-only buttons where the checkmark already conveys success - Use
data-messageto spell out what was copied for assistive tech ("Page link copied to clipboard" reads better than "Copied"). It defaults todata-label, then to "Copied", so omit it only when the button label already makes the action unambiguous - For copy buttons inside a Dropmenu item, add
data-no-auto-closeso the dropmenu stays open during the two second flash, otherwise the user never sees the success feedback - Do not stack a copy button next to every list item if the list is long. The control becomes visual noise. Surface copy on the items that are actually useful to copy (codes, identifiers, contact info)
- For dynamic values that change after page load, prefer
data-copy-targetoverdata-copy. The target's text content is read at click time, so the latest value is copied
Data Attributes
| Attribute | Description |
|---|---|
data-copy | Literal string the button copies. Highest priority in the resolver. |
data-copy-target | CSS selector. The button copies the target element's textContent, trimmed. Used only when data-copy is absent. |
data-label | Text that replaces the button's .nds-label during the success flash. Restored automatically after the flash window. |
data-message | Message announced through the shared aria-live region. Falls back to data-label, then to "Copied". |
JavaScript API
The NDS.Copy API powers every .nds-copy on the page and is also callable directly from your own scripts when you need to compose copy into a larger flow (for example, copying a dynamically computed URL after a network request).