
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
copy-text-to-clipboard
Advanced tools
Copy text to the clipboard in modern browsers (0.2 kB)
clipboard.js: 3.4 kBnpm install copy-text-to-clipboard
import copy from 'copy-text-to-clipboard';
button.addEventListener('click', () => {
copy('🦄🌈');
});
Copy text to the clipboard.
Returns a boolean of whether it succeeded to copy the text.
Must be called in response to a user gesture event, like click or keyup.
Type: object
Type: HTMLElement
Default: document.body
Specify a DOM element where the temporary, behind-the-scenes textarea should be appended, in cases where you need to stay within a focus trap, like in a modal.
The 'clipboardy' package provides similar functionality but with additional features such as reading from the clipboard and handling images. It is more versatile but also slightly larger in size compared to 'copy-text-to-clipboard'.
The 'clipboard.js' package is another alternative that offers more advanced features like handling copy and cut events. It is more feature-rich and suitable for complex use cases but may require more setup compared to 'copy-text-to-clipboard'.
The 'react-copy-to-clipboard' package is specifically designed for React applications. It provides a higher-level abstraction and integrates seamlessly with React components, making it a good choice for React developers.
FAQs
Copy text to the clipboard in modern browsers (0.2 kB)
The npm package copy-text-to-clipboard receives a total of 560,824 weekly downloads. As such, copy-text-to-clipboard popularity was classified as popular.
We found that copy-text-to-clipboard demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.