The copy event fires when the user starts a copy action in the browser UI. Learn ClipboardEvent.clipboardData, setData, preventDefault to customize clipboard text, addEventListener vs oncopy, and five try-it labs.
01
Kind
Instance event
02
Type
ClipboardEvent
03
When
User copy action
04
Handler
oncopy
05
Key API
clipboardData.setData
06
Status
Baseline widely available
Fundamentals
Introduction
When someone selects text and presses Ctrl+C (or Cmd+C on macOS), or chooses Copy from a menu, the browser fires copy. By default it puts the selection on the system clipboard.
Your handler can change what gets copied: write a custom string with event.clipboardData.setData("text/plain", ...) and call preventDefault() so the default selection copy does not overwrite it.
💡
Beginner tip
A copy handler can write clipboard data but cannot read it. Pair with the paste event when you need to inspect incoming clipboard contents.
Concept
Understanding copy
An instance event that answers: “Did the user just start a copy action from the browser UI?”
Default — copy the current selection (if any) to the clipboard.
ClipboardEvent — use clipboardData.setData(format, data).
Cancelable — preventDefault() after setting your own data.
Bubbles & composed — can reach Document and Window.
Baseline Widely available on MDN (since July 2015).
Foundation
📝 Syntax
Use the event name with addEventListener, or set the handler property:
copy is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. Clipboard MIME types and permissions for scripted clipboard APIs can still vary.
✓ Baseline · Widely available
Element copy
Works across modern desktop and mobile browsers for user-initiated copy actions.
100%Widely available
Google ChromeSupported · Desktop & Android
Full support
Mozilla FirefoxSupported · Desktop & Android
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
OperaSupported · Modern versions
Full support
Internet ExplorerSupported (legacy clipboard model)
Supported
copyBaseline
Bottom line: Listen for copy to customize outgoing clipboard text with setData + preventDefault; use paste when you need to read clipboard data.
Wrap Up
Conclusion
copy is the “user is copying” signal. Read the selection, optionally rewrite it with clipboardData.setData, cancel the default, and remember you cannot read the clipboard from this event.
Call setData then preventDefault() for custom text
Use document.getSelection() to inspect what the user highlighted
Keep attribution short and honest when you append source notes
Learn cut and paste alongside copy
❌ Don’t
Expect to read clipboard contents in a copy handler
Assume a synthetic copy event updates the system clipboard
Block all copying as a security feature—users can still screenshot
Forget secure-context rules for scripted navigator.clipboard APIs
Overwrite oncopy if you need multiple listeners
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about copy
User copy action—write with setData, cancel default, cannot read clipboard here.
5
Core concepts
📋01
User copy
UI shortcut / menu
Trigger
📄02
ClipboardEvent
clipboardData
API
✎️03
setData
+ preventDefault
Pattern
🚫04
No read
in copy handler
Limit
🎯05
Baseline
widely available
Compat
❓ Frequently Asked Questions
It fires when the user starts a copy action through the browser UI (for example Ctrl+C / Cmd+C or Edit → Copy). The default action copies the current selection to the clipboard.
No. MDN marks Element copy as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
A ClipboardEvent. The important property is clipboardData, which you can write to with setData(format, data).
No. MDN states a copy handler cannot read clipboard data. You can write with setData after cancelling the default action, but reading is restricted.
Call event.clipboardData.setData("text/plain", yourText) and event.preventDefault() so the browser does not copy the raw selection instead.
No. You can dispatch a synthetic copy event, but that alone will not put data on the system clipboard.
Did you know?
MDN’s classic demo uppercases the selection before it hits the clipboard. Select “hello”, copy, then paste into another field—you get HELLO.