Open In App

How to specify the type of files that server accepts in HTML5 ?

In this article, we will learn how to specify the types of files that the server accepts in HTML5. The <input> accept attribute is used to specify the type of file that the server accepts. This attribute can be used with <input type=”file”> element only. This attribute is not used for validation tools because file uploads should be validated on the Server.

We will add each specific file one by one.

<input type="File" name="" accept=".doc, .docx">


<input type="File" name="" accept="video/*">
Note: The * is the wild card, and it means that it accepts all video formats.

<input type="File" name="" accept=".pdf, .txt">


<input type="File" name="" accept="audio/*">

<input type="File" name="" accept="image/*">

<input type="File" name="" accept=".png, .jpg, .jpeg">

<input type="File" name="" accept="video/*, audio/*, .png, .pdf">

Example: This example shows how to specify the type of files that server accepts in HTML5.




<!DOCTYPE html>
<html>
 
<head>
    <title>To specify the type of file</title>
</head>
 
<body>
    <form>
        <label>Select a MSWord file:</label>
        <input type="File" name="" accept=".doc, .docx"><br><br>
 
        <label>Select an Video file:</label>
        <input type="File" name="" accept="video/*"><br><br>
 
        <label>Select a Pdf or Text file:</label>
        <input type="File" name="" accept=".pdf, .txt"><br><br>
 
        <label>Select an Audio file:</label>
        <input type="File" name="" accept="audio/*"><br><br>
 
        <label>Select an Image file:</label>
        <input type="File" name="" accept="image/*"><br><br>
 
        <label>Select a Png or Jpeg file:</label>
        <input type="File" name="" accept=".png, .jpg, .jpeg"><br><br>
 
        <label>Select a Multiple file Types:</label>
        <input type="File" name="" accept="video/*, audio/*, .png, .pdf">
        <br><br>
 
        <input type="Submit" name="">
    </form>
</body>
 
</html>

Output:


Article Tags :