The ondragend attribute is an event-handler attribute for the element being dragged. It runs JavaScript when the dragend event fires — the drag operation ends (mouse button released, or Escape cancels the drag).
Use it on the source (with draggable="true") to reset styles or state after dragstart. The drop target uses ondrop. Typical order: dragstart → drag… → dragend.
Baseline · Widely available.
Not deprecated and not experimental. The dragend event is stable across modern browsers since about July 2015. It is cancelable and may bubble.
Touch & keyboard caveat.
HTML drag-and-drop is mainly pointer-based. Offer a non-drag way to move items. Prefer addEventListener in apps.
Syntax
HTML Syntax
syntax.html
<element draggable="true" ondragend="script">
script is JavaScript that runs when the drag finishes. Equivalent JS: el.ondragend = handler or el.addEventListener("dragend", handler).
Values
Attribute Values
The attribute value is always a script. Common patterns:
Drop zone calls preventDefault on dragover/drop so a drop is allowed.
On dragend read event.dataTransfer.dropEffect.
Often none if canceled or no valid drop; otherwise copy, move, or link.
Exact values vary by browser and how effectAllowed was set in dragstart.
Edge Cases & Pitfalls
Most confusion is mixing up source dragend with target drop, or forgetting cleanup when the drag is canceled.
source
Fires on the drag source
Put ondragend on the draggable element — not on the drop zone. The zone uses ondrop.
cancel
Still fires on Escape / failed drop
Always clean up in dragend. Do not assume a successful drop happened.
vs drop
Not a substitute for ondrop
Moving DOM nodes into a target belongs in the target’s drop handler (with dragover + preventDefault).
setup
Need draggable="true"
Without it, most elements never start a drag — so dragend never runs.
a11y
Offer a non-drag path
Keyboard and many touch users cannot rely on HTML DnD. Provide buttons or another move UI.
Compatibility
Browser Support
ondragend is an HTML event-handler attribute for the Drag and Drop API in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
ondragend
Widely available since about July 2015 on desktop. Mobile/touch HTML drag-and-drop remains inconsistent — test your targets and provide fallbacks.
94%Global support (approx.)
Google Chrome4+
Full support
Mozilla Firefox3.5+
Full support
Apple Safari3.1+
Full support
Microsoft Edge12+
Full support
Opera12+
Full support
Samsung InternetModern
Partial / check
Internet Explorer9+
Supported
ondragendWidely supported (desktop)
Bottom line: Safe for desktop drag cleanup. Prefer addEventListener, always reset source styles in dragend, and offer a non-drag alternative.
Remember
Key Takeaways
Role: run script when the drag on the source finishes.
Cleanup: reset opacity/classes set in dragstart.
vs drop:drop is on the target; dragend is on the source.
Always: fires on cancel too — clean up every time.
One line:ondragend is the source’s “drag finished” hook — use it to tidy up after every drag.
Frequently Asked Questions
It is an event-handler attribute on the element being dragged. When the drag operation ends — usually by releasing the mouse button or pressing Escape — the dragend event fires and the JavaScript in ondragend runs.
On the drag source (the element with draggable). The drop target receives drop (and dragover). Use dragend on the source to clean up styles or state.
ondrop fires on the drop target when a valid drop happens. ondragend fires on the source when the drag finishes, whether the drop succeeded or was canceled.
Yes. Ending the drag with Escape still fires dragend on the source. Check dataTransfer.dropEffect (often "none") if you need to know the outcome.
Both work. For learning, ondragend in HTML is fine. In production code, prefer element.addEventListener("dragend", handler).
No. The dragend event and ondragend handler are part of the HTML Drag and Drop API and are Baseline widely available since about July 2015.