EN
HTML - file input only for images
3 points
In this article, we would like to show you how to create file input only for images in HTML.
Quick solution:
xxxxxxxxxx
1
<input type="file" accept="image/*">
or:
xxxxxxxxxx
1
<input type="file" accept="image/png, image/gif, image/jpeg">
Hint: add more accepted MIME Types if needed.
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.
xxxxxxxxxx
1
2
<html>
3
<body>
4
<label>
5
<span>Choose a picture:</span>
6
<input type="file"
7
name="picture"
8
accept="image/png, image/gif, image/jpeg">
9
</label>
10
</body>
11
</html>
Note:
You can also specify the string meaning any image file in the following way:
image/*