workflowstacks
ai-agent

Copy to Clipboard with clipboard.js

Easily copy text to clipboard with this lightweight tool, ideal for startup founders, backed by 34k+ GitHub stars
34,130 stars3,909 forksJavaScriptHealth Score 8/10Updated 2/12/2026100% free · open source
What it does

Clipboard.js is a lightweight JavaScript tool that allows you to easily copy text to the user's clipboard without using Flash.

Install / run
npm install clipboard
When to use it
  • When you need to provide a simple way for users to copy text, such as a password or a coupon code.
  • When you want to enhance the user experience by reducing the number of steps required to copy text.
  • When you need to support older browsers that do not have native copy to clipboard functionality.
Quick start
  1. 1Include the Clipboard.js script in your HTML file: <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js"></script>
  2. 2Create a DOM element with a data-clipboard-text attribute, such as a button: <button class="btn" data-clipboard-text="Hello World!">Copy to Clipboard</button>
  3. 3Initialize the Clipboard.js instance: const clipboard = new ClipboardJS('.btn');
  4. 4Use the success and error callbacks to handle the copy event: clipboard.on('success', function(e) { console.log(e); });
  5. 5Test the functionality by clicking the button and verifying that the text is copied to the clipboard.
Ready-to-paste prompt
new ClipboardJS('.btn', { text: function() { return 'Hello, ' + document.getElementById('name').value; } });
Heads up: Make sure the DOM element with the data-clipboard-text attribute is not hidden or disabled, as this can prevent the copy event from triggering.
Saves to your device

Topics

clipboard
javascript
How Copy to Clipboard with clipboard.js works
Codeflow
Free to inspect

Copy to Clipboard with clipboard.js is a tiny JavaScript project (~350 lines across 11 code files, plus 6 test files). Setup is light: installs like a normal app. Reading the code is optional. Last commit 6 months ago, MIT license, has a test suite.

Size
Tiny codebase
~350 lines · 11 code files · 3 min skim
Setup
One-command install
Installs like a normal app. Reading the code is optional.
Runs on
Node.js
No API keys detected
JavaScript 99%TypeScript 1%
Where to start reading
  1. 1
    readme.md
    Start here — what it does and how to install it
  2. 2
    composer.json
    Dependencies and the commands it exposes
  3. 3
    src/clipboard.d.ts
    Inside src/ — the main logic begins here
  4. 4
    demo/constructor-node.html
    A worked example — copy this to get going
What's in each folder
src/Core code — the actual logic8 files
demo/Examples you can copy12 files
.github/CI / automation (GitHub Actions)7 files
test/Tests — proof it works6 files
.husky/Tool / agent settings2 files
READMEHas testsDocumentedCI checksExamples includedMIT licenseLast update 6 mo ago
Quick Actions
Details
Creator
zenorocha
Language
JavaScript
Category
ai-agent
Published
9/18/2015

Are you the creator of this tool? Claim your listing → and earn 85% of every sale.