JavaScript Navigator clipboard Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Read-only property

What You’ll Learn

navigator.clipboard returns a Clipboard object — the modern entry point to copy and paste from JavaScript. Learn secure-context rules, writeText(), readText(), permissions, five examples, and try-it labs.

01

Kind

Read-only property

02

Returns

Clipboard

03

Baseline

Widely available

04

Context

Secure (HTTPS)

05

Copy

writeText()

06

Paste

readText()

Introduction

Almost every app needs “Copy” and “Paste.” The Clipboard API gives your page a clean, promise-based way to talk to the system clipboard — without the old document.execCommand("copy") hacks.

Your entry point is navigator.clipboard. That property is read-only and returns a Clipboard object with async methods such as writeText() and readText().

💡
Secure context required

MDN: the Clipboard API works in secure contexts (HTTPS / localhost). Prefer calling write/read from a user gesture (button click) for reliable permission behavior.

Understanding the clipboard Property

Think of navigator.clipboard as a handle to the system clipboard for this page. You do not assign to it — you call methods on the object it returns.

  • writeText(text) — copy a string to the clipboard.
  • readText() — read text from the clipboard (may need permission).
  • write() / read() — richer data (for example images) via ClipboardItem.
  • All methods return Promises and reject if access is denied.

📝 Syntax

General form of the property:

JavaScript
navigator.clipboard

Value

  • A Clipboard object used to access the system clipboard.

Common patterns

JavaScript
// Copy (from a click handler):
await navigator.clipboard.writeText("Hello CodeToFun");

// Paste text:
const text = await navigator.clipboard.readText();
console.log(text);

// Feature-detect:
if (navigator.clipboard && window.isSecureContext) {
  // safe to use Clipboard API
}

⚡ Quick Reference

GoalCode
Get Clipboardnavigator.clipboard
Copy textawait navigator.clipboard.writeText(str)
Read textawait navigator.clipboard.readText()
Secure page?window.isSecureContext
Detect API!!navigator.clipboard
Handle denytry / catch around awaits

🔍 At a Glance

Four facts to remember about navigator.clipboard.

Returns
Clipboard

API entry

Baseline
widely

Modern browsers

HTTPS
required

Secure context

Style
async

Promises

📋 Clipboard API vs execCommand

navigator.clipboarddocument.execCommand
StyleAsync PromisesOld sync boolean
StatusModern recommendedLegacy / discouraged
Text copywriteText()Select + "copy"
PermissionsClearer modelHacky / inconsistent
Best forNew appsLegacy only

Examples Gallery

Examples follow MDN Navigator.clipboard / Clipboard API patterns. Prefer Try It Yourself for interactive copy/paste. Use View Output for expected messaging.

📚 Getting Started

Detect the API and confirm a secure context.

Example 1 — Feature Detection

Check whether navigator.clipboard exists.

JavaScript
const supported = !!navigator.clipboard;
console.log(supported ? "clipboard available" : "clipboard missing");
Try It Yourself

How It Works

On insecure HTTP pages some browsers omit or restrict clipboard access even if the engine supports the API.

Example 2 — Secure Context Check

Pair detection with isSecureContext.

JavaScript
const lines = [
  "isSecureContext: " + window.isSecureContext,
  "clipboard: " + (navigator.clipboard ? "present" : "absent")
];
console.log(lines.join("\n"));
Try It Yourself

How It Works

Serve clipboard features over HTTPS (or localhost during development).

📈 Practical Patterns

Copy text, read text, and a reusable helper.

Example 3 — writeText() Copy

Copy a string from a button click.

JavaScript
async function copyCode() {
  if (!navigator.clipboard) {
    return "clipboard unavailable";
  }
  await navigator.clipboard.writeText("const x = 42;");
  return "copied to clipboard";
}

// Call from a button click in Try It
Try It Yourself

How It Works

writeText resolves when the text is on the clipboard. Catch errors if the browser blocks the write.

Example 4 — readText() Paste

MDN-style: read clipboard text into the page (may prompt for permission).

JavaScript
async function pasteInto(el) {
  if (!navigator.clipboard) {
    el.textContent = "clipboard unavailable";
    return;
  }
  try {
    const clipText = await navigator.clipboard.readText();
    el.textContent = clipText || "(empty clipboard text)";
  } catch (err) {
    el.textContent = "read denied: " + err.name;
  }
}

