HTML <input> accept 属性

定义和用法

accept 属性为用户可以从文件输入对话框中选择的文件类型规定一个过滤器。

accept 属规定的是能够通过文件上传进行提交的文件类型。

注意:accept 属性只能与 <input type="file"> 一起使用。

Tip:请不要将此属性用作验证工具。文件上传应在服务器段进行验证。

实例

规定用户可以从文件输入对话框中选择的文件类型:

<form action="/action_page.php">
  <label for="img">请选择图片:</label>
  <input type="file" id="img" name="img" accept="image/*">
  <input type="submit">
</form>

Try it yourself

Syntax

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

Tip:If multiple values need to be specified, separate these values with commas (for example <input accept="audio/*,video/*,image/*" />.

Attribute Value

Value Description
file_extension Specify the file extensions that users can select (for example: .gif, .jpg, .png, .doc)
audio/* Users can select all audio files
video/* Users can select all video files
image/* Users can select all image files
media_type

Valid media types, no parameters.

Please see the IANA media types for a complete list of standard media types.

Browser Support

The numbers in the table indicate the first browser version that fully supports this property.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
26.0 10.0 37.0 11.1 15.0