HTML Drag and Drop (DnD) API

HTML Drag and Drop (DnD) API
The HTML Drag and Drop (DnD) API allows users to drag elements from one location and drop them into another. This is commonly used in file uploads, sorting lists, and interactive interfaces.
It works natively in browsers using JavaScript and does not require any plugins.
Key Concepts
Draggable Element
Any HTML element can be made draggable using the attribute:
Drag Events
dragstart→ Fired when dragging startsdrag→ Fired during draggingdragend→ Fired when dragging ends
Drop Zone Events
dragover→ Fired when a dragged element is over a drop zonedrop→ Fired when the element is droppeddragleave→ Fired when the dragged element leaves a drop zone
Data Transfer
Use
event.dataTransferto pass data between draggable and drop target.
Example: Simple Drag and Drop
Explanation
draggable="true"→ Makes the element draggable.dragstart→ Stores the element’s ID indataTransfer.dragover→ Must prevent default to allow dropping.drop→ Retrieves the dragged element and appends it to the drop zone.
Key Points
The Drag and Drop API is purely client-side, requiring HTML, CSS, and JavaScript.
It is interactive and widely used for file uploads, sorting lists, and UI customization.
Use
dataTransferto pass data or even files.Works best with modern browsers.
