Open In App

HTML <input> accept Attribute

The HTML <input> accept Attribute is used to specify the file types that the input field can accept, restricting the file selection to those specified types, such as image/* for images or .pdf for PDF files.

HTML <input> accept Attribute Syntax:  

<input accept = "file_extension | audio/* | video/* | image/* | media_type">

HTML <input> accept Attribute Attribute Values: 

HTML <input> accept Attribute Example: 

Here is he basic implementation of using <input> accept Attribute.






<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML input accept attribute
    </title>
    <style>
        body {
            text-align: center;
        }
          
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <h1>GeeksForGeeks</h1>
    <h2>
        HTML input accept attribute
    </h2>
    <form action=" ">
        <input type="file" name="picture" accept="image/*">
        <input type="submit">
    </form>
</body>
  
</html>

Output: 

HTML input accept attribute example ouptut

HTML <input> accept Attribute Example Explanation:

HTML <input> accept Attribute Example:

In this example,we allows users to upload files, limiting options to .doc, .docx, and .pdf formats only using the accept attribute.






<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML input accept attribute
    </title>
    <style>
        body {
            text-align: center;
        }
          
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <h1>GeeksForGeeks</h1>
    <h2>
        HTML input accept attribute
    </h2>
    <form action=" ">
        <input type="file" accept=".doc, .docx, .pdf">
  
        <input type="submit">
    </form>
</body>
  
</html>

Output:

HTML accept Attribute example ouptut

HTML <input> accept Attribute Example Explanation:

HTML <input> accept Attribute use Cases:

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

To Specify acceptable file types for server upload using the “accept” attribute within the HTML <input type=”file”> element.

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

Here we create an input field that accepts CSV files by adding accept=”.csv” attribute to the HTML <input type=”file”> element.

3. What is the Limit File Format when using <input type=”file”> ?

The limit file format when using `<input type=”file”>` is defined by the “accept” attribute, specifying accepted file types.

HTML <input> accept Attribute Supported Browsers:

The browsers supported by HTML <input> accept Attribute are listed below: 


Article Tags :