The onpaste attribute is an event handler for the paste event. It runs when the user pastes through the browser UI into an editable context — for example an <input>, <textarea>, or contenteditable element.
The event is a ClipboardEvent. Read text with event.clipboardData.getData("text/plain"). To change what is inserted, call event.preventDefault() and insert your own data. Related: oncopy and oncut.
Baseline · Widely available.
Not deprecated. Prefer element.addEventListener("paste", …) in scripts; the HTML attribute is the same handler.
Clipboard reads belong inside the paste handler.
Browsers generally allow clipboardData.getData() only during a user-initiated paste (or copy/cut). A synthetic paste event will not insert clipboard contents by itself.
Syntax
HTML Syntax
syntax.html
<input onpaste="handler">
Modern equivalent: el.addEventListener("paste", function (event) { … });. The event bubbles, so a parent can listen too.
Values
Attribute Values
The value is a script (event handler code). Common uses:
Use
Meaning
Try it
Log / notify
React when paste happens (default insert still runs)
Default paste still inserts unless you call preventDefault().
Example 2 — Paste as Uppercase
Cancel the default insert, then put a transformed value.
HTML
<label for="code">Code</label>
<input id="code" type="text"
onpaste="
event.preventDefault();
var text = event.clipboardData.getData('text/plain').toUpperCase();
var el = event.target;
var start = el.selectionStart;
var end = el.selectionEnd;
el.value = el.value.slice(0, start) + text + el.value.slice(end);
el.setSelectionRange(start + text.length, start + text.length);
">
Status shows how many characters were on the clipboard.
Default paste still fills the textarea.
Edge Cases & Pitfalls
Most issues are clipboard permissions, canceling without re-inserting, or blocking paste for everyone.
timing
Read clipboard only in the handler
getData() is available during the paste event. Do not expect free clipboard access afterward.
cancel
If you preventDefault(), insert yourself
Otherwise nothing appears in the field. Transform, then write the value or selection.
a11y
Avoid blocking paste without a good reason
Password managers and assistive tech rely on paste. Prefer validate-after-paste over hard blocks.
fake
Synthetic paste does not insert
Dispatching a paste event will not put clipboard data into the document.
types
MIME types vary
Prefer text/plain. Rich paste may also offer text/html depending on the source.
Compatibility
Browser Support
onpaste is an HTML event attribute for the Clipboard API paste event. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
onpaste
Supported across modern browsers for user-initiated paste into editable content. Clipboard access rules still apply.
97%Global support (approx.)
Google ChromeYes
Full support
Mozilla FirefoxYes
Full support
Apple SafariYes
Full support
Microsoft EdgeYes
Full support
OperaYes
Full support
Samsung InternetYes
Full support
Internet ExplorerYes*
Legacy clipboardData
onpasteWidely supported
Bottom line: Safe to use for paste handling in forms and editors. Read clipboardData during the event; cancel only when you replace the insert yourself.
Remember
Key Takeaways
Role: run code when the user pastes into editable content.
Read with event.clipboardData.getData("text/plain").
Transform:preventDefault(), then insert your text.
Do not block paste lightly — it hurts accessibility and UX.
One line:onpaste lets you inspect or reshape clipboard text when the user pastes.
Frequently Asked Questions
It is an event handler attribute for the paste event. When the user pastes into an editable control (or a bubbling target), your script runs. You can read event.clipboardData and optionally cancel the default insert.
Inside the paste handler, call event.clipboardData.getData("text/plain") (or "text"). Outside a user-initiated clipboard event, browsers usually block clipboard reads.
Call event.preventDefault(), then insert your own text (for example set the input value or insert a text node into a contenteditable selection).
No. It is Baseline widely available. Prefer element.addEventListener("paste", …) in modern scripts; the HTML attribute is the same handler.
No. Dispatching a fake paste event does not change the document. Only a real user paste (or your own insert after preventDefault) updates content.
On editable elements such as input, textarea, and contenteditable regions, or on ancestors that listen while the event bubbles.