HTML oncut Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The oncut attribute is an event-handler attribute. It runs JavaScript when the cut event fires — the user starts a cut through the browser UI (for example Ctrl+X / Cmd+X, or a Cut menu item).

By default, the selection is copied to the clipboard and removed from the document. Your handler can replace clipboard data with clipboardData.setData(…) and preventDefault() — but canceling also stops the automatic removal, so call selection.deleteFromDocument() if you still want a cut. It cannot read the clipboard. Related: oncopy, onpaste.

Baseline · Widely available.

Not deprecated and not experimental. The cut event is stable across modern browsers since about July 2015. It bubbles, is cancelable, and is composed.

Prefer addEventListener in apps.

Inline oncut is fine for learning. Production code usually uses el.addEventListener("cut", handler). Cutting only works on editable content (inputs, textareas, contenteditable).

HTML Syntax

syntax.html
<element oncut=" script">

script is JavaScript that runs when cut fires. Equivalent JS: el.oncut = handler or el.addEventListener("cut", handler).

Attribute Values

The attribute value is always a script. Common patterns:

Value / patternDescriptionTry it
scriptAny JavaScript run when the user initiates cutTry it
oncut="fn()"Call a named function from the attributeTry it
clipboardData.setDataWrite custom text; use deleteFromDocument() if you still want removalTry it
preventDefault() onlyCancel cut — nothing is written or removedTry it
addEventListener("cut")Preferred modern listener on the element or documentTry it

Live Preview

Select text in the editable box, then cut (Ctrl+X / Cmd+X). Toggle options to transform or block the cut.

On cut

Paste somewhere else to verify uppercase. Block mode leaves the text in place.

Editable text
Select this sample text, then cut it.

Waiting for cut…

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Inline oncut on a Textarea

Show a status message when the user cuts from the field.

HTML
<label for="notes">Notes:</label>
<textarea id="notes" rows="3" cols="40" oncut="onCutNote()">
Select some text and cut it.
</textarea>
<p id="status">Waiting for cut…</p>

<script>
  function onCutNote() {
    document.getElementById("status").textContent = "cut event fired.";
  }
</script>
Try It Yourself

How It Works

  1. User selects text in the textarea.
  2. User cuts via keyboard or UI — cut fires on the element.
  3. oncut runs onCutNote() and updates status.
  4. Default still cuts — clipboard write + remove — unless you call preventDefault().

Example 2 — Uppercase Cut + Remove Selection

Replace clipboard text and still delete the selection (emulate cut).

HTML
<div id="source" contenteditable="true">
  Cut text from this box.
</div>
<p id="hint">Paste elsewhere to see UPPERCASE.</p>

<script>
  document.getElementById("source").addEventListener("cut", function (event) {
    var selection = document.getSelection();
    event.clipboardData.setData(
      "text/plain",
      selection.toString().toUpperCase()
    );
    selection.deleteFromDocument();
    event.preventDefault();
  });
</script>
Try It Yourself

How It Works

  1. Read the selection with document.getSelection().
  2. Write new data with clipboardData.setData("text/plain", …).
  3. Remove the selection with deleteFromDocument() (because you will cancel the default).
  4. Call preventDefault() so the browser does not also write the raw selection.

Example 3 — Cancel the Default Cut

Stop both the clipboard write and the removal from the document.

HTML
<textarea id="locked" rows="3" cols="40" oncut="blockCut(event)">
Try to cut this sentence.
</textarea>
<p id="log"></p>

<script>
  function blockCut(event) {
    event.preventDefault();
    document.getElementById("log").textContent =
      "Cut blocked (default action canceled).";
  }
</script>
Try It Yourself

How It Works

  1. User tries to cut from the textarea.
  2. preventDefault() cancels clipboard write and removal.
  3. Status updates so the student sees the event still ran.
  4. Text stays put — unlike a successful cut.

Edge Cases & Pitfalls

Most mistakes are forgetting that preventDefault also skips removing the selection, or trying to read the clipboard.

vs copy

Cut removes; copy does not

oncopy only writes to the clipboard. oncut writes and deletes the selection by default.

prevent

Canceling skips removal too

If you setData and preventDefault but still want a cut, call selection.deleteFromDocument() yourself.

read

Cannot read clipboard in cut

The handler may write with setData, but it cannot read clipboard contents.

readonly

Uneditable content

cut may still fire on non-editable text, but the event carries no clipboard data and nothing is removed.

synthetic

Synthetic cut events

Dispatching a fake cut does not change the system clipboard or the document. Only a real user-initiated cut does.

Browser Support

oncut is an HTML event-handler attribute for the Clipboard API in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

oncut

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support the cut event on editable content.

97% Global support (approx.)
Google Chrome 1+
Full support
Mozilla Firefox 22+
Full support
Apple Safari 3+
Full support
Microsoft Edge 12+
Full support
Opera 15+
Full support
Samsung Internet Modern · Full
Full support
Internet Explorer 9+
Supported
oncut Widely supported

Bottom line: Safe to use for reacting to user cut. Prefer addEventListener in production, and remember preventDefault also blocks removing the selection.

Key Takeaways

  • Role: run script when the user initiates a cut.
  • Default: clipboard write and remove selection.
  • Customize: setData + preventDefault (+ deleteFromDocument if needed).
  • Family: pair with oncopy / onpaste as needed.

One line: oncut is copy-plus-remove — cancel carefully if you still need the selection deleted.

Frequently Asked Questions

It is an event-handler attribute. When the user starts a cut action through the browser UI (for example Ctrl+X / Cmd+X), the cut event fires and the JavaScript in oncut runs.
Both can put data on the clipboard. Cut’s default action also removes the selection from the document. Copy leaves the document unchanged.
Yes. Call event.clipboardData.setData("text/plain", yourText) and event.preventDefault(). If you still want the selection removed, call selection.deleteFromDocument() yourself.
No. A cut event handler cannot read clipboard contents. It can only write via clipboardData.setData after canceling the default action.
Both work. For learning, oncut in HTML is fine. In production code, prefer element.addEventListener("cut", handler) so you can attach multiple listeners and keep script out of markup.
No. The cut event and oncut handler are standard and Baseline widely available since about July 2015.

Next: ondblclick

Run JavaScript when the user double-clicks an element.

ondblclick tutorial →

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.

8 people found this page helpful