A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/html/html-onpaste-event-attribute/ below:

HTML onpaste Event Attribute - GeeksforGeeks

HTML onpaste Event Attribute

Last Updated : 11 Jul, 2025

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: 

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4