Drag with constraints ― An tutorial of making an element draggable using Motion for React's drag prop. You can even set drag constraints by providing a ref to another element.
tutorialUpdated May 19, 2026

Creating the Project
Let's start the project by creating a Next.js application. We can do that by running npx create-next-app@latest client inside of a terminal.
Creating the 3 slides
Here I'll create 3 slides with a certain left position to randomize the layout.
I initialize a Lenis scroll to have a smooth scroll
I use an
overflow:hiddenon the parent to remove the horizontal scroll created by the long slides.
The slides all contain 3 phrases inside of them: