HTML oncopy Event Attribute

HTMLWeb DevelopmentFront End Technology

The HTML oncopy attribute is triggered when user copy the content of an HTML element in an HTML document.


Following is the syntax −

<tagname oncopy=”script”></tagname>


Let us see an example of HTML oncopy event Attribute −

Live Demo

<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
   body {
      color: #000;
      height: 100vh;
      background-color: #FBAB7E;
      background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
      text-align: center;
      padding: 20px;
   p {
      font-size: 1.1rem;
<h1>HTML oncopy Event Attribute Demo</h1>
<p oncopy="get()">I'm a paragraph HTML element with some dummy text.</p>
<p style="color:#db133a;">Now try to copy above paragraph text.</p>
<div class="show"></div>
   function get() { = "lightblue";


Now try to copy the content of paragraph element to observe how oncopy event attribute work.

Updated on 16-Feb-2021 04:37:54