HTML oncut Event Attribute

The HTML oncut event attribute is triggered when a user cuts content from an HTML element. This event fires when the cut operation is performed using Ctrl+X keyboard shortcut, right-click context menu, or any other method that removes selected content to the clipboard.

Syntax

Following is the syntax for the oncut event attribute −

<tagname oncut="script">Content</tagname>

Where script is the JavaScript code to execute when the cut event occurs.

Parameters

The oncut event attribute accepts the following parameter −

  • script − Specifies the JavaScript code or function to run when the cut event is triggered.

How It Works

The oncut event is part of the clipboard events family, along with oncopy and onpaste. When a user selects content and performs a cut operation, the browser first fires the oncut event, then removes the selected content from the element and places it in the clipboard.

Common elements that support the oncut event include text inputs, textareas, and any element with editable content (contenteditable="true").

Example − Basic Cut Event

Following example demonstrates the basic usage of the oncut event attribute −

<!DOCTYPE html>
<html>
<head>
   <title>HTML oncut Event Example</title>
</head>
<body style="font-family: Arial, sans-serif; padding: 20px; text-align: center;">
   <h2>HTML oncut Event Attribute Demo</h2>
   <p oncut="showAlert()" style="border: 2px solid #ccc; padding: 10px; background: #f9f9f9;">
      Select and cut this text to trigger the oncut event.
   </p>
   <p style="color: #666;">Select some text above and press Ctrl+X to cut.</p>
   <script>
      function showAlert() {
         alert("Content has been cut!");
      }
   </script>
</body>
</html>

When you select text and cut it using Ctrl+X, an alert message appears confirming the cut operation.

Example − Cut Event with Visual Feedback

Following example shows how to provide visual feedback when content is cut −

<!DOCTYPE html>
<html>
<head>
   <title>Cut Event with Visual Feedback</title>
</head>
<body style="font-family: Arial, sans-serif; padding: 20px;">
   <h2>Cut Event with Background Change</h2>
   <textarea id="textArea" oncut="changeBackground()" placeholder="Type some text here and try cutting it..." style="width: 100%; height: 100px; padding: 10px; font-size: 14px;">This is some sample text. Select and cut part of this text to see the background change.</textarea>
   <p id="message" style="color: #333; margin-top: 10px;">Status: Ready</p>
   <script>
      function changeBackground() {
         document.body.style.background = "lightblue";
         document.getElementById("message").textContent = "Status: Content was cut!";
         document.getElementById("message").style.color = "red";
         
         setTimeout(function() {
            document.body.style.background = "white";
            document.getElementById("message").textContent = "Status: Ready";
            document.getElementById("message").style.color = "#333";
         }, 2000);
      }
   </script>
</body>
</html>

In this example, cutting text from the textarea temporarily changes the background color and updates a status message.

Example − Preventing Cut Operation

Following example shows how to prevent the cut operation from occurring −

<!DOCTYPE html>
<html>
<head>
   <title>Preventing Cut Operation</title>
</head>
<body style="font-family: Arial, sans-serif; padding: 20px;">
   <h2>Protected Content - Cut Disabled</h2>
   <p oncut="preventCut(event)" style="border: 2px solid #ff6b6b; padding: 15px; background: #ffe0e0;">
      This is protected content. Try to cut this text - the operation will be blocked!
   </p>
   <p style="color: #666;">Select text above and try Ctrl+X. The cut operation will be prevented.</p>
   <div id="notification" style="margin-top: 10px; color: red; font-weight: bold;"></div>
   <script>
      function preventCut(event) {
         event.preventDefault();
         document.getElementById("notification").textContent = "Cut operation blocked for security reasons!";
         
         setTimeout(function() {
            document.getElementById("notification").textContent = "";
         }, 3000);
      }
   </script>
</body>
</html>

Using event.preventDefault() in the oncut handler blocks the cut operation and displays a notification message.

oncut Event Flow User selects text Presses Ctrl+X oncut event triggers Content moved to clipboard The oncut event fires before the content is actually removed Use event.preventDefault() to block the cut operation

Browser Compatibility

The oncut event attribute is supported in all modern browsers including Chrome, Firefox, Safari, Edge, and Internet Explorer 9+. It works on any element that supports text editing or has.

Common Use Cases

The oncut event is commonly used for −

  • Content protection − Preventing users from cutting sensitive information
  • User activity tracking − Logging when users cut content for analytics
  • Form validation − Triggering validation when content is modified through cutting
  • Auto-save functionality − Saving document state when content changes

Conclusion

The HTML oncut event attribute provides a way to respond when users cut content from elements. It can be used for content protection, user interaction tracking, or providing visual feedback. Combined with event.preventDefault(), it offers control over clipboard operations in web applications.

Updated on: 2026-03-16T21:38:54+05:30

130 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements