The paste event fires when the user starts a paste action in the browser UI. Learn clipboardData.getData, how to cancel and transform pasted text, onpaste, editable contexts, and five try-it labs.
01
Kind
Instance event
02
Type
ClipboardEvent
03
When
User paste action
04
Handler
onpaste
05
Key APIs
getData · preventDefault
06
Status
Baseline widely available
Fundamentals
Introduction
paste answers: “Did the user just paste through the browser UI?” If the cursor is in an editable context (an <input>, <textarea>, or an element with contenteditable), the default action inserts clipboard contents at the caret.
Unlike copy / cut, a paste handler can read clipboard data via event.clipboardData.getData(...). That makes paste the place to sanitize, transform, or block inbound clipboard content.
💡
Beginner tip
To insert different data than the clipboard holds, call event.preventDefault(), then insert your own text with the Selection API (MDN’s uppercase demo pattern).
Concept
Understanding paste
An instance event that answers: “Did the user initiate paste?”
Fires when paste starts through the browser UI (keyboard, menu, etc.).
ClipboardEvent — read with clipboardData.getData(format).
Default — insert clipboard contents into an editable context.
Cancelable — preventDefault() stops the default insert so you can paste custom data.
Bubbles — up through the DOM to Document and Window; also composed.
Baseline Widely available on MDN (since July 2015).
Foundation
📝 Syntax
Use the event name with addEventListener, or set the handler property:
DataTransfer-like object for this clipboard operation
clipboardData.getData("text")
Read plain text from the clipboard (paste handlers)
clipboardData.getData("text/html")
Read HTML when available (browser/support dependent)
preventDefault()
Cancel the default insert so you can insert manually
Triggers
⚡ When paste Fires
The user pastes via keyboard (Ctrl+V / Cmd+V) or the Edit menu.
In editable contexts, the browser prepares to insert clipboard contents at the cursor.
A synthetic paste event can be dispatched, but it will not change the document.
Compare
⚖️ paste vs copy / cut
Event
Direction
Typical clipboard API
paste
Inbound
getData (read)
copy
Outbound
setData (write) + preventDefault
cut
Outbound + remove
setData + often deleteFromDocument
💡
Also compare
Script-initiated clipboard reads/writes use navigator.clipboard (permissions / secure context). The paste event reacts when the user pastes through the UI.
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Listen
el.addEventListener("paste", fn)
Handler property
el.onpaste = fn
Read pasted text
event.clipboardData.getData("text")
Transform paste
preventDefault() + insert transformed text yourself
Legacy IE fallback
Some old code used window.clipboardData
MDN status
Baseline Widely available (Jul 2015)
Snapshot
🔍 At a Glance
Four facts to remember about paste.
Event type
ClipboardEvent
clipboardData
Read
getData
Inbound text
Override
preventDefault
Then insert
Baseline
yes
Widely available
Hands-On
Examples Gallery
Examples follow MDN Element: paste event. Copy text somewhere, then paste into the target with Ctrl+V / Cmd+V.
📚 Getting Started
MDN-style transform paste and the handler property.
Example 1 — Uppercase Paste (MDN)
Cancel the default insert, uppercase clipboard text, then insert it at the selection.
paste 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 paste
Fires on user paste; read clipboardData with getData, or preventDefault to insert transformed text.
FullWidely available
Google ChromeFull support
Yes
Mozilla FirefoxFull support
Yes
Apple SafariFull support
Yes
Microsoft EdgeFull support
Yes
OperaFull support
Yes
Internet ExplorerSupported (legacy clipboardData)
Yes
pasteBaseline
Bottom line: Listen for paste to sanitize or transform inbound clipboard text. Pair with copy and cut for the full clipboard story.
Wrap Up
Conclusion
paste is the inbound clipboard signal. Read with getData, transform with preventDefault + manual insert, and pair it with copy / cut for complete clipboard UX.
Use paste to sanitize or transform inbound clipboard text
Call preventDefault() when you insert custom paste data
Test in real editable fields and contenteditable regions
Prefer addEventListener in production code
Learn copy and cut alongside paste
❌ Don’t
Expect a synthetic paste event to change the document
Confuse paste (read) with copy/cut (write)
Assume every MIME type is available in every browser
Silently block paste without explaining the UX
Overwrite onpaste if you need multiple listeners
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about paste
User pasted—read clipboardData or cancel and insert your own.
5
Core concepts
📱01
On paste
user UI action
Trigger
📄02
ClipboardEvent
getData path
API
🔄03
Override
preventDefault
Pattern
👆04
vs copy/cut
inbound read
Compare
🎯05
Baseline
widely available
Status
❓ Frequently Asked Questions
It fires when the user starts a paste action through the browser UI (for example Ctrl+V / Cmd+V or Edit → Paste). In an editable context, the default action inserts clipboard contents at the cursor.
No. MDN marks Element paste 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 read with getData(format) in a paste handler.
Call event.preventDefault() to cancel the default insert, read clipboardData.getData("text"), transform it, then insert the result yourself (for example via the Selection API).
No. You can construct and dispatch a paste event, but MDN notes that doing so will not affect the document's contents.
paste is the inbound path and can read clipboardData. copy and cut are outbound: handlers typically write with setData and cannot read the clipboard.
Did you know?
MDN’s classic paste demo uppercases clipboard text before inserting it. Copy “hello”, paste into the target box, and you get HELLO—proof that paste handlers can reshape inbound data.