Skip to main content
Collision detection determines when a dragged item is over a droppable target. dnd-kit uses a flexible, priority-based collision system that supports multiple detection algorithms.

Overview

The collision detection system:
  • Runs during drag operations to detect overlaps
  • Supports multiple collision algorithms
  • Uses priority-based resolution for overlapping collisions
  • Allows per-droppable collision configuration
  • Provides collision data for custom behaviors

Collision observer

The CollisionObserver manages collision detection:
The observer automatically recomputes collisions when:
  • The drag position changes
  • Droppable shapes change (resize, scroll, etc.)
  • Droppables are added or removed

Collision types

Collision detectors

Collision detectors are functions that determine if a collision occurred:

Built-in detectors

dnd-kit provides several collision detection algorithms: Pointer intersection:
Detects when the pointer is over the droppable. Best for precise targeting. Shape intersection:
Detects when the draggable’s bounding rectangle overlaps the droppable. Returns the overlap area as the collision value. Center of mass:
Detects when the center point of the draggable is over the droppable. Useful for card-like interfaces. Closest corners:
Computes the distance between the draggable’s corners and the droppable’s corners. Returns the minimum distance as the collision value.

Collision priority

When multiple droppables collide, priority determines the winner:
Set priority per droppable:
Or use custom numeric priorities:

Priority resolution

Collisions are sorted by:
  1. Priority (descending): Higher priority wins
  2. Value (descending): Higher value wins if priorities are equal
  3. Order: First in the list wins if both are equal

Computing collisions

The CollisionObserver computes collisions automatically, but you can also compute them manually:

Implementation details

Custom collision detectors

You can create custom collision detection algorithms:

Distance-based detector example

Collision notifier

The CollisionNotifier is a core plugin that updates the drag target:
This plugin is automatically included in the abstract manager and updates dragOperation.target based on the highest-priority collision.

Using collision data

Access collision information during drag operations:

Acceptance rules

Droppables can filter which draggables they accept:
The collision observer respects acceptance rules:
See Draggables and Droppables for more on acceptance rules.

Force updates

You can force collision recomputation:
This is useful when:
  • Droppable positions change externally
  • You add/remove droppables programmatically
  • You need to trigger a manual update

Performance considerations

Collision detection runs frequently: The observer recomputes collisions on every position change during a drag. Keep collision detectors lightweight.
Caching: The observer caches collision results and only recomputes when position changes. Accessing the same position multiple times uses the cache.
Avoid heavy computations: Don’t perform expensive calculations in collision detectors. Use simple geometric tests when possible.

Choosing a detector

Use this guide to choose the right detector:

Droppables

Droppable configuration

Custom detectors

Build custom algorithms

Collision algorithms

API reference

Geometry utilities

Spatial calculations