HTML accept Attribute defines the type of the file that user can select to upload or the file that server accepts. HTML accept Attribute is used for input tag.
Table of Contents
Syntax of HTML accept Attribute
The Syntax of HTML accept Attribute is shown below.
<input type="file" accept="image/*" name="image" >
Usage of HTML accept Attribute
HTML accept Attribute is used to specify the type of file that server can accept. HTML accept Attribute is used with the input tag. HTML accept Attribute makes sure that user only upload the files which are allowed.
Used For
HTML accept Attribute is used for following tags.
Tag Name |
---|
HTML input Tag |
Example of HTML accept Attribute
Simple example of HTML accept Attribute is given below.
<label for="video">Video:</label>
<input type="file" id="video" accept="video/*">
In above example we have used HTML accept Attribute to only allow video files.
Values of HTML accept Attribute
Following values can be used with HTML accept Attribute.
Value | Description |
---|---|
image/* | All images are allowed. |
video/* | All videos are allowed. |
audio/* | All audio files are allowed. |
media_type | Valid media type without parameters. |
file_extension | Specify the allowed file extensions. |
At a time, more than one value can be used for HTML accept Attribute, separate the values with a comma.
<label for="video">Audio/Video:</label>
<input type="file" id="video" accept="audio/*,video/*">
Browser Support for HTML accept Attribute
HTML accept Attribute is supported by following major browsers.
Browser Name | Version |
---|---|
Chrome | 8.0 and above |
Firefox | 4.0 and above |
Opera | 15.0 and above |
IE / Edge | 10.0 and above |
Safari | 6.0 and above |