HTML accept attribute

accept attribute gives hint to the browser that which type of file will be accepted by the browser.

Example

<p>HTML Document: <input type="file" accept=".html"> </p>
<p>Java Script File: <input type="file" accept=".js"> </p>
<p>Cascading Style Sheet Document: <input type="file" accept=".css"> </p>
Try </>

accept attribute values

accept='video/*':

video value hints the browser that only video files should be accepted.

Example

<p>Upload Video: <input type="file" accept="video/*"><p>

Try</>

accept='audio/*':

audio value hints the browser that only audios are to upload.

Example

<p>Upload audio: <input type="file" accept="audio/*"><p>

Try</>

accept='image/*':

image value hints the browser that only images should be accepted.

Example

<p>Upload image: <input type="file" accept="image/*"><p>

Try</>

accept='.extension':

The value which starts with a dot(.) hints the browser that a file of specific extension is to upload.

Example

<p>Upload files: <input type="file" accept=".doc,.docx"><p>

Try</>
  • If files of different extensions are allowed, then extensions should be separated by a comma.

  • The same type of extensions (dublicate extensions) should not be used.

Related Tags

The tags which support this attribute are as follows.

<input> tag

input tag allows the user to enter data in the form. It supports accept attribute.

See the examples given above.



Was this article helpful?

 

Email:

Message:

Get the newsletter