PHPackages                             zenorocha/clipboardjs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. zenorocha/clipboardjs

ActiveComponent[Utility &amp; Helpers](/categories/utility)

zenorocha/clipboardjs
=====================

Modern copy to clipboard. No Flash. Just 3kb gzipped https://clipboardjs.com

v2.0.11(4y ago)34.2k218.2k—9.8%3.9k[4 PRs](https://github.com/zenorocha/clipboard.js/pulls)2JavaScriptCI failing

Since Mar 1Pushed 3mo ago411 watchersCompare

[ Source](https://github.com/zenorocha/clipboard.js)[ Packagist](https://packagist.org/packages/zenorocha/clipboardjs)[ Docs](https://clipboardjs.com/)[ RSS](/packages/zenorocha-clipboardjs/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (21)Used By (2)

clipboard.js
============

[](#clipboardjs)

[![Build Status](https://github.com/zenorocha/clipboard.js/workflows/build/badge.svg)](https://github.com/zenorocha/clipboard.js/workflows/build/badge.svg)[![Killing Flash](https://camo.githubusercontent.com/2cc7b2e5e7025f04c040c8ec9f5bbe4714b82bd38d0eeb8aa981ed4c841d0188/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6b696c6c696e672d666c6173682d627269676874677265656e2e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/2cc7b2e5e7025f04c040c8ec9f5bbe4714b82bd38d0eeb8aa981ed4c841d0188/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6b696c6c696e672d666c6173682d627269676874677265656e2e7376673f7374796c653d666c6174)

> Modern copy to clipboard. No Flash. Just 3kb gzipped.

[![Demo](https://cloud.githubusercontent.com/assets/398893/16165747/a0f6fc46-349a-11e6-8c9b-c5fd58d9099c.png)](https://clipboardjs.com/)

Why
---

[](#why)

Copying text to the clipboard shouldn't be hard. It shouldn't require dozens of steps to configure or hundreds of KBs to load. But most of all, it shouldn't depend on Flash or any bloated framework.

That's why clipboard.js exists.

Install
-------

[](#install)

You can get it on npm.

```
npm install clipboard --save

```

Or if you're not into package management, just [download a ZIP](https://github.com/zenorocha/clipboard.js/archive/master.zip) file.

Setup
-----

[](#setup)

First, include the script located on the `dist` folder or load it from [a third-party CDN provider](https://github.com/zenorocha/clipboard.js/wiki/CDN-Providers).

```

```

Now, you need to instantiate it by [passing a DOM selector](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-selector.html#L18), [HTML element](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-node.html#L16-L17), or [list of HTML elements](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-nodelist.html#L18-L19).

```
new ClipboardJS('.btn');
```

Internally, we need to fetch all elements that matches with your selector and attach event listeners for each one. But guess what? If you have hundreds of matches, this operation can consume a lot of memory.

For this reason we use [event delegation](https://stackoverflow.com/questions/1687296/what-is-dom-event-delegation) which replaces multiple event listeners with just a single listener. After all, [\#perfmatters](https://twitter.com/hashtag/perfmatters).

Usage
=====

[](#usage)

We're living a *declarative renaissance*, that's why we decided to take advantage of [HTML5 data attributes](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes) for better usability.

### Copy text from another element

[](#copy-text-from-another-element)

A pretty common use case is to copy content from another element. You can do that by adding a `data-clipboard-target` attribute in your trigger element.

The value you include on this attribute needs to match another's element selector.

[![example-2](https://cloud.githubusercontent.com/assets/398893/9983467/a4946aaa-5fb1-11e5-9780-f09fcd7ca6c8.png)](https://clipboardjs.com/#example-target)

```

```

### Cut text from another element

[](#cut-text-from-another-element)

Additionally, you can define a `data-clipboard-action` attribute to specify if you want to either `copy` or `cut` content.

If you omit this attribute, `copy` will be used by default.

[![example-3](https://cloud.githubusercontent.com/assets/398893/10000358/7df57b9c-6050-11e5-9cd1-fbc51d2fd0a7.png)](https://clipboardjs.com/#example-action)

```

Mussum ipsum cacilds...

  Cut to clipboard

```

As you may expect, the `cut` action only works on `` or `` elements.

### Copy text from attribute

[](#copy-text-from-attribute)

Truth is, you don't even need another element to copy its content from. You can just include a `data-clipboard-text` attribute in your trigger element.

[![example-1](https://cloud.githubusercontent.com/assets/398893/10000347/6e16cf8c-6050-11e5-9883-1c5681f9ec45.png)](https://clipboardjs.com/#example-text)

```

  Copy to clipboard

```

Events
------

[](#events)

There are cases where you'd like to show some user feedback or capture what has been selected after a copy/cut operation.

That's why we fire custom events such as `success` and `error` for you to listen and implement your custom logic.

```
var clipboard = new ClipboardJS('.btn');

clipboard.on('success', function (e) {
  console.info('Action:', e.action);
  console.info('Text:', e.text);
  console.info('Trigger:', e.trigger);

  e.clearSelection();
});

clipboard.on('error', function (e) {
  console.error('Action:', e.action);
  console.error('Trigger:', e.trigger);
});
```

For a live demonstration, go to this [site](https://clipboardjs.com/) and open your console.

Tooltips
--------

[](#tooltips)

Each application has different design needs, that's why clipboard.js does not include any CSS or built-in tooltip solution.

The tooltips you see on the [demo site](https://clipboardjs.com/) were built using [GitHub's Primer](https://primer.style/css/components/tooltips). You may want to check that out if you're looking for a similar look and feel.

Advanced Options
----------------

[](#advanced-options)

If you don't want to modify your HTML, there's a pretty handy imperative API for you to use. All you need to do is declare a function, do your thing, and return a value.

For instance, if you want to dynamically set a `target`, you'll need to return a Node.

```
new ClipboardJS('.btn', {
  target: function (trigger) {
    return trigger.nextElementSibling;
  },
});
```

If you want to dynamically set a `text`, you'll return a String.

```
new ClipboardJS('.btn', {
  text: function (trigger) {
    return trigger.getAttribute('aria-label');
  },
});
```

For use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the `container` value.

```
new ClipboardJS('.btn', {
  container: document.getElementById('modal'),
});
```

Also, if you are working with single page apps, you may want to manage the lifecycle of the DOM more precisely. Here's how you clean up the events and objects that we create.

```
var clipboard = new ClipboardJS('.btn');
clipboard.destroy();
```

Browser Support
---------------

[](#browser-support)

This library relies on both [Selection](https://developer.mozilla.org/en-US/docs/Web/API/Selection) and [execCommand](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) APIs. The first one is [supported by all browsers](https://caniuse.com/#search=selection) while the second one is supported in the following browsers.

[![Chrome logo](https://camo.githubusercontent.com/efd04fa8153b7f9d0cd5a5a5666c7661c1e430acf04106821668c1b875436773/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f6368726f6d652e706e67)](https://camo.githubusercontent.com/efd04fa8153b7f9d0cd5a5a5666c7661c1e430acf04106821668c1b875436773/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f6368726f6d652e706e67)[![Edge logo](https://camo.githubusercontent.com/b7b0e04e9a0a9ed74097d5c00b5db38f0a0a8a7dd36c137df8ce9ae4f3c2683b/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f656467652e706e67)](https://camo.githubusercontent.com/b7b0e04e9a0a9ed74097d5c00b5db38f0a0a8a7dd36c137df8ce9ae4f3c2683b/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f656467652e706e67)[![Firefox logo](https://camo.githubusercontent.com/2625bca8416091aa2bf44f2373b184cfe0f6eab80a841b400606f9c5c3dadc94/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f66697265666f782e706e67)](https://camo.githubusercontent.com/2625bca8416091aa2bf44f2373b184cfe0f6eab80a841b400606f9c5c3dadc94/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f66697265666f782e706e67)[![Internet Explorer logo](https://camo.githubusercontent.com/b1d28ca6a276bd5a968dcdafd92dd9d3a02984125eaed5b53cb9c31346009dbd/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f69652e706e67)](https://camo.githubusercontent.com/b1d28ca6a276bd5a968dcdafd92dd9d3a02984125eaed5b53cb9c31346009dbd/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f69652e706e67)[![Opera logo](https://camo.githubusercontent.com/81f6dfeb6e69a7bdcd77e98214a35988766ffe016f93049dd65f8cd80872d675/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f6f706572612e706e67)](https://camo.githubusercontent.com/81f6dfeb6e69a7bdcd77e98214a35988766ffe016f93049dd65f8cd80872d675/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f6f706572612e706e67)[![Safari logo](https://camo.githubusercontent.com/7f51ad99a81635f52aced9df8025ae6f2af6658548498739b0c0e4264a848670/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f7361666172692e706e67)](https://camo.githubusercontent.com/7f51ad99a81635f52aced9df8025ae6f2af6658548498739b0c0e4264a848670/68747470733a2f2f636c6970626f6172646a732e636f6d2f6173736574732f696d616765732f7361666172692e706e67)42+ ✔12+ ✔41+ ✔9+ ✔29+ ✔10+ ✔The good news is that clipboard.js gracefully degrades if you need to support older browsers. All you have to do is show a tooltip saying `Copied!` when `success` event is called and `Press Ctrl+C to copy` when `error` event is called because the text is already selected.

You can also check if clipboard.js is supported or not by running `ClipboardJS.isSupported()`, that way you can hide copy/cut buttons from the UI.

Bonus
-----

[](#bonus)

A browser extension that adds a "copy to clipboard" button to every code block on *GitHub, MDN, Gist, StackOverflow, StackExchange, npm, and even Medium.*

Install for [Chrome](https://chrome.google.com/webstore/detail/codecopy/fkbfebkcoelajmhanocgppanfoojcdmg) and [Firefox](https://addons.mozilla.org/en-US/firefox/addon/codecopy/).

License
-------

[](#license)

[MIT License](https://zenorocha.mit-license.org/) © Zeno Rocha

###  Health Score

64

—

FairBetter than 99% of packages

Maintenance55

Moderate activity, may be stable

Popularity73

Solid adoption and visibility

Community47

Growing community involvement

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 56.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~138 days

Recently: every ~106 days

Total

12

Last Release

1475d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f697e53dd9415ba890421aeabac0fae34cf9265e71cd9e5f9b115a4eb6b7e14d?d=identicon)[alphp](/maintainers/alphp)

---

Top Contributors

[![zenorocha](https://avatars.githubusercontent.com/u/398893?v=4)](https://github.com/zenorocha "zenorocha (205 commits)")[![vitormalencar](https://avatars.githubusercontent.com/u/7741167?v=4)](https://github.com/vitormalencar "vitormalencar (45 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (24 commits)")[![obetomuniz](https://avatars.githubusercontent.com/u/1680157?v=4)](https://github.com/obetomuniz "obetomuniz (13 commits)")[![r3nanp](https://avatars.githubusercontent.com/u/47953339?v=4)](https://github.com/r3nanp "r3nanp (12 commits)")[![helderberto](https://avatars.githubusercontent.com/u/862575?v=4)](https://github.com/helderberto "helderberto (9 commits)")[![realityking](https://avatars.githubusercontent.com/u/628508?v=4)](https://github.com/realityking "realityking (6 commits)")[![heldr](https://avatars.githubusercontent.com/u/134727?v=4)](https://github.com/heldr "heldr (5 commits)")[![mauriciosoares](https://avatars.githubusercontent.com/u/2321259?v=4)](https://github.com/mauriciosoares "mauriciosoares (5 commits)")[![vccortez](https://avatars.githubusercontent.com/u/6536964?v=4)](https://github.com/vccortez "vccortez (4 commits)")[![eduardolundgren](https://avatars.githubusercontent.com/u/113087?v=4)](https://github.com/eduardolundgren "eduardolundgren (4 commits)")[![coliff](https://avatars.githubusercontent.com/u/1212885?v=4)](https://github.com/coliff "coliff (3 commits)")[![LeuisKen](https://avatars.githubusercontent.com/u/7701575?v=4)](https://github.com/LeuisKen "LeuisKen (3 commits)")[![jaydson](https://avatars.githubusercontent.com/u/72206?v=4)](https://github.com/jaydson "jaydson (3 commits)")[![patrickhlauke](https://avatars.githubusercontent.com/u/895831?v=4)](https://github.com/patrickhlauke "patrickhlauke (2 commits)")[![calvincorreli](https://avatars.githubusercontent.com/u/7728?v=4)](https://github.com/calvincorreli "calvincorreli (2 commits)")[![jory](https://avatars.githubusercontent.com/u/200687?v=4)](https://github.com/jory "jory (2 commits)")[![arve0](https://avatars.githubusercontent.com/u/4810521?v=4)](https://github.com/arve0 "arve0 (2 commits)")[![SpazzMarticus](https://avatars.githubusercontent.com/u/5716457?v=4)](https://github.com/SpazzMarticus "SpazzMarticus (2 commits)")[![sebastianekstrom](https://avatars.githubusercontent.com/u/1921046?v=4)](https://github.com/sebastianekstrom "sebastianekstrom (1 commits)")

---

Tags

clipboardjavascript

### Embed Badge

![Health badge](/badges/zenorocha-clipboardjs/health.svg)

```
[![Health](https://phpackages.com/badges/zenorocha-clipboardjs/health.svg)](https://phpackages.com/packages/zenorocha-clipboardjs)
```

###  Alternatives

[droptica/droopler-project

Project template for Droopler with Composer

5010.0k](/packages/droptica-droopler-project)[thunder/thunder-project

Project template for Thunder projects with composer

1039.4k](/packages/thunder-thunder-project)[wingsuit-designsystem/wingsuit-kickstarter

Starterkit for Wingsuit and Layout Builder.

131.2k](/packages/wingsuit-designsystem-wingsuit-kickstarter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
