Input FileUpload accept Attribute

Definition and Usage

accept Sets or returns the value of the accept attribute of the file upload button.

The HTML accept attribute specifies the file types (that can be submitted through file upload) that the server accepts.

See also:

HTML Reference Manual:HTML <input> accept Attribute

Example

Example 1

Change the accepted content types:

// The server will only accept audio files in file uploads
document.getElementById("myFile").accept = "audio/*";

Try it yourself

Example 2

Display the content types accepted by the <input type="file"> element:

var x = document.getElementById("myFile").accept;

Try it yourself

Example 3

Accept multiple content types:

// The server will only accept audio and video files in file uploads
document.getElementById("myFile").accept = "audio/*,video/*";

Try it yourself

Syntax

Return the accept attribute:

fileuploadObject.accept

Set the accept attribute:

fileuploadObject.accept = "audio/*,video/*,image/*,MIME_type"

Attribute value

Value Description
audio/* Accept all audio files.
video/* Accept all video files.
image/* Accept all image files.
MIME_type

Valid MIME Types.

Please see IANA MIME Types, to get a complete list of standard MIME types.

Tip:If multiple values need to be specified, these values should be separated by commas.

Technical Details

Return Value: String value, containing a list of acceptable content types separated by commas.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supported Not Supported Supported Not Supported Supported