The ondragover attribute is a global event handler that runs JavaScript when the dragover event fires on a drop target — repeatedly while a dragged item or text selection is over that element.
Its most important job: call event.preventDefault() so the browser allows a drop. Pair a draggable="true" source with ondragenter / ondragleave for highlight, and keep heavy work out of dragover (it fires often).
Baseline · Widely available.
Not deprecated and not experimental. Stable since about July 2015. Per MDN, dragover is cancelable and may bubble. Firing rate is browser/OS dependent (spec hint ≈ 350 ms ±200 ms).
Discouraged as inline HTML.
MDN discourages HTML event handler attributes. Prefer element.addEventListener("dragover", handler) in production; use inline ondragover for quick demos and learning.
Syntax
HTML Syntax
syntax.html
<element ondragover="script">
script is JavaScript run on each dragover. Prefer: element.addEventListener("dragover", handler).
Values
Attribute Values
The attribute value is JavaScript. Common patterns:
Toggle preventDefault on dragover, then drag the box onto the zone and release. Without it, drop does not fire.
dragover
Desktop mouse drag works best. Watch the status when you release over the zone.
Drop target
Drag me
Drop zone
preventDefault on — drop should work.
Code
HTML Examples
Short, copy-ready snippets. Use Try It Yourself for a live editor.
Example 1 — preventDefault Allows Drop
Call preventDefault() in dragover, then handle drop.
HTML
<div id="item" draggable="true">Drag me</div>
<div id="zone" ondragover="allowDrop(event)" ondrop="handleDrop(event)">
Drop here
</div>
<p id="msg"></p>
<script>
function allowDrop(e) {
e.preventDefault(); // without this, drop will not fire
}
function handleDrop(e) {
e.preventDefault();
document.getElementById("msg").textContent = "drop — item released.";
e.currentTarget.appendChild(document.getElementById("item"));
}
</script>
dragenter — once (per boundary crossing) when entering.
dragover — many times while the pointer stays over the target.
Keep it light — avoid expensive work in dragover.
Always call preventDefault() here if you want drop.
Edge Cases & Pitfalls
Most “drop does nothing” bugs are a missing preventDefault in dragover.
drop
No preventDefault → no drop
Browsers block drops by default. Call preventDefault() on every dragover for that target (and usually again in drop).
perf
Fires repeatedly
Do not run heavy DOM or network work here. Highlight in dragenter/dragleave; keep dragover tiny.
compare
Not the same as dragenter
dragenter is for “just entered.” dragover is continuous hover + allow-drop signal.
a11y
Offer a non-drag path
Pointer drag is hard for keyboard users. Provide buttons that do the same move/copy action.
touch
Mobile varies
HTML DnD is historically mouse-oriented. Test touch devices before relying on it alone.
Compatibility
Browser Support
ondragover is an HTML event handler attribute for the browser Drag and Drop API. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
ondragover
Widely available since about July 2015. Desktop Chrome, Firefox, Safari, and Edge support it well. Event frequency and dropEffect cursors still differ by platform.
96%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
Full support
Internet Explorer9+
Supported
ondragoverWidely supported
Bottom line: Safe to use as the allow-drop gate. Prefer addEventListener, always preventDefault when drop should work, and keep the handler light.
Remember
Key Takeaways
Role: fires while hovering a drop target — call preventDefault() to allow drop.
vs enter: enter once at boundary; over repeatedly while hovering.
dropEffect: optional cursor hint (copy / move / link / none).
Keep it light: put highlight in enter/leave; put payload work in drop.
One line:ondragover + preventDefault() unlocks drop — without it, nothing lands.
Frequently Asked Questions
It is an inline event handler that runs JavaScript when the dragover event fires on a drop target — repeatedly while a dragged item or text selection is over that element.
By default the browser does not allow dropping on most elements. Call event.preventDefault() in every dragover handler on the target so the drop event can fire.
ondragenter fires when the pointer crosses into the target. ondragover fires repeatedly while hovering and is where preventDefault() enables drop.
It depends on the browser, OS, and pointer movement. The HTML specification suggests roughly 350 ms (±200 ms). Do not assume a fixed interval or one event per pixel.
Prefer element.addEventListener("dragover", handler). Inline ondragover works for learning. MDN discourages HTML event handler attributes in production.
On dragover you can set event.dataTransfer.dropEffect to "copy", "move", "link", or "none" to hint the cursor feedback for the potential drop.