Skip to main content

Overview

Modifiers transform the movement of draggable elements during drag operations. They can restrict movement to axes or boundaries, adjust positioning, or implement custom movement logic. This guide covers how to use modifiers in React with hooks like useDraggable and useSortable.

Restricting to a container element

Use the RestrictToElement modifier from @dnd-kit/dom/modifiers to constrain dragging within a container. Pass the container’s DOM element via a React ref:
Pass a function (element: () => container.current) rather than the ref’s current value (element: container.current). The function is evaluated when a drag starts, after the ref is populated. Passing container.current directly captures null on the initial render, and the modifier silently applies no restriction.
The function form also receives the current drag operation, which is useful when you need dynamic container references:

Restricting to the window

Use RestrictToWindow from @dnd-kit/dom/modifiers to prevent dragging outside the browser viewport:

Restricting to an axis

Use RestrictToVerticalAxis or RestrictToHorizontalAxis from @dnd-kit/abstract/modifiers to lock movement to a single axis:

Snapping to a grid

Use the SnapModifier from @dnd-kit/abstract/modifiers to snap movement to a grid:
The size option accepts a number for uniform snapping, or an object with separate x and y values:

Combining modifiers

You can combine multiple modifiers. They are applied in order:

Global vs. per-draggable modifiers

Modifiers can be set globally on the DragDropProvider to apply to all draggable elements, or on individual hooks for per-element control.

Global modifiers

Per-draggable modifiers

Per-draggable modifiers take precedence over global modifiers:
For the full list of built-in modifiers and how to create custom modifiers, see the core Modifiers documentation.