Skip to content

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.

Also known as: image uploader with preview, photo upload thumbnails, multiple image upload, cover photo selector, image gallery uploader

Image Upload with Preview live demo

Open in new tab

Bootstrap 6 code (HTML, CSS, JS)

A Bootstrap 6 image uploader that shows every chosen photo as a thumbnail before anything is sent. You can star one photo as the cover, open a Bootstrap 6 Dialog to write alt text, remove photos, and then upload them all with a progress bar on each tile. It suits trip stories, listings and galleries.

How it works

The root .iup-root holds a .iup-card with a slot meter, an error alert, the .iup-grid list and a footer with the upload button. The first grid item is .iup-add-tile, a dashed <label> around a visually hidden input.iup-input (accept="image/*" multiple). Every photo tile is cloned from <template class="iup-tile-template">.

When files are picked or dropped on the grid, addFiles() skips anything that is not an image, is larger than data-iup-max-mb, or would exceed data-iup-max. The skipped names are listed in the .iup-error alert. Accepted files get a local preview through URL.createObjectURL(), so nothing leaves the browser yet. refresh() updates the "5 / 12 photos" meter, hides the add tile when the grid is full, and keeps one tile marked .iup-tile--cover.

Each tile has three buttons. The star calls setCover() and uses aria-pressed. The pencil opens the <dialog class="dialog iup-dialog"> with Dialog.getOrCreateInstance(...).show(), showing a larger preview, an alt text textarea and a Bootstrap 6 .switch for the cover. The trash button removes the tile. The upload button adds .iup-tile--uploading to every pending tile, fills its .progress bar on a timer, and marks it .iup-tile--done with a green check.

The starting photos come from Unsplash through SAMPLE_PHOTOS; replace them with your own images.

Customization

  • data-iup-max and data-iup-max-mb on .iup-card: the photo limit (12) and the size limit per file (10 MB).
  • --iup-accent on .iup-root: the coral used by the cover ring, the add tile and the focus outline. The buttons, badge and bars use theme-danger, so swap that class too.
  • --iup-radius on .iup-root: the corner radius of every tile.
  • grid-template-columns in .iup-grid: two columns on phones and three from 640px.
  • Replace the timer in the .iup-upload click handler with one fetch() per photo, sending the original File, its alt text and a cover flag.

Use cases

  • Property and product listings: sellers upload photos and mark one as the cover with a star
  • Profile and portfolio pages: thumbnails appear before the upload so users can check the images
  • Accessibility-aware CMS forms: an alt text dialog lets people describe each photo
  • Media managers: size checks and per-photo progress show which images are ready

Accessibility

The file input stays keyboard focusable, and its tile shows a focus ring through :focus-within. Every tile button has an aria-label that names the photo. The cover star reports its state with aria-pressed. The Dialog is labelled by its title, traps focus while open, closes with Escape, and returns focus to the pencil button. Rejected files are listed in a role="alert" box, and a polite live region announces additions, removals and finished uploads.

Bootstrap 6 notes

The details editor is a native <dialog class="dialog"> with data-bs-dismiss="dialog" instead of Bootstrap 5's .modal. style.css includes dialog.dialog:not([open]) { position: fixed; } so the closed dialog adds no blank space. The cover toggle is the new .switch, buttons use btn-solid theme-inverse btn-icon, and the progress bars are colored with theme-danger. Built on 6.0.0-alpha.1, so the APIs can still change.

Image Upload with Preview 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
Category
File Uploads
License
Free for personal and commercial use

Questions about this template

Can I use the Image Upload with Preview 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.

Image Upload with Preview – free Bootstrap 6 file upload template
Image Upload with Preview · free Bootstrap 6 file upload template

More File Uploads

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.

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.