KoderSolution Logo
HomeArticlesTutorialsForumAI LabRun Code
KoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Engineering Newsletter

Join 100,000+ engineers receiving curated high-signal content weekly.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
🌐

HTML

Topic Hub & Articles

HTML HOME

3 min

HTML Introduction

5 min

HTML Editors

10 min

Recap Quiz

5 Questions

HTML Basic

10 min

HTML Elements

10 min

HTML Attributes

10 min

Recap Quiz

5 Questions

HTML Headings

10 min

HTML Styles

10 min

Recap Quiz

5 Questions

HTML Paragraphs

10 min

HTML Formatting

10 min

HTML Quotations

10 min

HTML Comments

10 min

Recap Quiz

5 Questions

HTML Colors

7 min

HTML CSS

10 min

HTML Links

10 min

Recap Quiz

5 Questions

HTML Images

10 min

HTML Favicon

10 min

HTML Page Title

10 min

Recap Quiz

5 Questions

HTML Tables

10 min

HTML Lists

10 min

HTML Block and Inline

10 min

Recap Quiz

5 Questions

HTML Classes

10 min

HTML Id

10 min

HTML Iframes

10 min

Recap Quiz

5 Questions

HTML JavaScript

10 min

HTML File Paths

10 min

HTML Head

10 min

Recap Quiz

5 Questions

HTML Layout

10 min

HTML Responsive

10 min

HTML Computercode

10 min

Recap Quiz

5 Questions

HTML Forms

10 min

HTML Form Attributes

10 min

HTML Form Elements

10 min

Recap Quiz

5 Questions

HTML Input Types

10 min

HTML Input Attributes

10 min

HTML Input Form Attributes

10 min

Recap Quiz

5 Questions

HTML Canvas

10 min

HTML SVG

10 min

HTML Media Intro

10 min

HTML Video

10 min

HTML Audio

10 min

Recap Quiz

5 Questions

HTML YouTube

10 min

HTML Geolocation

10 min

HTML Drag/Drop

10 min

HTML Local Storage

10 min

Recap Quiz

5 Questions

HTML Session Storage

10 min

HTML Web Workers

10 min

HTML SSE

10 min

Recap Quiz

5 Questions

HTML Semantics

10 min

HTML Accessibility

10 min

HTML Entities

10 min

Recap Quiz

5 Questions

HTML Symbols

10 min

HTML Emojis

10 min

HTML Charset

10 min

Recap Quiz

5 Questions

HTML URL Encode

10 min

HTML XHTML

10 min

HTML Global Attributes

10 min

Recap Quiz

5 Questions

HTML Event Attributes

10 min

HTML Color Groups

10 min

HTML URL Paths

10 min

Recap Quiz

5 Questions

HTML Summary

10 min

Progress
0%

0 / 61 Lessons

HTMLHTML APIs
Lesson

HTML Drag/Drop

10 min reading
Free Course

HTML Drag and Drop API: Building Interactive Drag-and-Drop UIs

The HTML Drag and Drop API allows users to click, drag, and drop elements between different containers on a web page, enabling interactive Kanban boards, file drop zones, and element reordering.

Drag and Drop Events and Syntax

To make an element draggable, set draggable="true" and handle key drag/drop events:

<!-- Draggable Element -->
<div draggable="true" ondragstart="handleDragStart(event)">Drag Me</div>

<!-- Drop Zone Container -->
<div ondragover="event.preventDefault()" ondrop="handleDrop(event)">Drop Here</div>

Key drag and drop events:

  1. ondragstart: Fires on the target element when the user starts dragging.
  2. ondragover: Fires continuously on the drop target while an item is dragged over it (must call event.preventDefault() to allow dropping).
  3. ondrop: Fires on the drop target when the user releases the dragged element.
  4. dataTransfer: Event object property used to store and transfer dragged data payload (event.dataTransfer.setData()).

Drag and Drop Event Cycle

flowchart TD
    A["User Drags draggable='true' Element"] --> B["ondragstart: Save Data to event.dataTransfer"]
    B --> C["User Drags Over Drop Zone"]
    C --> D["ondragover: event.preventDefault() (Allows Drop)"]
    D --> E["User Releases Mouse"]
    E --> F["ondrop: Read dataTransfer & Append Element to Drop Zone"]

Practical Code Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>HTML Drag and Drop Example</title>
    <style>
        .box { width: 100px; height: 100px; background-color: #38bdf8; border-radius: 8px; cursor: move; display: flex; align-items: center; justify-content: center; font-weight: bold; color: #0f172a; }
        .dropzone { width: 200px; height: 150px; background-color: #1e293b; border: 2px dashed #334155; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
    </style>
</head>
<body style="font-family: system-ui, sans-serif; background-color: #0f172a; color: #f8fafc; padding: 2rem;">

    <h2>Kanban Drag and Drop Demo</h2>

    <div style="display: flex; gap: 2rem; align-items: center;">
        <div id="dragItem" class="box" draggable="true">Card</div>
        <div id="dropContainer" class="dropzone">Drop Zone</div>
    </div>

    <script>
        const item = document.getElementById("dragItem");
        const zone = document.getElementById("dropContainer");

        item.addEventListener("dragstart", (e) => {
            e.dataTransfer.setData("text/plain", e.target.id);
        });

        zone.addEventListener("dragover", (e) => {
            e.preventDefault(); // Required to enable drop
        });

        zone.addEventListener("drop", (e) => {
            e.preventDefault();
            const id = e.dataTransfer.getData("text/plain");
            const dragged = document.getElementById(id);
            zone.appendChild(dragged);
            zone.style.borderColor = "#34d399";
        });
    </script>

</body>
</html>

Best Practices

  • Always call event.preventDefault() inside dragover: Browsers block file and element dropping by default; calling preventDefault() enables dropping.
  • Provide clear visual drop target feedback: Change border colors or opacity when an item is dragged over a valid drop zone.
  • Support touch events for mobile devices: Native HTML drag-and-drop lacks full touch screen support; pair with touch event handlers on mobile viewports.

Self-Check Challenge

Create a <div> element with draggable="true" and an ondragstart handler saving data via event.dataTransfer.setData()!

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Recommended Courses & Books

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum