# copy-text-to-clipboard

> Copy text to the clipboard in modern browsers (0.2 kB)

Latest version **3.2.2** (published 2025-09-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install copy-text-to-clipboard
pnpm add copy-text-to-clipboard
yarn add copy-text-to-clipboard
bun add copy-text-to-clipboard
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.2.2 |
| Published | 2025-09-23 |
| First published | 2017-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1045 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | copy, text, clipboard, browser, clipboard.js, modern |

## Links

- npm: https://www.npmjs.com/package/copy-text-to-clipboard
- Repository: https://github.com/sindresorhus/copy-text-to-clipboard
- Homepage: https://github.com/sindresorhus/copy-text-to-clipboard#readme
- Issues: https://github.com/sindresorhus/copy-text-to-clipboard/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/copy-text-to-clipboard

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 3.2.2 (latest) — 2025-09-23
- 3.2.1 — 2025-09-08
- 3.2.0 — 2023-07-05
- 3.1.0 — 2023-03-11
- 3.0.1 — 2021-02-18
- 3.0.0 — 2021-01-27
- 2.2.0 — 2020-04-06
- 2.1.1 — 2019-09-23
- 2.1.0 — 2019-04-05
- 2.0.0 — 2019-03-10
- 1.0.4 — 2017-12-02
- 1.0.3 — 2017-08-20
- 1.0.2 — 2017-06-15
- 1.0.1 — 2017-06-15
- 1.0.0 — 2017-05-22

## README

# copy-text-to-clipboard

> Copy text to the clipboard in modern browsers *(0.2 kB)*

[Try it out!](https://jsfiddle.net/sindresorhus/6406v3pf/)

## Comparison

- This module: **0.2 kB**
- [`clipboard.js`](https://github.com/zenorocha/clipboard.js): 3.4 kB

## Install

```sh
npm install copy-text-to-clipboard
```

## Usage

```js
import copy from 'copy-text-to-clipboard';

button.addEventListener('click', () => {
	copy('🦄🌈');
});
```

## API

### copy(text, options?)

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`.

#### options

Type: `object`

##### target

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.

## Related

- [clipboardy](https://github.com/sindresorhus/clipboardy) - Access the system clipboard (copy/paste) in Node.js

---
_Source: https://npm.io/package/copy-text-to-clipboard · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
