Chrome Extension

Allow image file only for input type file in HTML

<input type="file" accept="image/*" />

<input type="file" accept="image/jpeg,image/gif,image/x-png" />

Do you know, you can create and search your own code snippets on Devsheet. Store your code on cloud using devsheet and search using its chrome extension. Is it look cool?

This will prevent to browse the file that is not an image.

If you are using input[type="file"] HTML element then you may require to accept specific files like image/video. The code snippet can be used to browse only image files in your website. If you want to accept all files you can use accept="image/*" or if have specific extensions of image files that can only be accepted, you can use accept="image/jpeg,image/gif,image/x-png"

In the above image you can see that only image files are enabled and all the other files are faded out means disabled and you can not select them from the window. I am accepting all images in this example.

Search Index Data (The code snippet can also be found with below search text)

Accept image only in input[type="file"] HTML
Was this helpful?
Never leave your website again in search of code snippets by installing our chrome extension.