Skip to main content

Overview

The vanilla JavaScript adapter provides framework-agnostic drag and drop functionality through the core @dnd-kit/dom package. Use this when you’re building without a framework or want direct control over the DOM.

Installation

Install the core packages:

Getting Started

1

Create a DragDropManager

Initialize the drag and drop manager that coordinates all interactions:
2

Create draggable elements

Register elements as draggable:
3

Create droppable zones

Register elements as drop targets:
4

Listen to drag events

Subscribe to drag and drop events:

Complete Example

Here’s a full working example:

Sortable Lists

Create sortable lists using the Sortable class:

Advanced Features

Custom Drag Handles

Specify a different element as the drag handle:

Modifiers

Apply modifiers to constrain or modify drag behavior:

Sensors

Customize how drag operations are initiated:

Type Safety

Add type safety to your drag and drop data:

Cleanup

Always destroy the manager when you’re done:

Best Practices

  • Initialize once: Create your DragDropManager instance once and reuse it
  • Clean up: Always call destroy() to prevent memory leaks
  • Use data property: Store metadata on draggables for easier event handling
  • Batch updates: Apply multiple changes together for better performance
  • Element references: Keep element references up to date when DOM changes

Next Steps

Sensors

Configure how drag operations are initiated

Modifiers

Constrain and modify drag behavior

Collision Detection

Control how droppable targets are detected

Events

Listen to all available drag and drop events