Exploring the Drag and Drop Function in HTML5 | HTML Goodies

Exploring the Drag and Drop Function in HTML5

Written By
Kashif Nazir
Kashif Nazir
Nov 11, 2015
4 minute read

Though, it is interesting that in the earlier versions of HTML, this element was not included. Drag and drop functionality in HTML5 can now be used in making diagrams, managing files and just about every other standard drag and drop functionality. In HTML5 this native drag and drop functionality is not limited to the mouse events but rather it is more advanced when it is integrated in managing files on the developer’s end. Drag and drop element works differently in HTML5.

 

There are many drawbacks and short comings in using this functionality in other development and code versions. A notable drawback is that ad hoc drag and drop functionality cannot be mixed with other content on the same web page unless both commands are integrated into your code first. This random mixing will lead to havoc on the web page. Another, major drawback of ad hoc drag and drop is that it does not allow the user to use it on the desktop and does not work in Windows.  In HTML5 each of these problems have been taken care of providing a problem free framework for drag and drop API as well as faster web apps. HTML5 drag and drop functionality resembles the Java API and MFC. Developers who have already worked with these APIs can easily understand the drag and drop API in HTML5.

 

Draggable=’true’

Dragging an object in HTML5 can be done following simple and easy steps. Draggable ‘true’ attribute is used to drag the required content. Just about everything is drag able in HTML5, this includes links images and files. Dragging an image attribute will look like this

 

When we set an image or link as drag-able, we have to put its URL in the code to allow this feature. The text content can be integrated in to the code itself. But the links, images are by default and can be dragged in HTML5. To make other elements drag-able in HTML5 through the same ‘true’ attribute. But the one thing to be done is adding a listener in the ‘dragstart’. The following example explains how to include other data to be dragged.

< div draggable= ”true”ondragstart=“event.dataTransfer.setData(‘text/plain’’, ‘ This is the content that is being dragged”>

This is the content that is being dragged .

 

In the above example to make the element drag able ‘true’ attribute is used. If you want to make these elements not drag-able then ‘false’ value is used to disable the drag function.

But this is not the case with the XUL elements. They are all drag-able and there is no need to use drag-able attribute.

HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.