html tutorial - accept Attribute in HTML - html5 - html code - html form
- 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:
accept Attribute Values:
|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:
Code Explanation for accept Attribute in HTML:
- <input> tag used to get the inputs from the user.
- type=”file” used to specifies the file input.
- accept is used to specifies that the server accepted file types.
- “image/*” is define the input file must be image format.
Output for accept Attribute in HTML:
- If we click the “Choose file” button open dialog box is displayed.
- Open dialog box shows the default file type as image. We can choose only images from the folders.
- After choosing the image it shows that the image is chosen with its name as “images.jpg”.
Browser Support for accept Attribute in HTML:
Tips and Notes
- Do not use accept attribute as a validation tool. File uploads should be validated on the server.