The HTML oncut event
The HTML oncut attribute runs JavaScript when the user cuts the element's content to the clipboard. It is an inline handler for the cut event; in modern code prefer addEventListener('cut', …).
Overview
The oncut event attribute runs JavaScript when content is cut. In JavaScript the event itself is named cut — drop the on prefix when you call addEventListener.
It is a clipboard event. The handler receives a ClipboardEvent whose clipboardData object lets you read or modify what is being transferred — for example to sanitize pasted content or add a copyright line to copied text.
You can wire this up with the inline oncut HTML attribute, but the modern, recommended approach is element.addEventListener('cut', handler) in JavaScript. That keeps behavior out of your markup, lets you attach several handlers to the same event, and makes them easy to remove. The inline attribute is fine for quick demos.
Syntax
<element oncut="handler()">…</element>
element.addEventListener('cut', handler);
Best practices
- Prefer
element.addEventListener('cut', handler)over the inlineoncutattribute — it separates behavior from markup and allows multiple handlers. - Call
event.preventDefault()before writing your own data toclipboardData. - Sanitize pasted content rather than trusting it as-is.
- Do not block normal copy/paste — interfering with it frustrates users.
Frequently asked questions
What is the oncut event?
cut.How do I access the copied or pasted data?
event.clipboardData on the ClipboardEvent.Can I modify what gets copied?
preventDefault() and write your own value to event.clipboardData.Should I use the oncut attribute or addEventListener?
addEventListener('cut', …) in JavaScript. The inline oncut attribute works but mixes behavior into the markup and allows only one handler per element.