HTML <input> accept Attribute
Definition and Usage
accept
This attribute defines a filter for the file types that the user can select from the file input dialog.
accept
This attribute specifies the file types that can be submitted through file upload.
Note:accept
The attribute can only be used with <input type="file"> Used together.
Tip:Do not use this attribute as a validation tool. File upload validation should be performed on the server side.
Example
Specify the file types that the user can select from the file input dialog:
<form action="/action_page.php"> <label for="img">Please select an image:</label> <input type="file" id="img" name="img" accept="image/*"> <input type="submit"> </form>
Syntax
<input accept="file_extension|audio/*|video/*|image/*|media_type">
Tip:If multiple values need to be specified, separate these values with commas (for example <input accept="audio/*,video/*,image/*" />
.
Attribute Value
Value | Description |
---|---|
file_extension | Specify the file extensions that users can select (for example: .gif, .jpg, .png, .doc) |
audio/* | Users can select all audio files |
video/* | Users can select all video files |
image/* | Users can select all image files |
media_type |
Valid media types, without parameters. Please see the IANA Media Types for a complete list of standard media types. |
Browser Support
The numbers in the table indicate the first browser version to fully support this attribute.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
26.0 | 10.0 | 37.0 | 11.1 | 15.0 |