--- url: "https://web.dev/articles/clipboard/paste-text" titulek: "How to paste text | Clipboard | web.dev" h1: "How to paste text Stay organized with collections Save and categorize content based on your preferences." popis: "" jazyk: "en" kanonicka: "https://web.dev/articles/clipboard/paste-text" drobecky: ["Clipboard", "How to paste text"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:56:59" znaku: 4102 slov: 442 kodovani: "iso-8859-2" sha256: "2943a2437b6eaab3f34258b75847e2dd1ae9378eb278ed0cb48f533040786ef2" --- How to paste text Stay organized with collections Save and categorize content based on your preferences. Harry Theodoulou The modern way Using the Async Clipboard API To read text from the user's clipboard programmatically, for example, after a button click, you can use the [`readText()`](https://developer.mozilla.org/docs/Web/API/Clipboard/readText) method of the [Async Clipboard API](https://developer.mozilla.org/docs/Web/API/Clipboard_API). If permissions to read clipboard have not been granted yet, the call to `navigator.clipboard.readText()` will request it upon the first call to the method. `const pasteButton = document.querySelector('#paste-button'); pasteButton.addEventListener('click', async () => { try { const text = await navigator.clipboard.readText() document.querySelector('textarea').value += text; console.log('Text pasted.'); } catch (error) { console.log('Failed to read clipboard'); } });` Browser Support 66 79 125 13.1 [Source](https://developer.mozilla.org/docs/Web/API/Clipboard/readText) The classic way Using `document.execCommand()` By using the [`document.execCommand('paste')`](https://developer.mozilla.org/docs/Web/API/Document/execCommand#paste) you can paste the clipboard content at the insertion point (currently focused HTML element). The `execCommand` method returns a boolean that indicates whether the `paste` event was successful. However this method comes with limitations, for example because it's synchronous, pasting large amounts of data can block the page. `pasteButton.addEventListener('click', () => { document.querySelector('textarea').focus(); const result = document.execCommand('paste') console.log('document.execCommand result: ', result); })` Browser Support 1 12 69 1.3 [Source](https://developer.mozilla.org/docs/Web/API/Document/execCommand) Progressive enhancement `pasteButton.addEventListener('click', async () => { try { const text = await navigator.clipboard.readText() document.querySelector('textarea').value += text; console.log('Text pasted.'); } catch (error) { console.log('Failed to read clipboard. Using execCommand instead.'); document.querySelector('textarea').focus(); const result = document.execCommand('paste') console.log('document.execCommand result: ', result); } });` Further reading [Clipboard API on MDN](https://developer.mozilla.org/docs/Web/API/Clipboard_API) [Unblocking clipboard access](/async-clipboard#readtext()) Demo HTML ` How to paste text

How to paste text

` CSS `:root { color-scheme: dark light; } html { box-sizing: border-box; } *, *:before, *:after { box-sizing: inherit; } body { margin: 1rem; font-family: system-ui, sans-serif; } button { display: block; }` JS `const pasteButton = document.querySelector('button'); pasteButton.addEventListener('click', async () => { try { const text = await navigator.clipboard.readText() document.querySelector('textarea').value += text; console.log('Text pasted.'); } catch (error) { console.log('Failed to read clipboard. Using execCommand instead.'); document.querySelector('textarea').focus(); const result = document.execCommand('paste') console.log('document.execCommand result: ', result); } });` Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2026-09-04 UTC.