--- url: "https://web.dev/articles/clipboard/copy-text/pattern" titulek: "web.dev" h1: "" popis: "" jazyk: "en" kanonicka: "https://web.dev/articles/clipboard/copy-text/pattern" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:03:25" znaku: 1570 slov: 195 kodovani: "iso-8859-2" sha256: "afd05f483ef3831ed57aaa62307dbfa2329a9ce79fc7ff6db4054eb382a52c19" --- Stay organized with collections Save and categorize content based on your preferences. HTML ` How to copy text

How to copy 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 textarea = document.querySelector('textarea'); const button = document.querySelector('button'); button.addEventListener('click', async () => { try { await navigator.clipboard.writeText(textarea.value); } catch (err) { console.error(err.name, err.message); } });` 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-07-29 UTC.