10 CSS & JavaScript Snippets for Creating Drag-and-Drop UIs


Drag-and-drop has been with us for decades. It helps us to get things done on desktops, mobile apps and operating systems. There’s both a simplicity and intuitiveness that make them one of the most universal UI features.

So it’s no wonder that drag-and-drop has invaded the web over the past few years. From uploading files in Dropbox to sorting our Trello boards – its usefulness has been proven repeatedly.

There are a number of creative ways we can implement these interfaces into our own designs. Let’s take a look at ten unique examples of drag-and-drop UI:

Learn the Basics

Before you can go really in-depth with implementing drag-and-drop, it’s important to learn some fundamentals. That’s where this simple snippet that utilizes Angular can come in handy. It’s a basic exercise in dragging a square element from one side of the screen to the other. An alert pops up when you’re finished. Nothing fancy, but it could be useful for grasping the concepts involved.

See the Pen Angular Drag &Drop by Ben Parker

Draggable Panels

Speaking of Trello, the task management tracker’s implementation of drag-and-drop is incredibly useful. Here’s an example that stays pretty faithful to what makes Trello so cool. You can drag panels from column to column, and there’s an awesome color-changing effect when something is moved to a new spot.

See the Pen Kanban Drag and Drop by Ettrics

Build Your Own Kaleidoscope?

This is example is both quite breathtaking and a bit trippy. It utilizes HTML5 Canvas and some JavaScript to create a movement-aware kaleidoscope. But wait, there’s more! You can also drag an image into the UI, thus changing the image displayed within the kaleidoscope. All I can say is, “far out.”

See the Pen Kaleidoscope (Drag &Drop) by Justin Windle

Drag a Simple Page Element

On our desktop or laptop computers, we sometimes want to move a specific element off to the side. It’s still in view – but out of the way of other, more important items. That’s exactly what this dead-simple jQuery button does for the web. Move it to anywhere on the screen for later viewing.

See the Pen Grab &Drag by Ben Kalsky

HTML5 Drag-and-Drop API

Did you know that HTML5 has its own drag-and-drop API? I ask only because I had no clue. Here, it’s combined with some JavaScript to enable the swapping of squares. While this is a simple example, it shows the potential of tapping into the API.

See the Pen Drag and Drop HTML5 by Acauã Montiel

Form Builder

We often see drag-and-drop used with forms. A WordPress Plugin like Gravity Forms comes to mind, where fields can be added and repositioned quite intuitively. Here we have a form builder UI that uses HTML5 and Angular.js.

See the Pen Angular Drag-Drop FormBuilder by Lam Phuoc Thinh

Scalable Pixel Art

Adding images via drag-and-drop is quite common. But, like the kaleidoscope above, this snippet provides a unique use case. You can drag an image into a specified div, and it creates CSS-based pixel art that can be scaled to up to 20x the original size. It also outputs CSS code to paste into your project – a good representation of how useful this UI can be.

See the Pen Drag and Drop Pixel Art Generator by Will Boyd

Easily Add Events

The ability to rearrange data is a prime use of dragging. This calendar example shows how we can use the UI to place events on specific dates and even switch between dates, if necessary. Furthermore, it shows how implementing drag-and-drop can take the pain points out of common tasks.

See the Pen Drag an event from FullCalendar to trash or back to external list by Subodh Ghulaxe

It’s a Knockout

The file upload field has been around for years. But drag-and-drop makes it so much more user-friendly. Here we have a couple of example fields using Knockout.js. The first allows for dragging a single file, the other allowing for multiple uploads. But both offer a preview of the file, adding further visual confirmation to the UI.

See the Pen Knockout JS HTML5 File Bindings with upload preview and drag and drop by Safraz Razik

Moving From a Scrollable Container

This is one we don’t see very often. The scrollable container at the top of this snippet contains boxes that can be moved to another div down below. It shows that a scrollable interface can be quite usable in this type of scenario.

See the Pen Dragging Clones by Blake Bowen

Dragging You Towards a Better UI

There are several ways that a drag-and-drop UI can benefit the user-friendliness of your website. Hopefully, the examples above will provide you with some inspiration regarding how you can use this familiar feature to enhance your own projects.

Related Topics

This page may contain affiliate links. At no extra cost to you, we may earn a commission from any purchase via the links on our site. You can read our Disclosure Policy at any time.