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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:
Before Click:

After Click:

Examples: Set the accepted file type.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:
Before Click:

After Click:

Supported Browsers:

  • Google Chrome
  • Mozilla Firefox
  • Edge
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.