Skip to content

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.

Also known as: drag and drop upload, file upload zone, file dropzone, upload with progress bar, multiple file uploader

Drag and Drop File Upload live demo

Open in new tab

Bootstrap 6 code (HTML, CSS, JS)

A dark drag and drop file uploader built with Bootstrap 6. Files dropped on the dashed zone, or picked with "Browse files", appear in a list with a type icon, their size, a progress bar with the time left, and a remove button. Files that are too large or of the wrong type are rejected with a clear reason. Use it for project briefs, support attachments, CMS media or any form that accepts several files.

How it works

The root .dfu-root contains a .dfu-card with the drop zone .dfu-zone, the list .dfu-list and a <template class="dfu-row-template"> that every row is cloned from. The real input.dfu-input (with multiple and an accept list) sits inside the label.dfu-browse button. It is visually hidden but still focusable, so keyboard users tab to "Browse files" and press Enter or Space.

The zone listens to dragenter, dragover, dragleave and drop. A small depth counter keeps the .dfu-zone--over highlight steady while the pointer crosses child elements, and preventDefault() stops the browser from opening the dropped file. Clicking anywhere on the zone also opens the file dialog.

addFile() reads the extension and picks a Bootstrap Icon and color from the ICONS map. It checks the type against the input's accept list and the size against data-dfu-max-mb. Accepted files get a Bootstrap 6 .progress bar. startUpload() simulates the transfer at data-dfu-speed KB per second, updating the percentage, the transferred size and the seconds left. A finished bar switches from theme-accent to theme-success. Rejected rows get .dfu-row--error and the reason. removeEntry() stops the timer, removes the row, updates the count and total, and moves focus to the next remove button. The first rows come from SAMPLE_FILES, so the demo never starts empty.

Customization

  • data-dfu-max-mb on .dfu-card: the per-file size limit (25 MB by default). Update the badge text to match.
  • accept on .dfu-input: the allowed extensions. Validation reads this list, so there is one place to change.
  • ICONS in script.js: map more extensions to Bootstrap Icons and tone classes such as .dfu-type--pdf.
  • Delete the SAMPLE_FILES array (and its forEach call) in production.
  • Replace the timer in startUpload() with an XMLHttpRequest and its upload.onprogress event, calling setProgress(entry, percent).
  • --dfu-accent, --dfu-card and --dfu-row on .dfu-root: change the violet accent and the dark surfaces.
  • Remove multiple from the input to accept a single file.

Use cases

  • Document portals: users drop files into a zone and see each one listed with an icon and size
  • Application and support forms: type and size validation rejects files that are not allowed
  • Cloud storage and CMS tools: progress bars show the state of every upload
  • Dashboards: remove buttons let users drop a file before sending

Accessibility

The file input stays in the tab order, and its label shows a focus outline through :focus-within. Each progress bar has role="progressbar", aria-valuenow and a label with the file name. Each remove button's aria-label names its file. A visually hidden aria-live="polite" region announces added, uploaded, rejected and removed files. The zone's scale effect is turned off under prefers-reduced-motion.

Bootstrap 6 notes

Buttons use btn-solid theme-accent and btn-text theme-secondary btn-icon instead of btn-primary and btn-link. Progress bars are colored with theme-* classes, and badges use badge-subtle / badge-outline with a theme. Built on Bootstrap 6.0.0-alpha.1, so class names can still change. Icons come from Bootstrap Icons.

Drag and Drop File Upload at a glance

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

Questions about this template

Can I use the Drag and Drop File Upload 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 Bootstrap 6 and Bootstrap Icons 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):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/css/bootstrap.min.css">
  • <script type="module" src="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">

Built for Bootstrap 6.0.0-alpha.1. Bootstrap 6 ships as an ES module, so its script and this component's JavaScript load with type="module". Alpha releases can still change before the stable version.

Drag and Drop File Upload – free Bootstrap 6 file upload template
Drag and Drop File Upload · free Bootstrap 6 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.

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.

File Upload Dropzone – free Tailwind CSS file upload template

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.