File chooser

The <input> element with type="file" allows the user to choose one or more files from their device storage. Usually this used for uploading files to server.

code result
<label for="img_upload">
Choose a image file:
</label><br>

<input type="file"
       id="img_upload" name="img_upload"
       accept="image/png, image/jpeg" />

attributes

attribute description
id, name Name of element.
accept

Defines the types of files that the user can select. Value is a string, that represents a comma-separated list of file extensions (with dot) or valid mime-types. For example "image/*, .pdf".

multiple

A boolean value indicating that the user can select more than one file.

files

Contains a list of selected files.

capture

Specifies which camera to use for capture of image or video data. Possible values:

  • user - the user-facing camera and/or microphone should be used
  • environment - the outward-facing camera and/or microphone should be used
  • by default browser is free to decide on its own what to do.