Source Code

<div class="fd-wrap">
  <div class="fd-zone" id="fdZone">
    <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 16.5V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2.5"/><path d="M7 9l5-5 5 5"/><path d="M12 4v13"/></svg>
    <div class="fd-text">Drag files here or <span>click to browse</span></div>
    <input type="file" id="fdInput" multiple hidden />
  </div>
  <div class="fd-list" id="fdList"></div>
</div>

File Dropzone Uploader — Free HTML CSS JS Snippet

File Dropzone Uploader · Forms · Plain HTML, CSS & JS · Live preview

What's included

Features

Native HTML5 drag-and-drop with dragover, dragleave, and drop handlers plus a drag-active highlight state
Clicking the dropzone also opens a native file browser via a hidden multiple file input
Human-readable file size formatting (bytes converted to KB or MB)
Color-coded extension badges keyed off a lookup map, with a sensible default for unknown types
Per-file remove button that updates the in-memory file list and re-renders instantly
Both drag-drop and click-to-browse paths converge on one shared addFiles function
Fully self-contained vanilla JS with no external dependencies

About this UI Snippet

File Dropzone Uploader — Drag-and-Drop File Upload With Live File List

Screenshot of the File Dropzone Uploader snippet rendered live

This snippet is a file upload dropzone: a dashed-border drop area that accepts files either by clicking to browse or by dragging them straight from the desktop, backed by the native HTML5 drag-and-drop API and the File API.

Two ways in, one code path

Clicking the zone programmatically triggers a hidden <input type="file" multiple> via input.click(); its change event hands back a FileList. Dropping files fires the zone's drop handler, which reads event.dataTransfer.files — also a FileList. Both paths converge on a single addFiles() function so browsed and dropped files are handled identically.

Visual drag feedback

dragover calls preventDefault() (required for the drop to be allowed) and adds a .drag-active class that recolors the border, background, and icon; dragleave and drop both remove it, so the highlight only shows while a file is actually being dragged over the zone.

Per-file metadata rendering

Each accepted File object is pushed into a local files array. formatSize() converts the raw byte count into a human-readable KB/MB string, and extOf() pulls the extension off the filename to look up a color in the BADGE_COLORS map (falling back to a default indigo for unrecognized types) — giving each row a colored badge at a glance. A remove button on each row splices that file out of the array and re-renders the list.

Step by step

How to Use

  1. 1
    Load the snippetClick "File Dropzone Uploader" in the sidebar to load its HTML, CSS, and JS into the editor panels. The preview updates instantly.
  2. 2
    Edit the codeModify any panel — HTML, CSS, or JS. The preview refreshes as you type. Use Reset in each panel header to restore the original.
  3. 3
    Preview on devicesClick the Mobile (375px), Tablet (768px), or Desktop buttons in the preview header to check responsiveness.
  4. 4
    Export in your formatClick "HTML" to download a standalone file, "JSX" for a React component, "Tailwind" for a React + Tailwind CSS component, "Tailwind HTML" for a standalone HTML file with Tailwind CDN, "Vue" for a Vue 3 SFC with <template>/<script setup>/<style scoped>, or "Angular" for a standalone Angular .component.ts file. "Copy all" copies the full code to clipboard.
  5. 5
    Save your versionClick "Save as", type a name, and press Enter. Your snippet saves to IndexedDB and appears in the Saved tab.

Real-world uses

Common Use Cases

File upload forms
A ready-made dropzone for attachments, documents, or media uploads.
Admin panels and dashboards
Bulk file intake for CMS media libraries or document management tools.
Reference for the File and DataTransfer APIs
Shows how to read files identically whether dropped or selected via input.
Onboarding and import flows
A friendly first step for CSV imports, resume uploads, or asset intake.

Got questions?

Frequently Asked Questions

No, this snippet only handles client-side file selection and lists the chosen files with their metadata. Wire the addFiles function or the files array to an actual upload request (e.g. fetch with FormData) to send them somewhere.

The visible dropzone wraps a hidden <input type="file" multiple>. A click listener on the zone calls input.click() to programmatically open the native file picker, keeping the styled zone as the only visible control.

formatSize() checks the raw byte count: under 1024 bytes it shows bytes, under 1024*1024 it divides by 1024 for KB, and above that it divides by 1024*1024 for MB, each rounded to one decimal place.

extOf() extracts the lowercase extension from the filename, and that extension is looked up in the BADGE_COLORS map. Unmapped extensions fall back to a default indigo color so every file still gets a badge.