dropzone

The historical dropzone attribute was proposed to describe how an element should receive dragged files or text. It is obsolete and not a dependable way to implement drag and drop.

What you will learn

dropzone: distinguish three different things

For dropping files onto a page, distinguish the old HTML attribute, browser APIs (features JavaScript can use), and the JavaScript library so you can choose the right approach.

Start with a file input, without the dropzone attribute

The dropzone attribute has been removed from the current HTML standard. Adding it does not build file selection or an upload handler.

<label for="files">Choose files</label>
<input id="files" type="file" multiple>
<div id="drop-area">Drop files here</div>
<ul id="file-list"></ul>

Choose files or drop them

This demo lists file names and sizes. It does not read file contents or send files to a server.

Drop files in this box. On a phone or with a keyboard, use the file input above.

    No files selected. No files have been uploaded.

    Code to list dropped file names

    const input = document.querySelector("#files");
    const area = document.querySelector("#drop-area");
    const list = document.querySelector("#file-list");
    function showFiles(files) {
      list.replaceChildren();
      for (const file of files) {
        const li = document.createElement("li");
        li.textContent = file.name;
        list.appendChild(li);
      }
    }
    input.addEventListener("change", () => showFiles(input.files));
    area.addEventListener("dragover", (event) => {
      if (Array.from(event.dataTransfer.types).includes("Files")) {
        event.preventDefault();
      }
    });
    area.addEventListener("drop", (event) => {
      if (!event.dataTransfer.files.length) return;
      event.preventDefault();
      showFiles(event.dataTransfer.files);
    });

    Run this code after creating a box with id="drop-area" and a ul with id="file-list". Prevent the default dragover action for files, then inspect the files received in drop. Display names using textContent.

    Selection, preview, and upload are separate steps
    StepWhat happens
    SelectionThe browser has references to selected files. The demo stops here.
    PreviewThe browser reads content to show a preview, such as an image.
    UploadFiles are sent to a server and its response is checked. Listing names does not complete this step.

    If you mean the Dropzone library

    Dropzone is a JavaScript library that helps with previews and uploads. It is separate from the old dropzone attribute. You still need an upload endpoint and server-side checks for file type, size, and content.

    Historical syntax

    <!-- Historical example: do not rely on this. -->
    <div dropzone="copy file:image/png">Drop an image here</div>

    Browser support was inconsistent, and the attribute did not provide the complete keyboard, touch, validation, or upload behavior an application needs.

    Provide a file input first

    <label for="upload">Choose an image</label>
    <input id="upload" type="file" accept="image/*">

    A file input works without drag and drop and is available to keyboard and touch users. Add a visible drop area only as an enhancement, keeping the input as a reliable fallback.

    Modern drag-and-drop design

    Use dragover and drop events when appropriate, prevent default behavior only for the intended drop area, and announce the state clearly. Validate file type, size, and content on the server; client-side hints are not security controls.

    Related pages