Skip to content

File Upload Dropzone

Tailwind CSS drag-and-drop file upload zone with keyboard support, type and size validation, a file list and per-file progress bars.

Also known as: drag and drop upload, file dropzone, file upload area, upload with progress bar, drop files here

File Upload Dropzone live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A drag-and-drop file upload dropzone built with Tailwind CSS and vanilla JavaScript. Users can drop files onto the dashed area or pick them with the native file dialog, and every file appears in a list with its own progress bar, size and remove button. It fits attachment fields, project settings, support forms and media libraries.

How it works

The root is .tfd-dropzone. The drop area is a label (.tfd-zone, marked data-tfd-zone) that wraps a visually hidden input type="file" with multiple and an accept list. Because the input is only hidden with sr-only, clicking the label or pressing Enter/Space on the focused input opens the file dialog, and has-[input:focus-visible] draws a focus ring around the whole zone.

The script listens for dragenter, dragover, dragleave and drop on the zone. A drag counter keeps the tfd-zone--active highlight from flickering while the pointer moves over child elements. Dropped or selected files are passed to addFile(), which clones the row from the <template data-tfd-template>, fills in the extension badge, name and size, and appends it to data-tfd-list.

Each file is checked against the input's accept attribute and the size limit. Invalid files get data-state="error" and a red message. Valid files run through simulateUpload(), which raises the bar width and aria-valuenow in steps and then sets data-state="done". The row colors switch with group-data-[state=done] and group-data-[state=error] variants, so no extra CSS classes are toggled. Remove buttons cancel the timer, delete the row and update the counter in data-tfd-summary.

Customization

  • data-tfd-max-mb="10" on .tfd-dropzone: set the maximum file size in megabytes; larger files show "Larger than 10.0 MB". Update the "Max 10 MB" badge to match.
  • accept on #tfd-input: list the allowed extensions or MIME types (.pdf,.png or image/*); dropped files are validated against the same rule.
  • simulateUpload() in script.js: replace the timer with fetch() or an XMLHttpRequest that reports upload.onprogress to setProgress().
  • bg-indigo-500 on .tfd-bar and the indigo classes on the zone: swap for sky, violet or emerald to rebrand.
  • .tfd-zone.tfd-zone--active in style.css: change the border and background shown while files are dragged over.
  • Remove multiple from the input to accept one file at a time.

Use cases

  • Attachment fields: users drop files or pick them with the native dialog and see each in a list
  • Project settings: upload documents with type and size validation before sending
  • Support forms: per-file progress bars and remove buttons show the state of every attachment
  • Media libraries: keyboard users can open the file picker from the dashed drop area

Accessibility

The hidden input stays in the tab order and is described by the format hint through aria-describedby. Each row has a role="progressbar" with aria-valuemin, aria-valuemax, aria-valuenow and a file-specific aria-label. Remove buttons are labelled "Remove file name", and focus moves to the next row (or back to the input) after a removal. Completed uploads, errors and removals are announced through a role="status" live region. Animations in style.css and the bar transitions are turned off under prefers-reduced-motion: reduce.

Usage notes

For several dropzones on one page, wrap each in its own .tfd-dropzone and give each input a unique id and matching for. The sample row shows the completed state and can be deleted.

File Upload Dropzone at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile
Category
File Uploads
License
Free for personal and commercial use

Questions about this template

Can I use the File Upload Dropzone code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

File Upload Dropzone – free Tailwind CSS file upload template
File Upload Dropzone · free Tailwind CSS file upload template

More File Uploads

Image Upload with Preview – free Bootstrap 6 file upload template

Image Upload with Preview

Bootstrap 6 image uploader that shows thumbnails before upload, with a cover photo star, alt text Dialog, remove buttons, size checks and per-photo progress.

Drag and Drop File Upload – free Bootstrap 6 file upload template

Drag and Drop File Upload

Dark Bootstrap 6 drag and drop upload zone with a file list, type icons, file sizes, progress bars, size and type validation and remove buttons.

Profile Photo Upload with Preview – free Tailwind CSS file upload template

Profile Photo Upload with Preview

Tailwind CSS avatar uploader with drag and drop, a circular live preview, zoom slider, size previews, file validation and a simulated save.

Image Upload with Preview – free Bootstrap 5 file upload template

Image Upload with Preview

Bootstrap 5 drag-and-drop image uploader with thumbnail previews, remove buttons, type and size validation and simulated upload progress.