</> ConvertAtlas Developer Tools
Bootstrap 5 · Intermediate

Image Upload Preview

A file input that previews the selected image instantly.

Requires Bootstrap 5. Add the CDN tags below to your page (styles in <head>, scripts before </body>). The downloaded file already includes them.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<div class="card border-0 shadow-sm" style="max-width:320px"><div class="card-body text-center">
  <div class="rounded mx-auto mb-2 d-grid border" id="fpPrev" style="width:90px;height:90px;place-items:center;font-size:30px">🖼️</div>
  <input type="file" class="form-control form-control-sm" id="fpInput" accept="image/*">
  <small class="text-secondary d-block mt-1" id="fpName">No file chosen</small>
</div></div>
var input=document.getElementById('fpInput'),prev=document.getElementById('fpPrev'),name=document.getElementById('fpName');
input.addEventListener('change',function(){var f=input.files[0];if(!f)return;name.textContent=f.name;var r=new FileReader();r.onload=function(){prev.style.background='url('+r.result+') center/cover';prev.textContent=''};r.readAsDataURL(f)});
Free to use.This component uses Bootstrap 5 (linked above). Copy any file, or download a ready-to-open .html page with the CDN links already included.