Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For native HTML drag and drop, mark the source with draggable="true", place a value in event.dataTransfer during dragstart, cancel dragover on an eligible drop target, and handle the value in drop. Your code—not the browser—must validate the drop and update application state. Also provide a way to use the feature without dragging: WCAG 2.2 Success Criterion 2.5.7 requires a single-pointer alternative unless an exception applies.

Implement a basic native drag-and-drop interaction

This runnable example moves a task between two lists. It transfers a stable task ID rather than relying on a DOM node or passing an in-memory JavaScript object. On drop, it checks the ID and destination, updates the data model, and renders the lists from that model.

<ul id="todo" aria-label="To do">
  <li draggable="true" data-id="task-42">Prepare release notes</li>
</ul>

<ul id="done" aria-label="Done"></ul>

<script>
  const lists = {
    todo: [{ id: 'task-42', text: 'Prepare release notes' }],
    done: []
  };
  const payloadType = 'application/x-example-task-id';
  const allowedDestinations = new Set(['todo', 'done']);

  function render() {
    for (const listName of Object.keys(lists)) {
      const list = document.getElementById(listName);
      list.replaceChildren();
      for (const task of lists[listName]) {
        const item = document.createElement('li');
        item.textContent = task.text;
        item.dataset.id = task.id;
        item.draggable = true;
        list.append(item);
      }
    }
  }

  document.addEventListener('dragstart', (event) => {
    const item = event.target.closest('li[draggable="true"][data-id]');
    if (!item) return;
    event.dataTransfer.setData(payloadType, item.dataset.id);
    event.dataTransfer.effectAllowed = 'move';
  });

  document.addEventListener('dragover', (event) => {
    const target = event.target.closest('ul[id]');
    if (!target || !allowedDestinations.has(target.id)) return;
    event.preventDefault();
    event.dataTransfer.dropEffect = 'move';
  });

  document.addEventListener('drop', (event) => {
    const target = event.target.closest('ul[id]');
    if (!target || !allowedDestinations.has(target.id)) return;
    event.preventDefault();

    const id = event.dataTransfer.getData(payloadType);
    const sourceName = Object.keys(lists).find((name) =>
      lists[name].some((task) => task.id === id)
    );
    if (!sourceName || sourceName === target.id) return;

    const [task] = lists[sourceName].filter((entry) => entry.id === id);
    lists[sourceName] = lists[sourceName].filter((entry) => entry.id !== id);
    lists[target.id].push(task);
    render();
  });

  render();
</script>

Save this as an HTML file and open it in a browser. The example uses the browser’s native drag-and-drop events. Its in-memory arrays are demonstration state; a production application should update its own state store or persist the change as appropriate.

Understand the native drag event lifecycle

A typical operation starts at the draggable source, passes across potential targets, and ends at the source. The HTML Living Standard and MDN describe the event model in detail: WHATWG HTML Living Standard: Drag and drop, MDN: Drag operations.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Event Where it occurs Use it for
dragstart Source Set the permitted effect and transfer a stable identifier or serialized value.
dragenter and dragleave Elements the dragged item enters or leaves Optional visual feedback, such as highlighting a valid target.
dragover Current potential target, repeatedly Cancel the event on a valid target to opt into receiving a drop; optionally set the cursor effect.
drop Accepted target Read and validate the transferred value, then perform the application action.
dragend Source Clear temporary styling or state whether the operation succeeded or was canceled.

Most elements do not accept drops by default. Cancel dragover only for targets that are valid in the current application context. The specification says dragenter should also be canceled, but MDN notes that browsers do not implement that requirement in practice. In the drop handler, prevent the default when the page is handling the drop. See MDN’s event guidance.

Use dragend for cleanup rather than assuming a successful drop: it fires when the drag completes whether it succeeded or was canceled. During a native drag, the browser suppresses device input events, so do not expect ordinary mouse or keyboard event handling to replace the drag event lifecycle.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Transfer data safely and update application state

