https://github.com/uiwjs/copy-to-clipboard
Copy text to the clipboard in modern browsers
https://github.com/uiwjs/copy-to-clipboard
browser clipboard clipboard-copy clipboard-js copy
Last synced: 6 months ago
JSON representation
Copy text to the clipboard in modern browsers
- Host: GitHub
- URL: https://github.com/uiwjs/copy-to-clipboard
- Owner: uiwjs
- License: mit
- Created: 2018-09-06T01:52:53.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2025-12-12T15:11:02.000Z (7 months ago)
- Last Synced: 2025-12-14T06:17:56.915Z (7 months ago)
- Topics: browser, clipboard, clipboard-copy, clipboard-js, copy
- Language: JavaScript
- Homepage: https://uiwjs.github.io/copy-to-clipboard
- Size: 187 KB
- Stars: 18
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Copy Text to Clipboard
===
[](https://jaywcjlove.github.io/#/sponsor)

[](https://www.npmjs.com/package/@uiw/copy-to-clipboard)
[](https://github.com/uiwjs/react-codemirror/actions)
[](https://uiwjs.github.io/npm-unpkg/#/pkg/@uiw/copy-to-clipboard/file/README.md)
[](https://www.npmjs.com/package/@uiw/copy-to-clipboard)
[](https://github.com/uiwjs/copy-to-clipboard/network/dependents)
[](https://uiwjs.github.io/copy-to-clipboard/lcov-report/)
**This styling is an extra step which is likely not required.**
Why is it here? To ensure:
1. the element is able to have focus and selection.
2. if element was to `flash` render it has minimal visual impact.
3. less flakyness with selection and copying which **might** occur if the textarea element is not visible.
The likelihood is the element won't even render, not even a flash, so some of these are just precautions. However in IE the element is visible whilst the popup box asking the user for permission for the web page to copy to the clipboard. Place in top-left corner of screen regardless of scroll position.
## Usage
You will need Node.js installed on your system.
```bash
$ npm i @uiw/copy-to-clipboard
```
```js
import copyTextToClipboard from '@uiw/copy-to-clipboard';
copyTextToClipboard('test', (isCopy) => {
console.log('isCopy:', isCopy);
});
```
Or manually download and link [copy-to-clipboard](https://unpkg.com/@uiw/copy-to-clipboard/dist/) in your HTML, It can also be downloaded via [UNPKG](https://unpkg.com/@uiw/copy-to-clipboard/dist/):
```html
copyTextToClipboard('test', (isCopy) => {
console.log('isCopy:', isCopy);
});
```
## Contributors
As always, thanks to our amazing contributors!
Made with [contributors](https://github.com/jaywcjlove/github-action-contributors).
### License
Licensed under the MIT License.