writeText
Writes plain text to the clipboard.
The Clipboard API lets pages read or write clipboard data, but only in secure, permission-aware contexts.
await navigator.clipboard.writeText("Copied text");
const text = await navigator.clipboard.readText();
Browser APIs & BOM
navigator.clipboard is available in secure contexts and is usually tied to user gestures and browser permissions.
Writing text is common for copy buttons. Reading the clipboard is more sensitive and should be requested only when clearly needed.
Clipboard code should always provide feedback and fallback because support and permission behavior vary.
Writes plain text to the clipboard.
Reads plain text with permission constraints.
Clipboard APIs generally require HTTPS.
Browsers often require a click or similar action.
Examples
try {
await navigator.clipboard.writeText(value);
status.textContent = "Copied.";
} catch {
status.textContent = "Select and copy manually.";
}
const text = await navigator.clipboard.readText(); sendToServer(text);
Code patterns
These examples focus on practical browser APIs: URL state, storage, cookies, clipboard, permissions, observers and offline-capable platform tools.
Feature-detect clipboard access.
if (!navigator.clipboard) {
showManualCopyFallback();
}
Use inside a click handler.
await navigator.clipboard.writeText(value);
Permissions can reject.
try {
await navigator.clipboard.writeText(value);
} catch {
showManualCopyFallback();
}
Reading clipboard is sensitive.
// Ask only after a clear user action. const text = await navigator.clipboard.readText();
Rules that matter
Browser APIs are powerful because they touch privacy, navigation, storage, permissions and performance. Use them deliberately.
Support depends on browser and context.
Clipboard APIs require secure contexts.
It is the common safe use case.
Clipboard contents can be private.
Users need to know whether copying worked.
Manual copy should still be possible.
Production thinking
Clipboard interactions are small but trust-sensitive; users should never be surprised by them.
Copy buttons should be real buttons and status feedback should be readable text.
Production clipboard code needs permission handling, fallbacks and no surprise reads.
Clipboard APIs do not affect SEO directly, but trustworthy interactions affect user confidence.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
If you can explain support, permissions, fallback and cleanup, you are ready to use the API responsibly.
Senior audit upgrade
Last reviewed: 11 June 2026. Clipboard access depends on secure contexts, user gestures and permissions. Always design a manual fallback.
Use these references when browser support, syntax details or proposal status matters.