// Wire to a Paste button in Try It
Try It Yourself

How It Works

MDN: if the clipboard is empty or has no text, readText() resolves to an empty string.

Example 5 — Safe Copy Helper

Centralize detection, secure context, and error handling.

JavaScript
async function copyText(text) {
  if (!window.isSecureContext) {
    return { ok: false, reason: "insecure-context" };
  }
  if (!navigator.clipboard) {
    return { ok: false, reason: "unsupported" };
  }
  try {
    await navigator.clipboard.writeText(text);
    return { ok: true, reason: "copied" };
  } catch (err) {
    return { ok: false, reason: err.name };
  }
}

copyText("Hello").then((r) => console.log(JSON.stringify(r)));
Try It Yourself

How It Works

Return structured results so UI can show “Copied!” vs “Allow clipboard access” clearly.

🚀 Common Use Cases

  • Copy code / invite links — one-click writeText buttons.
  • Share snippets — copy formatted IDs, coupons, or URLs.
  • Paste into editorsreadText into a canvas or form (with permission).
  • Extensions / tools — MDN’s clip-text display pattern.
  • Prefer over execCommand — cleaner async API for modern browsers.

🧠 How navigator.clipboard Works

1

Secure page loads

HTTPS / localhost exposes the Clipboard API.

Context
2

Read navigator.clipboard

Get the Clipboard object for this document.

Entry
3

Call async methods

writeText / readText (often from a click).

Action
4

Promise resolves or rejects

Success updates the clipboard; denial rejects with an error.

📝 Notes

  • Baseline Widely available — safe default for modern sites.
  • Requires a secure context (HTTPS / localhost).
  • Not Deprecated or Experimental on MDN.
  • Reading the clipboard is more permission-sensitive than writing text.
  • Related: connection, Window, JavaScript hub.

Universal Browser Support

navigator.clipboard is Baseline Widely available across modern browsers (since about March 2020 per MDN). Always use a secure context. Some richer Clipboard methods still vary by browser.

Baseline · Widely available

Navigator.clipboard

Prefer writeText/readText for text copy-paste. Handle permission errors and serve over HTTPS.

Universal Widely available
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
clipboard Excellent

Bottom line: Use navigator.clipboard for modern copy/paste. Keep a fallback message when the context is insecure or access is denied.

Conclusion

navigator.clipboard is the modern Clipboard API entry point. Detect it, require HTTPS, call writeText / readText from user actions, and handle permission errors gracefully.

Continue with connection, Window methods, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Serve clipboard features over HTTPS
  • Call write/read from button clicks
  • Use try/catch around clipboard awaits
  • Show clear “Copied!” feedback
  • Prefer Clipboard API over execCommand

❌ Don’t

  • Assume clipboard works on plain HTTP
  • Silently ignore permission denials
  • Auto-read the clipboard on every page load
  • Paste untrusted clipboard text into innerHTML
  • Forget a fallback when the API is blocked

Key Takeaways

Knowledge Unlocked

Five things to remember about clipboard

Modern Clipboard API entry — async copy and paste.

5
Core concepts
📋 02

Copy

writeText

Write
📄 03

Paste

readText

Read
🔒 04

HTTPS

secure context

Security
05

Async

Promises

Style

❓ Frequently Asked Questions

It is a read-only Navigator property that returns a Clipboard object — the entry point to the Clipboard API for reading and writing the system clipboard (copy, cut, and paste features).
Yes. The Clipboard API is available only in secure contexts (HTTPS or localhost) in supporting browsers.
Call await navigator.clipboard.writeText("hello"). Prefer running it from a user gesture such as a button click so browsers are more likely to allow the write.
Call await navigator.clipboard.readText(). Reading often requires permission and may prompt the user. Handle promise rejections when access is denied.
No. The property is read-only. You use methods on the returned Clipboard object such as writeText() and readText().
No. MDN marks navigator.clipboard as Baseline Widely available. Some advanced methods (for example reading images via read()) can still vary by browser.
Did you know?

Never drop clipboard text straight into innerHTML. Treat pasted content as untrusted input — use textContent or sanitize before rendering HTML.

Learn connection Next

Network Information API for adaptive media quality.

connection →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful