What is HTML accept Attribute?

HTML, HTML Attributes , 0 Comments

The accept attribute Specify which type of file user can choose from the input picker. This attribute is valid for only input type=”file”

Example

 <input type="file" name="pic" accept="image/*"> 

Note: You can use accept attribute only for <input type=”file”>.

Tip: Do not use this attribute as a validation tool. File uploads should be validated on the server for better validation.

Syntax

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

Separate the values with a comma to indicate more than one value (e.g. <input accept=” image/*, video/*, audio/*,” />.

Attribute Values

ValueDescription
file_extensionSpecify the file extension(s) (e.g: .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/*The user can pick all image files
media_typeA valid media type, with no parameters. Look at
IANA Media Types for a complete list of standard media types

Browser Support

Data on support for the input-file-accept feature across the major browsers from caniuse.com

Spread the love

Leave a Reply

avatar
  Subscribe  
Notify of