← Todos os snippets
Área de upload (arrastar e soltar)
Zona tracejada que destaca ao arrastar e mostra o nome do arquivo.
Preview ao vivo
Código completo
<style>*{box-sizing:border-box}body{font-family:system-ui,sans-serif;margin:0;padding:24px;background:#0e1013;color:#e8eaec;line-height:1.5}a{color:inherit;text-decoration:none}img{max-width:100%;display:block}
.up{max-width:420px;margin:24px auto;border:2px dashed #3a3f45;border-radius:16px;padding:36px 20px;text-align:center;cursor:pointer;transition:.2s}.up.on,.up:hover{border-color:#2f6fed;background:#2f6fed12}.up b{color:#2f6fed}input{display:none}#nome{margin-top:10px;font-size:13px;color:#1f9c7a}
</style>
<label class="up" id="z"><div style="font-size:34px">⬆</div><p><b>Clique</b> ou arraste um arquivo aqui</p><input type="file" id="f"><div id="nome"></div></label>
<script>
const z=document.getElementById('z'),f=document.getElementById('f'),n=document.getElementById('nome');['dragenter','dragover'].forEach(e=>z.addEventListener(e,x=>{x.preventDefault();z.classList.add('on')}));['dragleave','drop'].forEach(e=>z.addEventListener(e,()=>z.classList.remove('on')));z.addEventListener('drop',x=>{x.preventDefault();f.files=x.dataTransfer.files;n.textContent=f.files[0]?.name});f.onchange=()=>n.textContent=f.files[0]?.name
</script>