The ondragenter attribute is a global event handler that runs JavaScript when the dragenter event fires on a drop target — when a dragged item or text selection crosses into that element’s boundary (including nested descendants).
Use it for visual feedback (highlight the zone, update status text). Pair a draggable="true" source with ondragover, ondragleave, and ondrop on the receiver. To allow a drop, call event.preventDefault() in dragover — not as the main job of dragenter.
Baseline · Widely available.
Not deprecated and not experimental. The dragenter event has been stable across modern browsers since about July 2015.
Discouraged as inline HTML.
MDN discourages HTML event handler attributes. Prefer element.addEventListener("dragenter", handler) in production; use inline ondragenter for quick demos and learning.
Syntax
HTML Syntax
syntax.html
<element ondragenter="script">
script is JavaScript run when dragenter fires. Prefer: element.addEventListener("dragenter", handler).
Values
Attribute Values
The attribute value is JavaScript. Common patterns:
dragenter — pointer crosses into the target; good for highlight-on.
dragover — fires many times; call preventDefault() here to allow drop.
dragleave — pointer leaves; good for highlight-off (watch nested children).
drop — user releases on a valid target; receive the payload here.
Edge Cases & Pitfalls
Most surprises come from nested children or putting preventDefault in the wrong handler.
drop
Allow drop in dragover
Browsers block drops unless the target calls preventDefault() during dragover. Highlighting in dragenter alone does not enable drop.
nested
Child elements re-fire enter/leave
Moving over descendants can toggle highlight repeatedly. Use an enter counter or check event.relatedTarget on dragleave.
source
Not the same as ondragstart
dragenter fires on the receiver. Source events (dragstart, drag, dragend) fire on the item being dragged.
a11y
Drag is pointer-heavy
Offer keyboard or button alternatives. Announce zone state with an aria-live region instead of alert().
touch
Mobile behavior varies
HTML Drag and Drop is historically mouse-oriented. Test touch devices; consider Pointer Events when touch is required.
Compatibility
Browser Support
ondragenter 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
ondragenter
The dragenter event is widely available since about July 2015. Desktop Chrome, Firefox, Safari, and Edge support it well. Touch drag UX still differs by device.
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
ondragenterWidely supported
Bottom line: Safe to use for drop-zone feedback on modern sites. Prefer addEventListener, pair with dragover + preventDefault, and offer non-drag alternatives.
Remember
Key Takeaways
Role: run JS when a dragged item enters a drop target — usually to highlight.
Target, not source: put it on the receiver; source uses draggable + dragstart.
vs dragover: enter once per crossing; over repeats and enables drop via preventDefault.
Modern: prefer addEventListener("dragenter", …) over inline attributes.
One line:ondragenter highlights when a drag enters the zone — enable drop in dragover.
Frequently Asked Questions
It is an inline event handler that runs JavaScript when the dragenter event fires on a drop target — when a dragged item or text selection enters that element’s boundary.
No. Call event.preventDefault() in dragover on the drop target to allow dropping. Use dragenter mainly for visual feedback such as highlighting the zone.
ondragenter fires when the pointer crosses into the target (including nested children). ondragover fires repeatedly while the pointer stays over the target and is where preventDefault() enables drop.
Prefer element.addEventListener("dragenter", handler). Inline ondragenter works for learning but mixes HTML and JavaScript. MDN discourages HTML event handler attributes in production.
Moving over nested child elements can fire dragenter and dragleave on the parent repeatedly. Use an enter counter or check event.relatedTarget on dragleave to keep highlight state stable.
No. draggable="true" belongs on the source being dragged. The drop target needs dragenter, dragover, dragleave, and drop handlers.