image upload with preview

How we can create a custom file input to upload and preview images? Solution: See this Image Upload With Preview Using jQuery and CSS, Custom File Input Image.

Previously I have shared few file input programs, but this program is about preview the selected image. Basically, HTML comes with many types of inputs like text, password, email, etc and all these inputs are for forms. There is input type “file” which is for uploading a file, we just have to put <input type="file"> tag to creating this. By default, it comes with basic styles but we can customize its style and function using JS and CSS.

Today you will learn to create Custom File Input Image preview. Basically, there is a dummy image placeholder and a file input below the image. When you will click on the input for uploading an image, the file explorer will open. After selecting an image, the dummy placeholder will replace it with the selected image. Also, there is a little text animation while image loading.

So, Today I am sharing Image Upload With Preview Using jQuery and CSS. There I have placed call and ID names in the elements and styled that using CSS. And all the functions are based on jQuery, there I have used this library to fewer codes and save time. This is a complete program, you can use this on select profile pic upload photo section on your website.

If you are thinking now how this image upload and preview program actually is, then see the preview given below.

Preview Of Custom File Input For IMG Uploading

See this video preview to getting an idea of how this custom file input looks like.

Live Demo

Now you can see this visually, also you can see it live by pressing the button given above. If you like this, then get the source code of its.

You May Also Like:

Image Upload With Preview Using jQuery and CSS Source Code

Before sharing source code, let’s talk about it. First I have created a main div named container as always and placed all elements inside it. Inside the main div, I have created a form and placed a div for loading text, another div with an IMG tag for preview, and a file input with label inside it. I have placed ID and class names inside every tag for styling and functioning. Also in the HTML file, I have linked external files like CSS, JS, and jQuery CDN.

Now using CSS I have placed all the elements in the right place, as you can see in the preview. There is a bounce effect when program loading and on refresh which is based on a library. WIth CSS first I have done basics works,  gave elements values like size, position, margin, padding, etc. I have used CSS @Keyframe command to creating the blink text animation when image loading.

jQuery handling here the image upload and preview feature in this program. Fetched the elements using ID name $("#IDname") method and created functions on click using .on('click',function() ) command. Also, jQuery showing and hiding the alert or blinking text when loading by adding and removing class names.

Left all other things you will understand after getting the codes, I can’t explain all in writing. For creating this program you have to create 3 files. First file for HTML, second file for CSS, and the third file for JavaScript. Follow the steps to creating this without any trouble.

index.html

Create an HTML file named ‘index.html‘ and put these codes given below.

style.css

Now create a CSS file named ‘style.css‘ and put these codes given here.

function.js

The final step, create a JavaScript file named ‘function.js‘ and put the codes.

That’s It. Now you have successfully created Image Upload With Preview Using jQuery and CSS, Custom File Input Image program. If you have any doubt or question comment down below.

Thanks For Visiting, Keep Visiting.

8 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here