HTML oncut Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Events & Handlers

Introduction

The oncut attribute is an inline event handler that runs JavaScript when the cut event fires. That happens when the user cuts content — with Ctrl+X (Cmd+X on Mac), Edit → Cut, or the context menu Cut action. Unlike copy, cut removes the selection from the source after placing it on the clipboard. It is common on contenteditable regions, textarea, and input fields. Use it for validation before removal, logging edits, or customizing clipboard data with event.clipboardData. The cut event bubbles. For production sites, prefer addEventListener("cut", …) over inline handlers.

What You’ll Learn

01

Event handler

Inline JS.

02

cut event

Ctrl+X / Cut.

03

contenteditable

Editable div.

04

vs oncopy

Cut vs copy.

05

addEventListener

Preferred way.

06

preventDefault

Cancel cut.

Purpose of oncut Attribute

The primary purpose of oncut is to react when the user cuts text or content from an editable element. Common uses include validating that removed content is allowed, showing a “Text cut” message, logging editor changes, or customizing what lands on the clipboard via event.clipboardData. Because cut both copies and removes, your handler runs before the selection disappears — use event.preventDefault() to block the cut if needed.

Do not confuse oncut with oncopy. Copy duplicates content; cut moves it off the page. Pair with onpaste for full clipboard coverage. Avoid blocking cut without a good reason — users rely on Cut for editing and accessibility workflows.

💡
Cancel a cut with preventDefault

In the cut handler, call event.preventDefault() to stop the selection from being removed and prevent the default clipboard update.

📝 Syntax

Set oncut on an editable element or assign element.oncut:

oncut.html
<script>

  function handleCut() {

    document.getElementById("status").textContent = "Content cut!";

  }

</script>



<div contenteditable="true" oncut="handleCut()">

  Select and cut this editable text.

</div>

<p id="status"></p>

Syntax Rules

  • Value is JavaScript code executed when the user cuts from the element.
  • Pass event when you need clipboardData or preventDefault().
  • Works on editable elements: contenteditable, textarea, input, etc.
  • JavaScript: element.oncut = function(e) { … }.
  • Modern alternative: element.addEventListener("cut", handler).
  • The cut event bubbles — you can delegate on a parent container.

💎 Values

The oncut attribute accepts a string of JavaScript code:

  • oncut="handleCut()" — Call a named function.
  • oncut="handleCut(event)" — Pass the event for clipboard access or cancellation.
  • JavaScript: field.oncut = (e) => { … } assigns the handler.
oncut-js.html
const editor = document.getElementById("editor");

editor.addEventListener("cut", (event) => {

  const selection = window.getSelection().toString();

  if (selection.length > 500) {

    event.preventDefault();

    document.getElementById("msg").textContent = "Cannot cut more than 500 characters.";

    return;

  }

  document.getElementById("msg").textContent = "Cut allowed.";

});

⚡ Quick Reference

EventWhen it firesHandler
copyUser copies selectiononcopy
cutUser cuts selectiononcut
pasteUser pastesonpaste
clipboardDataIn copy/cut handlersetData / getData
KeyboardCtrl+X / Cmd+XFires cut
Bubbles?cut yesDelegate on parent

Applicable Elements

TargetSupported?Notes
contenteditableYesMost common for rich inline editing
<textarea>, <input>YesCut from form fields
<div>, <p>SometimesWhen text is selectable or contenteditable
<pre>, <code>YesCommon for code snippets
<img>LimitedCopy image via browser, not text selection
<button>SometimesWhen button label text is selected

oncut vs oncopy vs onpaste

HandlerWhen it firesTypical use
oncutContent cut (copy + remove)Validate before removing text
oncopyContent copied to clipboardFeedback, attribution, logging
onpasteContent pasted from clipboardSanitize pasted input

Examples Gallery

Inline oncut on contenteditable, addEventListener with validation, and comparing cut with copy events.

👀 Live Preview

Select text in the editable box and cut it (Ctrl+X or context menu Cut):

Cut this sample text. Select any part of it, then press Ctrl+X.

Cut some text to see the event fire.

Example — Inline oncut on contenteditable

Show feedback when the user cuts content from an editable div:

