Drag and Drop

Method of easily dragging and dropping elements on a page, requiring minimal JavaScript.

Spec https://html.spec.whatwg.org/multipage/interaction.html#dnd
Status WHATWG Living Standard
IE Edge Firefox Chrome Safari Opera
      98    
    95 97    
    94 96 TP  
11 (2,3) 95 93 95 15 80
10 (2,3) 94 92 94 14.1 79
9 (1,3) 93 91 93 14 78
8 (1,3) 92 90 92 13.1 77
Show all
7 (1,3) 91 89 91 13 76
6 (1,3) 90 88 90 12.1 75
5.5 (1,3) 89 87 89 12 74
  88 86 88 11.1 73
  87 85 87 11 72
  86 84 86 10.1 71
  85 83 85 10 70
  84 82 84 9.1 69
  83 81 83 9 68
  81 80 81 8 67
  80 79 80 7.1 66
  79 78 79 7 65
  18 77 78 6.1 64
  17 (2) 76 77 6 63
  16 (2) 75 76 5.1 62
  15 (2) 74 75 5 60
  14 (2) 73 74 4 58
  13 (2) 72 73 3.2 57
  12 (2) 71 72 3.1 56
    70 71   55
    69 70   54
    68 69   53
    67 68   52
    66 67   51
    65 66   50
    64 65   49
    63 64   48
    62 63   47
    61 62   46
    60 61   45
    59 60   44
    58 59   43
    57 58   42
    56 57   41
    55 56   40
    54 55   39
    53 54   38
    52 53   37
    51 52   36
    50 51   35
    49 50   34
    48 49   33
    47 48   32
    46 47   31
    45 46   30
    44 45   29
    43 44   28
    42 43   27
    41 42   26
    40 41   25
    39 40   24
    38 39   23
    37 38   22
    36 37   21
    35 36   20
    34 35   19
    33 34   18
    32 33   17
    31 32   16
    30 31   15
    29 30   12.1
    28 29   12
    27 28   11.6
    26 27   11.5
    25 26   11.1
    24 25   11
    23 24   10.6
    22 23   10.5
    21 22   10.0-10.1
    20 21   9.5-9.6
    19 20   9
    18 19    
    17 18    
    16 17    
    15 16    
    14 15    
    13 14    
    12 13    
    11 12    
    10 11    
    9 10    
    8 9    
    7 8    
    6 7    
    5 6    
    4 5    
    3.6 4    
    3.5      
    3      
    2      
Safari on iOS Opera Mini Android Browser Blackberry Browser Opera Mobile Android Chrome Android Firefox IE Mobile Android UC Browser Samsung Internet QQ Browser Baidu Browser KaiOS Browser
15 all 94 (4) 10 64 (4) 94 (4) 92 11 12.12 15.0 10.4 7.12 2.5
14.5-14.8   4.4.3-4.4.4 7 12.1     10   14.0      
14.0-14.4   4.4   12         13.0      
13.4-13.7   4.2-4.3   11.5         12.0      
Show all
13.3   4.1   11.1         11.1-11.2      
13.2   4   11         10.1      
13.0-13.1   3   10         9.2      
12.2-12.5   2.3             8.2      
12.0-12.1   2.2             7.2-7.4      
11.3-11.4   2.1             6.2-6.4      
11.0-11.2                 5.0-5.4      
10.3                 4      
10.0-10.2                        
9.3                        
9.0-9.2                        
8.1-8.4                        
8                        
7.0-7.1                        
6.0-6.1                        
5.0-5.1                        
4.2-4.3                        
4.0-4.1                        
3.2                        

Notes

dataTransfer.items only supported by Chrome.

Currently no browser supports the dropzone attribute.

Firefox supports any kind of DOM elements for .setDragImage. Chrome must have either an HTMLImageElement or any kind of DOM Element attached to the DOM _and within the viewport_ of the browser for .setDragImage.

  1. Partial support refers to no support for the dataTransfer.files or .types objects

  2. Partial support refers to not supporting .setDragImage

  3. Partial support refers to limited supported formats for dataTransfer.setData/getData.

  4. Not supported in Chromium browsers on Android 6 or older.

Bugs

  • Chrome strips out newlines from text/uri-list see bug

  • In Chrome, DataTransfer.addElement is not implemented. There is no other way to implement a draggable object which updates during the drag due to some other circumstances (e.g. changes color on a valid drop spot), as it is just a static image if addElement is not supported.

  • In Firefox, an element won't drag unless the dragstart handler sets dataTransfer data (even if it doesn't get retrieved). Test case

  • In Firefox, drag and drop does not work when the page is served as application/xhtml+xml Mozilla Bug #751778, Mozilla Bug #1106160

  • In Firefox, the dragstart event does not fire on button elements. This effectively disables drag and drop for button elements.

  • Safari doesn't implement the DragEvent interface. It adds a dataTransfer property to MouseEvent instead. See WebKit bug #103423.

  • In Safari 8, after setting event.dataTransfer.dropEffect, the value in the drop event is always 'none'

  • In IE9-10, the draggable attribute could be effectively applied for a and img elements. For div and span elements you should call element.dragDrop() to start drag event.

  • In IE9-11, using "text/plain" as the format for event.dataTransfer.setData and event.dataTransfer.getData reportedly does not work and causes a JS error. The format needs to be "text", which seems to work in all the mainstream browsers (Chrome, Safari, Firefox, IE9-11, Edge).

Resources

Data by caniuse.com
Licensed under the Creative Commons Attribution License v4.0.
https://caniuse.com/dragndrop