Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » HTML-CSS-PHP-JavaScript / JavaScript Codes » Preview Image Before Uploading In <input=”file”/> Field Using Pure JavaScript

Preview Image Before Uploading In <input=”file”/> Field Using Pure JavaScript

Image preview is a great feature for user to check their image before upload whether the correct image is going to upload or if the image looks nice or not etc. So in this tutorial, we will show you how to preview an image before upload using pure Vanilla JavaScript, HTML and CSS. You may also like to upload multiple images with preview using jQuery and PHP.

This is a simple frontend utility to help the file-upload process on your website. It is written in pure JavaScript, has no dependencies. You can check out the live demo. For the most part, browsers do a good job of handling image uploads. That being said – we find that the ability to show our users a preview of their upload can go a long way in increasing the confidence in their upload.


  1. Previe Image In A DIV Before Uploading.
  2. Generate Thumbnail On File Select.
  3. Light Weight.
  4. Pure JavaScrit.
  5. Cross Browser.
  6. Your code will be lightweight because it will have zero dependencies.
  7. Your website will perform better. You won’t need to load external scripts and stylesheets.
  8. You’ll have more control. You will have built the clock to behave exactly the way you want it to (rather than trying to bend a plugin to your will).
Recommended For You:
How To Add/Create A QR Code Reader On Your Website Using JavaScript?

How To Preview Image Before Uploading In <input=”file”> Field Using Pure JavaScript?

There are few easy and understandable steps to achieve your desired functionality using pure Vanilla JavaScript that we are gonna share below. Follow each step perfectly.


<input type="file" name="FileUpload" accept="image/*" id="ImgFileUpload"/>
<img id="previewImageFile" />


<script type="text/javascript">
/* Preview Image Before Uploading
----------------------------------------------- */
ImgFileUpload.onchange = evt => {
const [file] = ImgFileUpload.files
if (file) {
previewImageFile.src = URL.createObjectURL(file)


No need to customize it. Just copy paste.

Troubleshooting the Errors

Do it with concentration and patience. Check your alls steps and again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.

Final Words:

That’s all we have. We hope that you liked this article. If you have any problem with this code in your template then feel free to contact us with a full explanation of your problem. We will reply to you as time allows us or If you have any doubts and problems please comment below. We are happy to help you! If you liked this article, Don’t forget to share this with your friends so they can also take benefit from it and leave your precious feedback in our comment form below. Happy development, See you in the next article.

Recommended For You:
Get All Resources Like href And src From A WebPage Using PHP

You Like It, Please Share This Recipe With Your Friends Using...

Be the first to write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *