CHAPTER 17
Beginner
HTML Drag and Drop API
Updated: May 10, 2026
5 min read
# HTML Drag and Drop API
1. Introduction
HTML5 introduced native Drag and Drop (DnD). This API allows you to click an element, drag it across the screen, and drop it into another element. It's the foundation of modern interfaces like Trello boards or file-upload zones.2. Learning Objectives
- Make an element draggable.
- Create a drop zone.
-
Understand the basic JavaScript events required (
ondragstart,ondragover,ondrop).
3. Detailed Explanations
Step 1: Make it Draggable
To make an HTML element draggable, set thedraggable attribute to true.
html
Step 2: What to Drag (ondragstart)
When the user starts dragging, JavaScript stores the ID of the dragged item in the DataTransfer object.
javascript
Step 3: Where to Drop (ondragover)
By default, HTML elements cannot be dropped onto other elements. To create a "Drop Zone", you must prevent this default behavior using ondragover.
html
Step 4: Do the Drop (ondrop)
When the item is released over the drop zone, retrieve the ID and append the element to the new container.
javascript
4. Mini Project: Task Board UI (Kanban)
html
5. MCQs
Q1: Which attribute makes an HTML element draggable? A)drag="true"
B) moveable="true"
C) draggable="true"
D) drag-and-drop="enable"
*Answer: C*
6. Summary
The HTML Drag and Drop API combines thedraggable HTML attribute with specific JavaScript events (dragstart, dragover, drop) to create highly interactive, modern web applications.