inline-oncut.html
<div contenteditable="true" oncut="handleCut()">

  Try cutting this text!

</div>



<script>

  function handleCut() {

    document.getElementById("msg").textContent = "Text cut!";

  }

</script>
Try It Yourself

How It Works

The browser fires cut when the clipboard receives content and the selection is removed. Your inline handler runs at that moment.

Dynamic Values with JavaScript

Assign the handler with element.oncut or addEventListener:

dynamic-oncut.html
const editable = document.getElementById("dynamicEditable");

editable.oncut = function () {

  console.log("Dynamic content cut!");

};



// Or preferred form:

editable.addEventListener("cut", () => {

  console.log("Cut detected via addEventListener.");

});
Try It Yourself

How It Works

Register the listener once at page load. When the user cuts, your handler runs before the default removal completes.

Example — cut vs copy

Listen for both clipboard events on the same field:

cut-vs-copy.html
field.addEventListener("cut", () => {

  log("cut — removed from field");

});



field.addEventListener("copy", () => {

  log("copy — duplicated to clipboard");

});
Try It Yourself

How It Works

Both are clipboard events. oncut handles move-style removal; oncopy handles duplication only.

♿ Accessibility

  • Do not block cut lightly — Users rely on Cut for editing and assistive workflows. Avoid preventDefault() unless validation truly requires it.
  • Provide feedback — A visible status message helps users understand that their cut action was registered.
  • contenteditable accessibility — Editable regions need clear labels and keyboard focus styles so users know where they can edit and cut.
  • Avoid alert() on cut — Use inline status text or toast-style messages instead of modal alerts.
  • Keyboard users — Cut via Ctrl+X / Cmd+X must still work when you add custom cut handlers.

🧠 How oncut Works

1

User selects text

Highlights editable content.

Selection
2

User cuts

Ctrl+X or Cut command.

Action
3

cut event fires

Handler runs on element.

oncut
=

Content removed

Clipboard + source updated.

Browser Support

The cut event and oncut handler are supported in all modern browsers — Chrome, Firefox, Safari, and Edge. clipboardData and preventDefault() work in current browsers during the cut event.

DOM Events · Fully supported

Universal oncut support

All major browsers fire the underlying event and honor the oncut handler attribute.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer IE 9+ supported
Full support
Opera Fully supported
Full support
oncut attribute 99% supported

Bottom line: Universal support for the cut event. Test with keyboard cut (Ctrl+X) and context menu Cut on contenteditable and textarea elements.

💡 Best Practices

✅ Do

  • Use addEventListener on the element — Clearer than inline oncut.
  • Validate before blocking — Use preventDefault() only when cut must be cancelled (e.g. protected content).
  • Show cut feedback — A brief status message improves UX without blocking the clipboard.
  • Pair with oncopy and onpaste — Handle the full clipboard lifecycle when building editors.
  • Keep handlers fast — Cut handlers run synchronously before content is removed; avoid slow work.

❌ Don’t

  • Respect user intent — Do not use cut handlers to silently discard content the user meant to move.

Conclusion

The oncut attribute runs JavaScript when the user cuts content from an editable element and the cut event fires. Use it for validation, feedback, or customizing clipboard data with event.clipboardData.

Prefer addEventListener("cut", …), respect user expectations, and pair with oncopy and onpaste when building clipboard-aware editors.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about oncut

Bookmark these before wiring your next event handler.

5
Core concepts
🌐 02

Editable content

contenteditable.

Scope
🔄 03

preventDefault

Cancel cut.

Pattern
📝 04

addEventListener

Preferred.

Modern
05

vs oncopy

Cut vs copy.

Note

❓ Frequently Asked Questions

It runs JavaScript when the cut event fires — when the user cuts content from an editable element.
Editable elements: contenteditable divs, textarea, input, and other elements where cut is allowed.
Yes. Use event.preventDefault() in the cut handler to cancel the operation and keep content in place.
oncut copies and removes content. oncopy duplicates content and leaves it in place.
Prefer element.addEventListener("cut", …). Inline oncut works for simple demos.
Yes. One listener on a parent can handle cut events from child elements.

Handle cut events with JavaScript

Practice inline oncut, addEventListener, and cut vs copy in the Try It editor.

Try oncut demo →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful