HTML onpaste Event Attribute


The onpaste HTML event attribute specifies the JavaScript function to be executed when the user pastes content into an element. It is supported by all HTML elements, but can only be used on elements that are editable, such as <input>, <textarea>, and elements with the contenteditable attribute set to true.

When the user pastes content into an element with the onpaste attribute, the JavaScript function specified by the attribute is executed. The function can then access the clipboard contents using the clipboardData property of the event object.

The onpaste event attribute can be used for a variety of purposes, such as:

  • Validating the pasted content before it is inserted into the element.
  • Converting the pasted content to a different format.
  • Performing some other action, such as updating a database or sending an email.

Here is an example of how to use the onpaste event attribute:

<input type="text" onpaste="validatePastedContent(event)">

The validatePastedContent() function would be responsible for validating the pasted content before it is inserted into the <input> element. If the content is not valid, the function could prevent it from being inserted or display an error message to the user.


<element onpaste="script">


  • scriptThe name of the script to use when the event has been triggered.


<!DOCTYPE html> 
<title>onpaste event</title>
<textarea onpaste="pasteAlarm()">Paste text here.</textarea>
<p id="test"> </p>
function pasteAlarm() {
document.getElementById("test").innerHTML = "The onpaste attribute has been triggered.";

Browser Support

The following table will show you the current browser support for the HTML onpaste Event Attribute.

Edge Chrome Firefox Opera Safari
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview

Last updated by CSSPortal on: 13th October 2023