File Input Attributes
What you'll learn: How to use HTML attributes to control precisely which files users can select and how they select them.
Controlling File Selection
The basic <input type="file"> element becomes much more powerful when you add attributes that filter and guide what users can upload. Think of these attributes as setting rules for a bouncer at a club—they determine who (or what) gets in.
The Key Attributes
accept
Limits file selection to specific MIME types or extensions:
<input type="file" accept="image/png, image/jpeg">
<input type="file" accept=".pdf,.doc,.docx">
Users will only see matching files in the picker dialog. Note: this is a hint to the browser, not security—always validate server-side.
multiple
Allows selecting more than one file at once:
<input type="file" multiple accept="image/*">
Without this, users can only pick one file per input.
capture
Hints that mobile devices should use their camera or microphone directly:
<input type="file" accept="image/*" capture="environment">
<!-- Options: "user" (front camera), "environment" (rear camera) -->
On mobile, this may skip the file picker and open the camera app immediately.
webkitdirectory
Enables selecting entire folders instead of individual files:
<input type="file" webkitdirectory>
This non-standard but widely-supported attribute lets users upload directory structures. All files within the selected folder become available.
Combining Attributes
<input type="file"
accept="image/*"
multiple
capture="environment">
This creates a mobile-friendly image uploader that prefers the rear camera and allows multiple photos.
Key Takeaway: File input attributes like accept, multiple, capture, and webkitdirectory help you guide users toward uploading the right files in the right way, improving UX and reducing upload errors.