The onpaste attribute works when some content is pasted in an element. This event attribute is supported by all HTML elements. It is mostly used with <input> element.
There are three ways to paste the content in HTML elements which are listed below:Â
- Use CTRL + V key
- Select “Paste” from the edit menu in the browser.
- select the “Paste” command from the right-click menu
Syntax:Â
<element onpaste = "script">
Attribute Value
The script event runs when the onpaste attribute is called.
Example 1:
In this example, we will see the implementation of the above event attribute.Â
HTML
<!DOCTYPE html>
<html>
<head>
<title>onpaste attribute</title>
<style>
body {
text-align: center;
}
h1 {
color: green;
}
input {
padding: 20px;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>onpaste Attribute</h2>
<input type="text" onpaste="Geeks()"
value="A computer science portal for geeks"
size="40">
<p id="sudo"></p>
<script>
function Geeks() {
document.getElementById("sudo").
innerHTML = "pasted text!";
}
</script>
</body>
</html>
|
Output:Â

Output
Example 2 :
In this example, we will see the implementation of the above event attribute.Â
HTML
<!DOCTYPE html>
<html>
<head>
<title>onpaste attribute</title>
<style>
body {
text-align: center;
}
h1 {
color: green;
}
input {
padding: 20px;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>onpaste Attribute</h2>
<input type="text" onpaste="Geeks()"
value="A computer science portal for geeks"
size="40">
<script>
function Geeks() {
alert("pasted text!");
}
</script>
</body>
</html>
|
Output:

Output
Supported Tags:
It supports all HTML elements.Â
Supported Browsers
- Google Chrome 1 and above
- Edge 12 and above
- Firefox 22 and above
- Opera 12.1 and above
- Safari 1 and above
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!
Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!
Last Updated :
20 Dec, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...