CKTIS / HTML
onpaste — paste event handler
The onpaste attribute assigns JavaScript code to handle the paste event. It is available on all HTML elements, but adding it does not make an element editable.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
onpaste="JavaScript function body"onpaste is a global HTML event handler attribute associated with the paste event. Its value contains JavaScript statements forming a function body, not an event type name. The attribute itself does not make an element editable.
Inside the attribute code, event is the event object and this is the element handling the event. Returning return false cancels the event's default action when it is cancelable; for an ordinary paste into an editing field, this prevents text insertion. It does not mean that event propagation stops.
The HTML attribute onpaste and JavaScript property element.onpaste configure the same handler mechanism: the attribute contains code, whereas the property accepts a function or null. Assigning the property again replaces its previous function. addEventListener('paste', handler) registers listeners separately; it uses paste, without the on prefix.
The example updates a status message and blocks the default paste. It requires JavaScript and permission to execute inline event handlers; Content Security Policy can block them. Do not construct this code from untrusted data.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>onpaste demo</title>
<label>Paste here: <textarea onpaste="document.getElementById('status').textContent = 'paste handled'; return false;"></textarea></label>
<p id="status" role="status">waiting</p>
</html>Result
paste handled
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.