The webkitdirectory property of the HTMLInputElement interface reflects the webkitdirectory HTML attribute, which indicates that <input type="file"> elements can only select directories instead of files.
When a directory is selected, the directory and its entire hierarchy of contents are included in the set of selected items. The selected file system entries can be obtained using the webkitEntries property.
Note: This property is called webkitdirectory in the specification due to its origins as a Google Chrome-specific API.
A Boolean; true if the <input> element should allow picking only directories or false if only files should be selectable.
Setting webkitdirectory to true causes the input element to offer directories for the user to select instead of files. After the user chooses a directory, each File object in the returned files has its File.webkitRelativePath property set to a path relative to the selected ancestor directory. For example, consider this file system:
PhotoAlbums
├── Birthdays
│ ├── Jamie's 1st birthday
│ │ ├── PIC1000.jpg
│ │ └── PIC1044.jpg
│ └── Don's 40th birthday
│ ├── PIC2343.jpg
│ └── PIC2356.jpg
└── Vacations
└── Mars
├── PIC5556.jpg
├── PIC5684.jpg
└── PIC5712.jpg
If the user chooses the PhotoAlbums directory, the list reported by files will contain File objects for every file. The entry for PIC2343.jpg will have a webkitRelativePath of PhotoAlbums/Birthdays/Don's 40th birthday/PIC2343.jpg. This makes it possible to determine the selected directory's hierarchy even though the FileList is flat.
Note: The behavior of webkitRelativePath is different in Chromium < 72. See this bug for further details.
In this example, a directory picker is presented which lets the user choose one or more directories. When the change event occurs, a list of all files contained within the selected directory hierarchies is created and displayed.
<input type="file" id="file-picker" name="fileList" webkitdirectory multiple /> <ul id="listing"></ul>
document.getElementById("file-picker").addEventListener(
"change",
(event) => {
let output = document.getElementById("listing");
for (const file of event.target.files) {
let item = document.createElement("li");
item.textContent = file.webkitRelativePath;
output.appendChild(item);
}
},
false,
);
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
webkitdirectory |
7 | 13 | 50 | 15 | 11.1 | 132131–132In Chrome for Android 131, if a user selects a directory, the browser crashes (see bug 376834374).18–131The property reflects the attribute, but users cannot choose a directory, only individual files (see bug 40248532. |
142141–142File entries returned for a selected directory have an empty string for webkitRelativePath (bug 1973726). |
8714–87The property reflects the attribute, but users cannot choose a directory, only individual files (see bug 40248532. |
18.411.3–18.4The property can be set, but has no effect (see bug 271705). |
1.0The property reflects the attribute, but users cannot choose a directory, only individual files (see bug 40248532. |
132131–132In Chrome for Android 131, if a user selects a directory, the browser crashes (see bug 376834374).4.4–131The property reflects the attribute, but users cannot choose a directory, only individual files (see bug 40248532. |
18.411.3–18.4The property can be set, but has no effect (see bug 271705). |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory