HTML oncopy attribute

HTML oncopy attribute: In this attribute triggers when users copy the content in the element. This attribute accepts a single value script to run. There are three actions to copy the content of an element:

  • Press CTRL + C
  • Select “Copy” from the Edit menu in a browser
  • Right-click to show the context menu and select “Copy” command.

HTML oncopy attribute

This attribute is a part of all the elements in the HTML.

Syntax: <element oncopy = “script”>

Browser compatibility

This  attribute supports different types of browsers as follows

  • Chrome
  • Mozilla
  • InternetExplorer
  • Safari
  • Opera


<!DOCTYPE html> 
        <title>oncopy attribute</title> 
            body { 
            h1 { 
        <h2>oncopy attribute</h2> 
        <input type="text" oncopy="Freshersnow()" value="Freshersnow"> 
        <p id="sudo"></p> 
            function Freshersnow() { 
                document.getElementById("sudo").innerHTML = "Copied box content" 


html oncopy attribute