Languages
[Edit]
EN

HTML - file input only for images

3 points
Created by:
Kevin
797

In this article, we would like to show you how to create file input only for images in HTML.

Quick solution:

or:

Hint: add more accepted MIME Types if needed.

 

Practical example

Edit

In this example, we create file input using type="file" attribute. To make it allow only images, we set accept attribute to the types that file input should accept.

Note:

You can also specify the string meaning any image file in the following way:

  • image/*

 

See also

Edit
  1. image content-type list (mime types)

References

Edit
  1. <input type="file"> - HTML | MDN
  2. Common MIME types - HTTP | MDN

Alternative titles

  1. HTML - file input with images filter only
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join