This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2020.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The writeText() method of the Clipboard interface writes the specified text to the system clipboard, returning a Promise that is resolved once the system clipboard has been updated.
writeText(newClipText)
newClipTextThe string to be written to the clipboard.
A Promise that is resolved once the clipboard's contents have been updated.
NotAllowedError DOMException
Thrown if writing to the clipboard is not allowed.
Writing to the clipboard can only be done in a secure context.
Additional security requirements are covered in the Security consideration section of the API overview topic.
This example sets the clipboard's contents to the string "<empty clipboard>".
button.addEventListener("click", () => writeClipboardText("<empty clipboard>"));
async function writeClipboardText(text) {
try {
await navigator.clipboard.writeText(text);
} catch (error) {
console.error(error.message);
}
}
| Specification |
|---|
| Clipboard API and events> # dom-clipboard-writetext> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
writeText |
66["From version 107, this method must be called within user gesture event handlers, or the user must grant theclipboard-write permission.", "Before version 107, the user must grant the clipboard-write permission."] |
79["From version 107, this method must be called within user gesture event handlers, or the user must grant theclipboard-write permission.", "Before version 107, the user must grant the clipboard-write permission."] |
63["This method must be called within user gesture event handlers.", "Web extensions require theclipboardRead permission in manifest to read data. With this permission, the extension does not require a user interaction and does not display a paste prompt.", "A paste prompt is displayed when the clipboard is read. If the clipboard contains same-origin content, the prompt is suppressed."] |
53["From version 93, this method must be called within user gesture event handlers, or the user must grant theclipboard-write permission.", "Before version 93, the user must grant the clipboard-write permission."] |
13.1This method must be called within user gesture event handlers. |
66["From version 107, this method must be called within user gesture event handlers, or the user must grant theclipboard-write permission.", "Before version 107, the user must grant the clipboard-write permission."] |
63["This method must be called within user gesture event handlers.", "Web extensions require theclipboardRead permission in manifest to read data. With this permission, the extension does not require a user interaction and does not display a paste prompt.", "A paste prompt is displayed when the clipboard is read. If the clipboard contains same-origin content, the prompt is suppressed."] |
47["From version 73, this method must be called within user gesture event handlers, or the user must grant theclipboard-write permission.", "Before version 73, the user must grant the clipboard-write permission."] |
13.4This method must be called within user gesture event handlers. |
9.0["From version 21.0, this method must be called within user gesture event handlers, or the user must grant theclipboard-write permission.", "Before version 21.0, the user must grant the clipboard-write permission."] |
66["From version 107, this method must be called within user gesture event handlers, or the user must grant theclipboard-write permission.", "Before version 107, the user must grant the clipboard-write permission."] |
13.4This method must be called within user gesture event handlers. |
Clipboard.write()Clipboard.read()Clipboard.readText()
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText