W3cubDocs

/Web APIs

Clipboard API

The Clipboard API provides the ability to respond to clipboard commands (cut, copy, and paste) as well as to asynchronously read from and write to the system clipboard.

Note: This API is not available in Web Workers (not exposed via WorkerNavigator).

This API is designed to supersede accessing the clipboard using document.execCommand().

Note: The clipboard is a data buffer that is used for short-term, data storage and/or data transfers, this can be between documents or applications. It is usually implemented as an anonymous, temporary data buffer, sometimes called the paste buffer, that can be accessed from most or all programs within the environment via defined programming interfaces.

A typical application accesses clipboard functionality by mapping user input such as keybindings, menu selections, etc. to these interfaces.

Accessing the clipboard

Instead of creating a Clipboard object through instantiation, you access the system clipboard through the Navigator.clipboard global:

js

navigator.clipboard
  .readText()
  .then(
    (clipText) => (document.querySelector(".editor").innerText += clipText),
  );

This snippet fetches the text from the clipboard and appends it to the first element found with the class editor. Since readText() (and read(), for that matter) returns an empty string if the clipboard isn't text, this code is safe.

Interfaces

Clipboard Secure context

Provides an interface for reading and writing text and data to or from the system clipboard. The specification refers to this as the 'Async Clipboard API'.

ClipboardEvent Secure context

Represents events providing information related to modification of the clipboard, that is cut, copy, and paste events. The specification refers to this as the 'Clipboard Event API'.

ClipboardItem Secure context

Represents a single item format, used when reading or writing data.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
ClipboardItem 98
76–98The ClipboardItem constructor only accepts a blob as the item data, but not strings or Promises that resolve to strings or blobs. See bug 1014310.
98
79–98The ClipboardItem constructor only accepts a blob as the item data, but not strings or Promises that resolve to strings or blobs. See bug 1014310.
87 No 84
63–84The ClipboardItem constructor only accepts a blob as the item data, but not strings or Promises that resolve to strings or blobs. See bug 1014310.
13.1 98
84–98The ClipboardItem constructor only accepts a blob as the item data, but not strings or Promises that resolve to strings or blobs. See bug 1014310.
98
84–98The ClipboardItem constructor only accepts a blob as the item data, but not strings or Promises that resolve to strings or blobs. See bug 1014310.
No 68
60–68The ClipboardItem constructor only accepts a blob as the item data, but not strings or Promises that resolve to strings or blobs. See bug 1014310.
13.4 18.0
14.0–18.0The ClipboardItem constructor only accepts a blob as the item data, but not strings or Promises that resolve to strings or blobs. See bug 1014310.
Clipboard_API 76 79 87 No 63 13.1 84 84 No 60 13.4 14.0
getType 76 79 87 No 63 13.1 84 84 No 60 13.4 14.0
presentationStyle No No 87 No No 13.1 No No No No 13.4 No
types 76 79 87 No 63 13.1 84 84 No 60 13.4 14.0
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
ClipboardEvent 58 17 22 No 45 10.1 58 58 22 43 10.3 7.0
Clipboard_API 41 12 22 4 28 10.1 41 41 22 28 10.3 4.0
clipboardData 41 12 22 5 28 10.1 41 41 22 28 10.3 4.0
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
Clipboard_API 66 79 63 No 53 13.1 66 66 63 47 13.4 9.0
read
86From version 86, the text/html MIME type is supported.
76From version 76, the image/png MIME type is supported.
66Images are not supported.
79
90Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
No 63 13.1
84From version 84, the image/png MIME type is supported.
66Images are not supported.
86From version 86, the text/html MIME type is supported.
84From version 84, the image/png MIME type is supported.
66Images are not supported.
No 54 13.4 12.0
readText 66 79
NoFirefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
No 53 13.1 66 66
NoFirefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
47 13.4 9.0
write
66From version 76, the image/png MIME type is supported.
79
87Writing to the clipboard is available without permission in secure contexts and browser extensions, but only from user-initiated event callbacks. Browser extensions with the "clipboardWrite" permission can write to the clipboard at any time.
63["This method accepts a DataTransfer object instead of an array of ClipboardItem objects.", "Writing to the clipboard is available without permission in secure contexts and browser extensions, but only from user-initiated event callbacks. Browser extensions with the \"clipboardWrite\" permission can write to the clipboard at any time."]
No 63 13.1
66From version 84, the image/png MIME type is supported.
66From version 84, the image/png MIME type is supported.
No 54 13.4 12.0
writeText 66 79
63Writing to the clipboard is available without permission in secure contexts and browser extensions, but only from user-initiated event callbacks. Browser extensions with the "clipboardWrite" permission can write to the clipboard at any time.
No 53
13.1Must be called within user gesture event handlers such as pointerdown or pointerup.
66 66
63Writing to the clipboard is available without permission in secure contexts and browser extensions, but only from user-initiated event callbacks. Browser extensions with the "clipboardWrite" permission can write to the clipboard at any time.
47
13.4Must be called within user gesture event handlers such as pointerdown or pointerup.
9.0

api.Clipboard

BCD tables only load in the browser

api.ClipboardEvent

BCD tables only load in the browser

api.ClipboardItem

BCD tables only load in the browser

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API