HTML accept Attribute

Last Updated : 31 Jul, 2026

HTML accept Attribute specifies the type of file that the server accepts. This attribute can be used with the <input> element only. This attribute is not used for validation tools because file uploads should be validated on the Server.

Syntax

<input accept = "file_extension"> 

Note: This attribute is not supported in HTML5.

Attribute Values:

TypeDescription
file_extensionIt Specify the file extension(s) like .gif, .jpg, .png, .doc) the user can pick from.
audio/*The user can pick all sound files.
video/*The user can pick all video files.
image/*A valid media type, with no parameters. Look at IANA Media Types for a complete list of standard media types.
media_typeA valid media type without parameters

Attribute: The accept attribute is associated with <input> elements only. 

HTML accept Attribute Examples

Example: Here is the implementation of HTML accept Attribute.

HTML
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>

<head>
    <title>accept attribute</title>
    <style>
        body {
            text-align: center;
        }
    </style>
</head>

<body>
  
<!--Driver Code Ends-->

    <form action=" ">
        <input type="file" name="picture" 
               accept="image/*">
        <input type="submit">
    </form>

<!--Driver Code Starts-->
</body>

</html>
<!--Driver Code Ends-->

Explanation:

  • In the above example we creates a form with the action attribute set to an empty string.
  • Inside the form, an input field of type file is defined with the name attribute set to "picture".
  • The accept attribute specifies that only image files are accepted for upload.
  • A submit button is provided to submit the form data.

HTML accept Attribute Use cases

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

In HTML5, the accept attribute is used within the input element of type file to specify the types of files that the server can accept for upload.

2. How to create input field that accept CSV file in HTML ?

To create an input field that accepts CSV files in HTML, use the input element with type="file" and set the accept attribute to ".csv" or "text/csv".

Comment