HTML | DOM Input FileUpload accept Property
The DOM Input FileUpload accept Property in HTML DOM is used to set or return the value of the accept attribute of the file upload button. The accept attribute specifies the types of files which are acceptable by that the server.
Syntax:
- Return the accept property:
fileuploadObject.accept
- Set the accept property:
fileuploadObject.accept="audio/*, video/*, image/*, MIME_type"
Property Values:
- audio/* : All sound files are acceptable
- video/* : All video files are acceptable
- image/* : All image files are acceptable
- MIME_type : A valid MIME type, with no parameters.
Return Value: It returns the string value which represent the type of the accepted file.
Example-1: Return the accepted file type.
<!DOCTYPE html> <html> <head> <style> h1 { color: green; } </style> </head> <body> <center> <h1> Geeeks for Geeks </h1> <p>Select a file to upload: <input type="file" id="myFile" size="50" accept="video/*"> </p> <button onclick="myFunction()"> File type </button> <p id="demo"></p> <script> function myFunction() { var gfg = document.getElementById( "myFile").accept; document.getElementById( "demo").innerHTML = gfg; } </script> </center> </body> </html> |
Output:
Before Click:

After Click:

Examples: Set the accepted file type.
<!DOCTYPE html> <html> <head> <style> h1 { color: green; } </style> </head> <body> <center> <h1> Geeks for Geeks </h1> <p>Select a file to upload: <input type="file" id="myFile" size="50" accept="video/*"> </p> <button onclick="myFunction()"> File type </button> <p id="demo"></p> <script> function myFunction() { var gfg = document.getElementById( "myFile").accept = "audio/*,video/*"; document.getElementById( "demo").innerHTML = gfg; } </script> </center> </body> </html> |
Output:
Before Click:

After Click:

Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Edge
- Opera
- Safari
Recommended Posts:
- HTML | DOM Input FileUpload name Property
- HTML | DOM Input FileUpload value Property
- HTML | DOM Input FileUpload type Property
- HTML | DOM Input FileUpload autofocus Property
- HTML | DOM Input FileUpload disabled Property
- HTML | DOM Input FileUpload required Property
- HTML | DOM Input FileUpload multiple Property
- HTML | DOM Input FileUpload form Property
- HTML | DOM Input FileUpload files Property
- HTML | DOM Input FileUpload Object
- HTML | <input> accept Attribute
- HTML | DOM Input URL value Property
- HTML | DOM Input URL name Property
- HTML | DOM Input Datetime value Property
- HTML | DOM Input DatetimeLocal min Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



