The :file selector matches every input element with type="file" — the upload control in HTML forms. It is a jQuery form pseudo-class since 1.0, equivalent to [type="file"].
01
Syntax
input:file
02
type
= file
03
Prefix
Use input
04
Official
Style + count
05
Upload
change event
06
CSS alt
[type=file]
Fundamentals
Introduction
File inputs power uploads — profile photos, document attachments, CSV imports. When a form mixes text fields, checkboxes, and file pickers, you need a selector that targets only the upload controls.
jQuery’s :file pseudo-class selects all elements of type file — in practice, every <input type="file">. It has existed since jQuery 1.0 and is equivalent to $("[type=file]"). Official docs recommend input:file rather than bare :file, which implies *:file.
Concept
Understanding the :file Selector
Think of :file as a shortcut for “every file upload input in this scope.” It filters by the HTML type attribute — nothing else.
<input type="file"> → matches.
<input type="file" accept="image/*"> → matches (accept does not affect selector).
<input type="text"> → no match.
<input type="checkbox"> → no match (use :checkbox).
<button> → no match.
💡
Beginner Tip
For performance in modern browsers, official jQuery docs suggest input[type="file"] instead of :file so the initial query can use native querySelectorAll.
No arguments — the pseudo-class matches by input type attribute.
Return value
A jQuery object containing every file input in the search context.
Empty collection when no file inputs exist.
Official jQuery API example
jQuery
var input = $( "input:file" ).css({
background: "yellow",
border: "3px red solid"
});
$( "div" )
.text( "For this type jQuery found " + input.length + "." )
.css( "color", "red" );
Cheat Sheet
⚡ Quick Reference
Element
input:file
input[type="file"]
<input type="file">
Matches
Matches
<input type="file" multiple>
Matches
Matches
<input type="text">
No match
No match
<input type="button">
No match
No match
Native querySelectorAll
Not supported
Supported
Compare
📋 :file vs [type="file"] and other input types
jQuery pseudo-class vs attribute selector vs sibling form types.
:file
input:file
jQuery extension
[type=file]
input[type="file"]
Native CSS — faster
:checkbox
input:checkbox
Different type
:button
:button
Buttons, not file
Hands-On
Examples Gallery
Example 1 follows the official jQuery input:file demo. Examples 2–5 compare with attribute selectors, count scoped uploads, handle the change event, and use the native performance pattern.
📚 Official jQuery Demo
Style file inputs and report how many were found.
Example 1 — Official Demo: input:file
Official jQuery demo — yellow background, red border, and match count.
jQuery
var input = $( "input:file" ).css({
background: "yellow",
border: "3px red solid"
});
$( "div" ).text( "For this type jQuery found " + input.length + "." );
Form reset — clear file inputs with .val("") on the matched set.
Accept filters — combine with [accept] for image-only pickers.
🧠 How jQuery Evaluates :file
1
Find candidates
Start from scoped inputs — input:file, not bare :file.
Scope
2
Check type attribute
Keep only input elements whose type is file.
Filter
3
Return collection
All matching file inputs in document order within scope.
Result
4
✓
Chain methods
Apply .css(), .on("change"), or .prop() on upload controls.
Important
📝 Notes
Available since jQuery 1.0 — selects input[type=file] only.
Equivalent to [type="file"] — official jQuery documentation.
Prefer input:file over bare $(":file") (implies *:file).
Not valid in native querySelectorAll(":file") — use attribute selector instead.
accept, multiple, and capture attributes do not change whether :file matches.
Security: browsers restrict reading file paths — use the files API after selection.
Compatibility
Browser Support
The :file pseudo-class is a jQuery extension — not standard CSS — and works in jQuery 1.0+. File inputs themselves are supported in all modern browsers. For native selector speed, use input[type="file"].
✓ jQuery 1.0+
jQuery :file Selector
Works wherever jQuery and HTML file inputs are supported. Native: input[type=file].
100%jQuery + HTML
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
:fileUniversal
Bottom line: Use input:file or input[type=file] scoped to your form — not bare :file on the whole document.
Wrap Up
Conclusion
The :file selector matches every file upload input — <input type="file"> — in your search context. The official demo styles them and reports how many were found.
Prefix with input, scope to your form, and prefer input[type="file"] when you need native selector performance. Pair with change handlers for upload UX.
Read full file paths from the value attribute (blocked by browsers)
Forget to scope when multiple forms exist on one page
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :file
All file upload inputs in scope.
5
Core concepts
📁01
:file
type=file
API
in02
Prefix
input:file
Scope
[]03
Equiv
[type=file]
CSS
Δ04
change
Upload UX
Tip
demo05
Official
Count demo
Demo
❓ Frequently Asked Questions
:file selects every input element whose type attribute is file — the control users click to upload files from their device. $("input:file") finds all file inputs in the search context. Available since jQuery 1.0.
Yes. Official jQuery docs state that :file is equivalent to [type="file"]. For native querySelectorAll performance in modern browsers, prefer input[type="file"] over the :file pseudo-class.
Prefer $("input:file"). Bare $(":file") implies the universal selector — equivalent to $("*:file") — which scans every element type. Official docs recommend prefixing with input or scoping to a form.
No. It is a jQuery extension since version 1.0. Native querySelectorAll cannot run :file directly. Use input[type="file"] for standard CSS attribute matching.
The official jQuery form demo styles $("input:file") with a yellow background and red border, then reports how many were found — typically one file input among text, button, checkbox, and other controls in the sample form.
Yes. After selecting with $("input:file"), bind the change event — e.g. $("input:file").on("change", function() { var name = this.files[0].name; }) — to react when the user picks a file.
Did you know?
Official jQuery docs note that :file cannot use native querySelectorAll optimization — but input[type="file"] can. In upload-heavy pages, switching to the attribute selector for the initial query often improves performance while keeping the same matched elements.