DataTransfer carries text or files; it does not pass arbitrary JavaScript object references between pages or applications. A common in-page pattern is to transfer a type-tagged string containing a stable record ID, look up that ID in current application state, and then apply the operation. The API overview is in MDN: HTML Drag and Drop API.

  • Validate the payload: Treat transferred data as input. Check that the ID exists and that the current user and application rules permit the operation.
  • Validate the destination: A destination that accepts one item or user may not accept another. Do not rely on a drop cursor or client-side identifier as authorization.
  • Use application state as the source of truth: Change the model, then render the result. Directly moving DOM nodes alone can leave a framework’s state or persisted data unchanged.
  • Choose the effect intentionally: Set effectAllowed at the source, such as move, and a compatible dropEffect on a valid target when useful.

For file drops, inspect the transferred file items and handle them as files rather than expecting an application-specific text ID. The details of data types and drag data are covered by MDN’s API overview.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Make the interaction accessible without requiring a drag

Keyboard operation and a non-drag pointer alternative are separate needs. WCAG 2.2 Success Criterion 2.5.7 requires functionality operated by dragging to also work with a single pointer without dragging, unless dragging is essential or the user agent controls the functionality. See the WCAG 2.2 standard and W3C’s explanation of Dragging Movements.

Offer a one-click alternative

For a reorderable list, provide Move up and Move down buttons, or let a user select an item and then choose a destination. These approaches let someone complete the same task with a single pointer and no drag motion. WAI describes examples in technique G219.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Support keyboard and assistive technology users

Ensure every action has a keyboard-accessible control as well as the non-drag pointer path. Make the action and its result understandable to assistive technology, and keep focus useful after a move—for example, retain focus on the moved item or its associated control. A drag-only feature is not made accessible merely by adding keyboard support if the separate single-pointer alternative is still absent.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose native drag and drop or a custom interaction

Native HTML drag and drop is a direct fit when the browser’s drag event model matches the task, such as accepting files or moving items between in-page targets. For sortable boards or touch-oriented interfaces, decide based on the devices and input methods the feature must support; the cited standards explain native behavior and accessibility criteria but do not establish that one implementation approach is universally best.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
  • Check whether the required interaction works for the intended mouse, touch, and keyboard users.
  • Plan a single-pointer alternative that does not require dragging.
  • Decide how drop positioning and visual feedback should behave.
  • Connect the gesture to application state and validate allowed moves.

Or skip the browser setup

If your goal is to capture a page while working on a JavaScript implementation or documenting its behavior, ScreenshotNeo provides a screenshot API and MCP server. A single GET request can return a screenshot or PDF. Its capture can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses report the page verdict and billing status. AI agents can use its MCP server tools: take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000. See ScreenshotNeo and the API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Replace YOUR_API_KEY with your key and change the target URL as needed. Sign up for 1,000 free screenshots a month, with no card required.

Troubleshoot common problems

Symptom Likely cause Fix
The drop handler never runs. The target has not opted into accepting drops, or the handler is attached to a different element than the event reaches. On eligible targets, call event.preventDefault() in dragover; use event delegation or attach handlers to the actual target.
The cursor indicates a drop, but nothing moves. The browser reports an interaction; it does not update application data for you. Read the expected payload in drop, validate it, update the model, and render or persist the new state.
getData() returns an empty string or an unexpected value. The source and target may use different data types, the source did not set data, or the payload is not the expected text. Set a consistent type in dragstart; read that same type in drop; reject missing or invalid IDs.
An item disappears, duplicates, or returns after rendering. The DOM was manipulated without making the corresponding application-state change, or the move logic did not distinguish source and destination. Move the record in the model, handle same-list drops deliberately, and render from the updated state.
Temporary highlight or drag state remains after cancellation. Cleanup was tied only to the successful drop path. Clear source-side temporary state in dragend, which also runs for canceled drags.
Users cannot complete the operation without dragging. The interface offers no equivalent single-pointer path. Add controls such as Move up/Move down or item selection followed by destination selection, and make the controls keyboard accessible.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.