Open In App

HTML accept Attribute

Last Updated : 12 Mar, 2024
Like Article

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


<input accept = "file_extension"> 

Note: This attribute is not supported in HTML5.

Attribute Values:

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.

<!DOCTYPE html>

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

    <form action=" ">
        <input type="file" name="picture" 
        <input type="submit">



HTML accept attribute example output


  • 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”.

Supported Browsers

The browser supported by accept attribute are listed below:  

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads