HTMLInputElement: webkitdirectory property

Baseline 2025
Newly available

Since August 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

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.

Value

A Boolean; true if the <input> element should allow picking only directories or false if only files should be selectable.

Description

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.

Examples

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.

HTML

html
<input type="file" id="file-picker" name="fileList" webkitdirectory multiple />
<ul id="listing"></ul>

JavaScript

js
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);
  }
});

Result

Specifications

Specification
File and Directory Entries API
# dom-htmlinputelement-webkitdirectory

Browser compatibility

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
Chrome – Full support
Chrome 7 (Release date: 2010-10-19)
footnote Full support
Edge – Full support
Edge 13 (Release date: 2015-11-12)
footnote Full support
Firefox – Full support
Firefox 50 (Release date: 2016-11-15)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 11.1 (Release date: 2018-04-12)
footnote Full support
Chrome Android – Partial support
Chrome Android 18 – 130 (Release date: 2012-06-27)
footnote Partial support
footnote The property reflects the attribute, but users cannot choose a directory, only individual files (see bug 40248532.
Chrome Android – Partial support
Chrome Android 131 – 131 (Release date: 2024-11-12)
footnote Partial support
footnote In Chrome for Android 131, if a user selects a directory, the browser crashes (see bug 376834374).
Chrome Android – Full support
Chrome Android 132 (Release date: 2025-01-14)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 141 – 141 (Release date: 2025-07-22)
footnote Partial support
footnote File entries returned for a selected directory have an empty string for webkitRelativePath (bug 1973726).
Firefox for Android – Full support
Firefox for Android 142 (Release date: 2025-08-19)
footnote Full support
Opera Android – Partial support
Opera Android 14 – 86 (Release date: 2013-05-21)
footnote Partial support
footnote The property reflects the attribute, but users cannot choose a directory, only individual files (see bug 40248532.
Opera Android – Full support
Opera Android 87 (Release date: 2025-01-22)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 11.3 – 18.3 (Release date: 2018-03-29)
footnote Partial support
footnote The property can be set, but has no effect (see bug 271705).
Safari on iOS – Full support
Safari on iOS 18.4 (Release date: 2025-03-31)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 1 – 28 (Release date: 2013-04-27)
footnote Partial support
footnote The property reflects the attribute, but users cannot choose a directory, only individual files (see bug 40248532.
Samsung Internet – Full support
Samsung Internet 29 (Release date: 2025-10-25)
footnote Full support
WebView Android – Partial support
WebView Android 4.4 – 130 (Release date: 2013-12-09)
footnote Partial support
footnote The property reflects the attribute, but users cannot choose a directory, only individual files (see bug 40248532.
WebView Android – Partial support
WebView Android 131 – 131 (Release date: 2024-11-12)
footnote Partial support
footnote In Chrome for Android 131, if a user selects a directory, the browser crashes (see bug 376834374).
WebView Android – Full support
WebView Android 132 (Release date: 2025-01-14)
footnote Full support
WebView on iOS – Partial support
WebView on iOS 11.3 – 18.3 (Release date: 2018-03-29)
footnote Partial support
footnote The property can be set, but has no effect (see bug 271705).
WebView on iOS – Full support
WebView on iOS 18.4 (Release date: 2025-03-31)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Has more compatibility info.

See also