--- url: "https://web.dev/articles/clipboard/paste-images" titulek: "How to paste images | Clipboard | web.dev" h1: "How to paste images Stay organized with collections Save and categorize content based on your preferences." popis: "" jazyk: "en" kanonicka: "https://web.dev/articles/clipboard/paste-images" drobecky: ["Clipboard", "How to paste images"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:05:25" znaku: 5538 slov: 683 kodovani: "iso-8859-2" sha256: "5e044a999ff4aca4130c5a41c8ecce500d4aeb71271b59301bbc1cf2da26ed14" --- How to paste images Stay organized with collections Save and categorize content based on your preferences. Harry Theodoulou The modern way Using the Async Clipboard API To read images from the user's clipboard programmatically, that is, after a button click, you can use the [`read()`](https://developer.mozilla.org/docs/Web/API/Clipboard/read) method of the [Async Clipboard API](https://developer.mozilla.org/docs/Web/API/Clipboard_API). If permission to read from the clipboard have not been granted yet, the call to `navigator.clipboard.read()` will request it upon the first call of the method. `const pasteButton = document.querySelector('#paste-button'); pasteButton.addEventListener('click', async () => { try { const clipboardItems = await navigator.clipboard.read(); for (const clipboardItem of clipboardItems) { const imageTypes = clipboardItem.types.find(type => type.startsWith('image/')) for (const imageType of imageTypes) { const blob = await clipboardItem.getType(imageType); // Do something with the image blob. } } } catch (err) { console.error(err.name, err.message); } });` Browser Support 76 79 127 13.1 [Source](https://developer.mozilla.org/docs/Web/API/Clipboard/read) The classic way Listen for the `paste` event The classic way to paste images is to use the (synchronous) [Clipboard API](https://developer.mozilla.org/docs/Web/API/Clipboard_API), which gives you access to the [`clipboardData`](https://developer.mozilla.org/docs/Web/API/ClipboardEvent/clipboardData) field inside the [Document: `paste` event](https://developer.mozilla.org/docs/Web/API/Document/paste_event). However, this method comes with limitations, for example because it's synchronous, pasting large amounts of data can block the page. `document.addEventListener('paste', async (e) => { e.preventDefault(); for (const clipboardItem of e.clipboardData.files) { if (clipboardItem.type.startsWith('image/')) { // Do something with the image file. } } });` Browser Support 66 79 63 13.1 [Source](https://developer.mozilla.org/docs/Web/API/Clipboard) Progressive enhancement For browsers that do not support the Async Clipboard API, it is impossible to access the user's clipboard programmatically (for example, on a button click). Thus for accessing a user's clipboard on a `paste` event, you can use the Async Clipboard API and fall back to the (synchronous) Clipboard API. The `ClipboardItem` objects coming from `navigator.clipboard.read` have a `types` field which is an array, and `File` objects coming from `event.clipboardData.files` have a `type` field which is a string. You can conditionally check each of the `type` or `types` fields for images in the clipboard: `document.addEventListener('paste', async (e) => { e.preventDefault(); const clipboardItems = typeof navigator?.clipboard?.read === 'function' ? await navigator.clipboard.read() : e.clipboardData.files; for (const clipboardItem of clipboardItems) { let blob; if (clipboardItem.type?.startsWith('image/')) { // For files from `e.clipboardData.files`. blob = clipboardItem // Do something with the blob. } else { // For files from `navigator.clipboard.read()`. const imageTypes = clipboardItem.types?.filter(type => type.startsWith('image/')) for (const imageType of imageTypes) { blob = await clipboardItem.getType(imageType); // Do something with the blob. } } } });` Further reading Clipboard API on MDN Unblocking clipboard access on web.dev Demo HTML `
Hit â + v (for macOS) or ctrl + v (for other operating systems) to paste images anywhere in this page.
` 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 `document.addEventListener('paste', async (e) => { e.preventDefault(); const clipboardItems = typeof navigator?.clipboard?.read === 'function' ? await navigator.clipboard.read() : e.clipboardData.files; for (const clipboardItem of clipboardItems) { let blob; if (clipboardItem.type?.startsWith('image/')) { // For files from `e.clipboardData.files`. blob = clipboardItem // Do something with the blob. appendImage(blob); } else { // For files from `navigator.clipboard.read()`. const imageTypes = clipboardItem.types?.filter(type => type.startsWith('image/')) for (const imageType of imageTypes) { blob = await clipboardItem.getType(imageType); // Do something with the blob. appendImage(blob); } } } }); const appendImage = (blob) => { const img = document.createElement('img'); img.src = URL.createObjectURL(blob); document.body.append(img); };` 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.