HTML Tutorial

The language for building web pages.

HTML Drag and Drop

HTML Drag and Drop API

In HTML, any element can be dragged and dropped. Drag and Drop is a very common feature. It is when you grab an object and drag it to a different location.

Steps to Implement:

  1. Set draggable="true" on the element
  2. Handle the ondragstart event to set data
  3. Handle ondragover on the drop target (prevent default)
  4. Handle ondrop to accept the dropped element

Try It Yourself

Edit the code below and click Run to see the result live.

Source Code
Result
Topics