The accept
attribute on an input tag specifies the acceptable file types that can be uploaded.
This only applies to input controls of type file
.
An accept
attribute on an <input> element of type file.
This file selector let the user select only image files.
<form action="/tutorial/fileupload.html" enctype="multipart/form-data">
<label for="image">Select image to upload</label><br />
<input type="file" id="image" name="image" accept="image/*"><br /><br />
<input type="submit">
</form>
The accept
attribute specifies which file format or media type the input element accepts.
This attribute is only valid with the file input type.
The accept
attribute only filters the file selection. It does not validate the format during form submission.
<input type="file" accept="file-extension | audio/* | video/* | image/* | media-type">
Value | Description |
---|---|
file-extension | File extension(s), such as, .gif, .jpg, .png, .doc, and others. |
audio/* | Accepts all sound files. |
video/* | Accepts all video files. |
image/* | Accepts all image files. |
media-type | A valid media type, without parameters. |
Here is when accept
support started for each browser:
Chrome
|
26.0 | Mar 2013 |
Firefox
|
37.0 | Mar 2015 |
IE/Edge
|
10.0 | Sep 2012 |
Opera
|
15.0 | May 2013 |
Safari
|
11.1 | Mar 2018 |
Back to <input>