The ondragstart attribute is a global event handler that runs JavaScript when the dragstart event fires on the source — when the user begins dragging an element or text selection.
Use it to store payload with event.dataTransfer.setData(), set effectAllowed, or add a dragging style. Most elements need draggable="true". Drop targets still need ondragover + preventDefault() and ondrop. Reset visuals in ondragend.
Baseline · Widely available.
Not deprecated and not experimental. Stable since about July 2015. Per MDN, dragstart is cancelable and may bubble — preventDefault() can block the drag from starting.
Discouraged as inline HTML.
MDN discourages HTML event handler attributes. Prefer element.addEventListener("dragstart", handler) in production; use inline ondragstart for quick demos and learning.
Syntax
HTML Syntax
syntax.html
<element ondragstart="script">
script is JavaScript run when the drag begins. Prefer: element.addEventListener("dragstart", handler).
Values
Attribute Values
The attribute value is JavaScript. Common patterns:
Value / pattern
Description
Try it
setData(type, data)
Store text/plain (or other MIME) for the drop target
Check a condition inside dragstart (here: a checkbox).
preventDefault() cancels the drag before it starts.
No dragend / drop runs for a cancelled start.
Useful for locked cards, disabled rows, or permission checks.
Edge Cases & Pitfalls
Most “dragstart never fires” bugs are a missing draggable="true".
source
Needs draggable="true"
Plain divs and custom cards will not start a user drag without it. Images/links may drag under the default auto behavior.
drop
setData ≠ drop alone
Storing data in dragstart does nothing unless the target allows drop via dragover + preventDefault and reads it in drop.
style
Reset in dragend
If you add a “dragging” class in dragstart, always remove it in dragend so cancelled drops do not leave a faded element.
a11y
Offer a non-drag path
Keyboard and many assistive tech users cannot drag. Provide buttons or menus that do the same move/copy action.
touch
Mobile varies
HTML Drag and Drop is mouse-oriented. Test touch devices before relying on it alone.
Compatibility
Browser Support
ondragstart 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
ondragstart
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
ondragstartWidely supported
Bottom line: Safe to use for starting drag payloads on modern sites. Prefer addEventListener, pair with draggable, and finish drops with dragover + drop.
Remember
Key Takeaways
Role: runs on the source when a drag begins — set data and visuals.
Needsdraggable="true" on most elements.
setData in start; getData in drop; allow drop in dragover.
Cancelable:preventDefault() can block the drag from starting.
One line:ondragstart prepares the source payload — drop still needs dragover + drop.
Frequently Asked Questions
It is an inline event handler that runs JavaScript when the dragstart event fires on the source — when the user begins dragging an element or text selection.
Yes for most elements. Images and links are often draggable by default (auto). Plain divs and other nodes need draggable="true" for dragstart to fire from a user drag.
Store payload with event.dataTransfer.setData(), optionally set effectAllowed or a drag image, and add a visual class. Reset styles in dragend.
Yes. Calling preventDefault() in dragstart can cancel the drag so it does not start. Use that to block dragging under certain conditions.
Prefer element.addEventListener("dragstart", handler). Inline ondragstart works for learning. MDN discourages HTML event handler attributes in production.
ondragstart fires once when the drag begins on the source. ondragend fires when the drag finishes (success or cancel). Target events (dragenter, dragover, drop) fire on the drop zone.