html tutorial - accept Attribute in HTML - html5 - html code - html form

Accept attribute in html

Learn html - html tutorial - accept attribute in html - html examples - html programs

  • The accept attribute used to specifies a comma-separated list of content types that the server accepts.
  • The accept attribute can only use with <input> file tag.

Syntax for accept attribute in HTML:

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

Applies To:

Element Attribute
<input> accept

accept Attribute Values:

Value Description
file_extension A file extension, e.g.: .gif, .jpg, .png, .doc
audio/* All audio files are supported
video/* All video files are supported
image/* All image files are supported
media_type A valid media type, is used with no parameters.

Sample Coding for accept Attribute in HTML:

Tryit<!DOCTYPE html>
        <title>Wikitechy accept attribute</title>
            <input type=”file” name=”image” accept=”image/*”>
            <input type=”submit”>

Code Explanation for accept Attribute in HTML:

accept Attribute Code Explanation

  1. <input> tag used to get the inputs from the user.
  2. type=”file” used to specifies the file input.
  3. accept is used to specifies that the server accepted file types.
  4. “image/*” is define the input file must be image format.

Output for accept Attribute in HTML:

accept Attribute Tag Output

  1. If we click the “Choose file” button open dialog box is displayed.
  2. Open dialog box shows the default file type as image. We can choose only images from the folders.
  3. accept Attribute Tag Output
  4. After choosing the image it shows that the image is chosen with its name as “images.jpg”.

Browser Support for accept Attribute in HTML:

8.0 10.0 4.0 6.0 15.0

Tips and Notes

  • Do not use accept attribute as a validation tool. File uploads should be validated on the server.

Related Searches to accept Attribute in html