loading

Copy text

WriteText

WriteText places a string on the system clipboard and completes once the copy has landed. Writing generally succeeds without a prompt when triggered from a user gesture such as a button click.

C#
await clipboard.WriteText("Hello from C#!");
Live sample
Text to copy
copy text output
Results will appear here when you interact with the samples.

Paste text

ReadText

ReadText resolves with the clipboard's current text content. Because reading exposes potentially sensitive data, the browser shows a permission prompt the first time and may require the page to be focused.

C#
string text = await clipboard.ReadText();
Live sample
paste text output
Results will appear here when you interact with the samples.

Write typed items

Write

Write puts one or more ClipboardItem entries - a MIME type plus raw bytes - on the clipboard in a single operation. Pasting into a rich editor picks the HTML flavor, while plain-text targets receive the text/plain flavor. This demo writes both flavors of the same message.

C#
var plain = new ClipboardItem
{
    MimeType = "text/plain",
    Data = Encoding.UTF8.GetBytes("Bit.Butil"),
};

var html = new ClipboardItem
{
    MimeType = "text/html",
    Data = Encoding.UTF8.GetBytes("<b>Bit.Butil</b>"),
};

await clipboard.Write([plain, html]);
Live sample
Item content
write items output
Results will appear here when you interact with the samples.

Read typed items

Read

Read returns every representation currently on the clipboard as ClipboardItem entries. Pass a ClipboardFormats instance to request specific unsanitized formats (for example raw text/html) where the browser supports it. Copy something - text, rich text or an image - then read it back.

C#
ClipboardItem[] items = await clipboard.Read();

foreach (var item in items)
{
    // item.MimeType, item.Data (byte[])
}

// request unsanitized HTML where supported:
var unsanitized = await clipboard.Read(new ClipboardFormats
{
    Unsanitized = ["text/html"],
});
Live sample
read items output
Results will appear here when you interact with the samples.
Warning:
Secure context and permissions required The asynchronous Clipboard API is only available in secure contexts (HTTPS or localhost). Reading triggers a browser permission prompt and typically must run inside a user gesture with the document focused; support for typed items via Read and Write also varies between browsers. Always wrap clipboard calls in try/catch and degrade gracefully when access is denied.

API reference

Member
Signature
Description
WriteText
ValueTask WriteText(string text)
Writes text to the system clipboard, completing once the text is fully copied.
ReadText
ValueTask<string> ReadText()
Reads the clipboard's current content as a string.
Write
ValueTask Write(ClipboardItem[] items)
Writes arbitrary typed data items to the system clipboard.
Read
ValueTask<ClipboardItem[]> Read(ClipboardFormats? formats = null)
Reads all data items currently on the clipboard, optionally requesting specific unsanitized formats.
ClipboardItem.MimeType
string MimeType
The MIME type of the item, e.g. text/plain, text/html or image/png.
ClipboardItem.Data
byte[] Data
The raw bytes of the item.
ClipboardFormats.Unsanitized
string[] Unsanitized
MIME types to receive unsanitized from Read, where the browser supports it.
An unhandled error has occurred. Reload 🗙