HTMLInputElement.files

The HTMLInputElement.files is a property that allows you to access the FileList selected with the <input type="file"> element.

Value

An instance of FileList or null if the HTMLInputElement is not of type="file".

Examples

The example below shows how you can access the HTMLInputElement.files property and log the files' name selected by the user.

HTML

<input id="files" type="file" multiple />

JavaScript

Note that HTMLInputElement.files still returns an instance of FileList even if no files are selected. Therefore it's safe to iterate through it with for...of without checking if any files are selected.

const fileInput = document.getElementById("files");

console.log(fileInput.files instanceof FileList); // true

for (const file of fileInput.files) {
  console.log(file.name); // prints file name
}

Specifications

Specification
HTML Standard
# dom-input-files-dev

Browser compatibility

BCD tables only load in the browser