# ClipboardItem

> ClipboardItem packages one clipboard payload in one or more MIME representations; its API includes types, getType(), and supports().

The `ClipboardItem` interface packages clipboard data as one or more MIME representations. Pass an item to `navigator.clipboard.write()`, or receive items from `navigator.clipboard.read()`, then inspect `types` and retrieve a representation with `getType()` ([Clipboard API and events](https://www.w3.org/TR/clipboard-apis/#clipboarditem), W3C).

`ClipboardItem` is available in secure contexts. BCD `api.ClipboardItem` records the interface from Chrome 76, Chrome for Android 84, Firefox 127, and Safari 13.1. The [Async Clipboard compatibility data](/compatibility/clipboard/) shows the related read and write surface. MDN marks `ClipboardItem` as Baseline 2024 while noting that individual parts have different support ([ClipboardItem](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem), MDN).

## Syntax

```js
const item = new ClipboardItem(items);
const styledItem = new ClipboardItem(items, options);

item.types;
item.presentationStyle;
await item.getType(type);
ClipboardItem.supports(type);
```

The constructor accepts a record whose keys are MIME types and whose values are strings, `Blob` objects, or promises for either form. The specification exposes `ClipboardItem` on `Window`, not workers. An item returned by `navigator.clipboard.read()` lists formats in `types`; the specification fetches the bytes when `getType()` runs and shares an in-flight read between concurrent calls for the same type.

## Members

| Member | Type | Meaning |
|---|---|---|
| `options.presentationStyle` | `"unspecified"`, `"inline"`, or `"attachment"` | Optional presentation hint; the default is `"unspecified"`. |
| `types` | Frozen array of strings | MIME types represented by the item. |
| `presentationStyle` | String | The presentation hint stored on the item. |
| `getType(type)` | `Promise<Blob>` | Retrieves the blob for a represented MIME type. |
| `supports(type)` | Boolean | Reports whether the browser supports a MIME type for clipboard writing. |

The specification distinguishes a constructed item from an item returned by `read()`. Constructed values already hold the supplied representation promises. A read item acts as a lazy fetcher: its `types` reflect the formats present when `read()` ran, while `getType()` requests the selected payload. If the system clipboard changes before that request, the specification rejects the call with `InvalidStateError`.

`ClipboardItem.supports()` is synchronous. Use it to decide whether to add an optional representation, but still keep a representation that the receiving application can use. MDN documents `types` and `presentationStyle` as read-only properties and `getType()` as the method that returns the requested representation as a blob ([ClipboardItem](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem), MDN).

`presentationStyle` supplies a presentation hint to the paste destination. The specification defines `"unspecified"`, `"inline"`, and `"attachment"`, with `"unspecified"` as the default. The hint does not replace format selection: a reader still chooses a representation from `types`. `supports(type)` serves a different purpose. The specification returns `true` when the type is among its mandatory or optional data types and returns `false` otherwise ([Clipboard API and events](https://www.w3.org/TR/clipboard-apis/#clipboarditem), W3C).

For a text-only task, MDN recommends the convenience methods `readText()` and `writeText()` instead of the general `read()` and `write()` methods. `ClipboardItem` is the form used when `read()` or `write()` carries strings or arbitrary data represented by `Blob` objects. Its constructor accepts one or more MIME type keys and the corresponding data values, so one item can make separate representations available to the receiving application ([ClipboardItem](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem), MDN).

The constructor preserves the record's representation order in `types`. WebKit documents why that order matters on macOS and iOS: it writes types to the system pasteboard in the supplied order, and native applications may treat earlier types as higher-fidelity choices ([Async Clipboard API](https://webkit.org/blog/10855/async-clipboard-api/), WebKit). Put the representation that best preserves the copied content first, followed by formats that more paste targets can consume. A rich-text item can therefore list `text/html` before `text/plain` while still giving a plain-text editor usable data.

Each value may defer work with a promise. The web.dev clipboard article recommends starting asynchronous preparation inside the promise supplied to `ClipboardItem` for Safari, instead of awaiting the preparation before constructing the item ([Unblocking clipboard access](https://web.dev/articles/async-clipboard), web.dev). This keeps the `write()` call in the user-activation handler while the representation finishes. The promise must still resolve to a string or `Blob` accepted by the constructor; a rejected representation promise makes the clipboard write fail under the specification's write algorithm.

The constructor also normalizes MIME type keys before storing them. The specification throws `TypeError` for an empty `items` record, a key that cannot be parsed as a MIME type, or a duplicate representation with the same parsed type and custom-format flag. A standard `text/html` representation and a `web text/html` custom representation do not collide because the latter retains its custom flag. These checks happen when the item is constructed, before it is passed to `navigator.clipboard.write()` ([Clipboard API and events](https://www.w3.org/TR/clipboard-apis/#clipboarditem), W3C).

## Exceptions

The constructor validates the representation record and MIME type strings. The Clipboard specification requires `getType()` to throw `TypeError` when its argument cannot be parsed as a MIME type. When the type is valid but the item has no matching representation, the returned promise rejects with `NotFoundError`. The specification also defines `InvalidStateError` for a read item whose source clipboard has changed ([Clipboard API and events](https://www.w3.org/TR/clipboard-apis/#clipboarditem), W3C).

:::caution
Calling `getType()` with a valid type that the item does not represent does not choose a substitute: the returned promise rejects with `NotFoundError`. Chromium reports this case as `The type was not found` in its [`ClipboardItem` implementation](https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/modules/clipboard/clipboard_item.cc). An argument that cannot be parsed as a MIME type throws `TypeError`. Read `item.types` first, then provide a text or UI fallback when the requested representation is missing ([Clipboard API and events](https://www.w3.org/TR/clipboard-apis/#clipboarditem), W3C).
:::

## Examples

The examples use a click handler because clipboard writes are permission-sensitive. Each branch updates visible status text so the reader can tell whether the rich or fallback path ran.

### Writing HTML with a plain-text representation

Package HTML and plain text in the same item. If the rich clipboard surface is absent, use `writeText()`; if that method is also absent, select a textarea and ask `execCommand("copy")` to copy plain text.

```html
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>ClipboardItem example</title>
<button id="copy" type="button">Copy the OpenPWA card</button>
<output id="status" aria-live="polite"></output>
<script>
async function copyCard(html, text, status) {
  if (navigator.clipboard?.write && "ClipboardItem" in window) {
    const item = new ClipboardItem({
      "text/html": new Blob([html], { type: "text/html" }),
      "text/plain": new Blob([text], { type: "text/plain" }),
    });
    await navigator.clipboard.write([item]);
    status.textContent = "Copied HTML and plain text";
    return;
  }
  if (navigator.clipboard?.writeText) {
    await navigator.clipboard.writeText(text);
    status.textContent = "Copied plain text";
    return;
  }
  const area = Object.assign(document.createElement("textarea"), { value: text });
  document.body.append(area);
  area.select();
  status.textContent = document.execCommand("copy") ? "Copied plain text" : "Copy failed";
  area.remove();
}

document.querySelector("#copy").addEventListener("click", () =>
  copyCard("<strong>OpenPWA</strong>", "OpenPWA", document.querySelector("#status")),
);
</script>
</html>
```

The web.dev clipboard article documents `execCommand()` as the older DOM-bound route and shows multiple MIME representations in one `ClipboardItem` ([Unblocking clipboard access](https://web.dev/articles/async-clipboard), web.dev). The fallback above preserves the plain-text task without claiming rich-format support.

### Reading an image and handling a missing representation

Check the API and the item's advertised types before requesting bytes. This failure path focuses a paste target when direct clipboard reading is unavailable, denied, or contains no PNG.

```html
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Paste a PNG</title>
<button id="paste" type="button">Read PNG from clipboard</button>
<output id="status" aria-live="polite"></output>
<img id="preview" alt="Pasted PNG preview" hidden>
<div id="paste-target" contenteditable="true" role="textbox" tabindex="0"
     aria-label="Manual paste target">Paste the image here when prompted.</div>
<script>
async function pastePng(preview, fallback, status) {
  if (!navigator.clipboard?.read) {
    fallback.focus();
    status.textContent = "Paste the image into the focused field";
    return;
  }
  try {
    const items = await navigator.clipboard.read();
    const item = items.find((entry) => entry.types.includes("image/png"));
    if (!item) {
      fallback.focus();
      status.textContent = "Clipboard has no PNG; paste a supported value";
      return;
    }
    const blob = await item.getType("image/png");
    preview.src = URL.createObjectURL(blob);
    preview.hidden = false;
    status.textContent = "PNG loaded";
  } catch (error) {
    if (error.name !== "NotAllowedError") throw error;
    fallback.focus();
    status.textContent = "Clipboard access denied; paste manually";
  }
}

document.querySelector("#paste").addEventListener("click", () =>
  pastePng(document.querySelector("#preview"), document.querySelector("#paste-target"), document.querySelector("#status")),
);
</script>
</html>
```

The W3C algorithm defines lazy retrieval for items returned by `read()`. The code requests only the advertised `image/png` representation and leaves a concrete manual-paste route for the other branches.

## See also

- [Async Clipboard API](/reference/capabilities/clipboard/)
- [Web Share API](/reference/capabilities/web-share/)
- [Clipboard API and events: ClipboardItem interface](https://www.w3.org/TR/clipboard-apis/#clipboarditem) (w3.org)
- [ClipboardItem](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem) (MDN)
- [Unblocking clipboard access](https://web.dev/articles/async-clipboard) (web.dev)