html drag and drop list

How we can create a draggable list using HTML CSS JavaScript? Solution: See this HTML Drag and Drop List With JavaScript, Draggable List With Add Items.

Previously I have shared a to-do list using JavaScript, it is also like that but we can drag and drop list items in this program. This program is an example of how HTML 5 can drag and drop items with JS. We used draggable items in frontend for users and backend also, that help us to place items as our requirement.

Today you will learn to create a Draggable List With Add Items Program, a kind of To-Do list. Basically, this a to-do list type program and you also can shift up and down items with drag and drop. You have to hold the mouse click or touch tap and drop into over other items to shift them. You also can add items in the list by type and click on add icon.

So, Today I am sharing HTML Drag and Drop List With JavaScript. HTML 5 comes with a separate attribute for define the element draggable or not, and with JS we can create a fully functional program for drag and drop. There I have used pure JavaScript, not any library or framework had used. You can use this program on your project, this will be very useful for you.

If you are thinking now how this drag and drop program actually is, then see the preview given below.

Preview Of Draggable List With Add Items

See this video preview to getting an idea of how this to-do list looks like.

Live Demo

Now you can see this visually, you also can see it live by pressing the button given above. If you like this, then get the source code of its.

You May Also Like:

HTML Drag and Drop List With JavaScript Source Code

Before sharing source code, let’s talk about it. First, I have created a text input with a placeholder and a span for add icon using HTML. After that, I have created a list with a class named and HTML draggable element. Basically, HTML draggable="true" attribute defines the item draggable or not (info), That’s why I have placed this attribute.

Now using CSS I have placed all the elements in the right place, as you can see in the preview. For placing the add icon, I have used + sign and placed inside the span and on hover rotating it by 180 degrees. When you will hover on the list items you will see ‘drag me‘ text on the right side of tab for creating that, I have used CSS :after command and added content.

JavaScript handling the main features of the program, add items like a to-do list and a draggable function. I have fetched elements using the JS document.querySelector command. And created the drag and drop feature using commands: dragstart, drageneter, dragover, dragleave, drop, dragend.

Left all other things you will understand after getting the codes, I can’t explain all in writing. For creating this program you have to create 3 files for that. First for HTML, second for CSS, and the third for JavaScript. Follow the steps to creating this without any error.

index.html

Create an HTML file named ‘index.html‘ and put these codes given below.

style.css

Now create a CSS file named ‘style.css‘ and put these codes given here.

function.js

The final step, create a JavaScript file named ‘function.js‘ and put the codes.

That’s It. Now you have successfully created HTML Drag and Drop List With JavaScript, Draggable List With Add Items. If you have any doubt or question comment down below.

Thanks For Visiting, Keep Visiting.

5 COMMENTS

  1. Quite new to Javascript as well as CSS, but tried this out and works great, except…. How to actually submit the UL and save the sorted order !?
    Am I missing something obvious here….

  2. How could you use this with items created dynamically with a JS loop? I’ve tried but keep getting “Cannot read properties of null (reading ‘addEventListener’)” error.

LEAVE A REPLY

Please enter your comment!
Please enter your name here