HTML <input> Tag with the 'accept' Attribute
<form name="myForm" action="http://www.htmlcodes.ws/resources/html-forms-action.cfm">
<input type="file" name="myFile" accept=".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document">
<button>Submit</button>
</form>
The above example demonstrates usage of the <input>
element with the accept
attribute.
The accept
attribute allows you to specify the file types that will be accepted when using a file upload control. When using type="file"
to allow the user to upload a file to the server, the accept
attribute allows you to restrict the file types that they can upload. Any file type that is not specified will not be accepted.
When using this attribute, provide a comma-separated list of content types that the server accepts.
It's best to specify both the MIME type as well as any extensions that might be used.
Here are the values you can use with the accept
attribute:
audio/*
video/*
image/*
- [A valid MIME type, with no parameters]
- [A string whose first character is a "." (U+002E) character] (for specifying a file extension)