---
url: "https://web.dev/articles/clipboard/copy-images/pattern"
titulek: "web.dev"
h1: ""
popis: ""
jazyk: "en"
kanonicka: "https://web.dev/articles/clipboard/copy-images/pattern"
drobecky: []
zdroj: "live"
wayback_snapshot: ""
stazeno: "2026-09-13 22:29:28"
znaku: 1949
slov: 239
kodovani: "iso-8859-2"
sha256: "30e8b610a9eeba2a6bb5d21184eb6745ae096eba6fb3fbed589453f2180b4ac3"
---
Stay organized with collections
Save and categorize content based on your preferences.
HTML `
How to copy images
How to copy images
` 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 button = document.querySelector('button'); const img = document.querySelector('img'); button.addEventListener('click', async () => { const responsePromise = fetch(img.src); try { if ('write' in navigator.clipboard) { await navigator.clipboard.write([ new ClipboardItem({ 'image/svg+xml': new Promise(async (resolve) => { const blob = await responsePromise.then(response => response.blob()); resolve(blob); }), }), ]); // Image copied as image. } else { const text = await responsePromise.then(response => response.text()); await navigator.clipboard.writeText(text); // Image copied as source code. } } 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.