The :password selector matches every <input type="password"> element — masked credential fields in login and signup forms. Available since jQuery 1.0; equivalent to [type=password]; always prefer input:password over bare :password.
01
Syntax
input:password
02
type=password
Masked input
03
Official
Style + count
04
[type=]
Equivalent
05
Scope
form input
06
Native CSS
Faster query
Fundamentals
Introduction
Login pages, account settings, and checkout flows almost always include at least one password field. jQuery’s :password pseudo-class selects every input whose type attribute is password — regardless of name, id, or placeholder text.
Official jQuery documentation notes that :password is equivalent to [type=password], but because it is a jQuery extension, modern browsers run native input[type="password"] faster. Always prefix with input — bare $(":password") implies $("*:password") and scans the entire document.
Concept
Understanding the :password Selector
Think of :password as a shortcut for password-type inputs only:
input:password → masked credential fields (dots or bullets in the UI).
input[type="text"] → visible plain text — different type, no match.
input[type="password"][name="pwd"] → still matches :password.
Does not select <textarea> or custom widgets — only input type="password".
💡
Beginner Tip
Scope to your form: $("#login input:password") avoids styling password fields in unrelated modals or admin panels on the same page.
No arguments — keeps elements whose type is password.
Return value
A jQuery object containing every matching password input (zero or more).
Official jQuery API example
jQuery
var input = $( "input:password" ).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:password
input[type="password"]
<input type="password">
Matches
Matches
<input type="password" autocomplete>
Matches
Matches
<input type="text">
No match
No match
<input type="hidden">
No match
No match
Native querySelectorAll
Not supported
Supported
Compare
📋 :password vs [type="password"] and other input types
jQuery pseudo-class vs attribute selector vs sibling form types.
:password
input:password
jQuery extension
[type=password]
input[type="password"]
Native CSS — faster
:text
input:text
Plain text inputs
:input
input:password
Also matches :input set
Hands-On
Examples Gallery
Example 1 follows the official jQuery input:password demo. Examples 2–5 compare with attribute selectors, scope to a login form, highlight empty password fields, and use the native performance pattern.
📚 Official jQuery Demo
Style password inputs and report how many were found.
Example 1 — Official Demo: input:password
Official jQuery demo — yellow background, red border, and red match count among mixed form controls.
jQuery
var input = $( "input:password" ).css({
background: "yellow",
border: "3px red solid"
});
$( "div" ).text( "For this type jQuery found " + input.length + "." )
.css( "color", "red" );
$( "form" ).on( "submit", function() { return false; } );
Submit with empty password → .error class (red outline)
After typing a value → error removed on next submit
How It Works
Passing this as context limits input:password to fields inside the submitted form.
Example 5 — Native Performance: input[type="password"]
Official docs — use attribute selector in modern browsers for querySelectorAll speed.
jQuery
// jQuery with native-friendly selector:
$( "input[type='password']" ).addClass( "secure-field" );
// Pure DOM (no jQuery pseudo-class):
document.querySelectorAll( "input[type='password']" );
Performance — prefer input[type="password"] in hot paths.
🧠 How jQuery Evaluates :password
1
Parse selector
Combine input with :password — e.g. #login input:password.
Query
2
Find candidates
Collect input elements in scope (or all elements if bare :password).
Scan
3
Filter by type
Keep inputs where type attribute equals password.
Match
4
✓
Return collection
Chain .css(), .val(), or event handlers.
Important
📝 Notes
Available since jQuery 1.0 — equivalent to [type=password].
jQuery extension only — not valid in native querySelectorAll(":password").
Always use input:password — bare :password implies universal scan.
Official performance tip — use input[type="password"] in modern browsers.
Does not match text fields, hidden inputs, or textareas.
Also included in the broader :input selector set.
Compatibility
Browser Support
The :password pseudo-class is a jQuery extension and works in jQuery 1.0+. The equivalent input[type="password"] attribute selector is standard CSS and runs in native querySelectorAll in all modern browsers.
✓ jQuery 1.0+ · extension
jQuery :password Selector
Use input:password in jQuery; use input[type="password"] for native speed.
100%jQuery + native attr
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
:passwordUniversal
Bottom line: Scope to forms with input:password; prefer [type="password"] when performance matters.
Wrap Up
Conclusion
The :password selector matches every input type="password" element — the official demo styles them yellow with a red border and reports the match count.
Prefix with input, scope to your form, and reach for [type="password"] when you need native query performance.
Write $("#login input:password") for scoped queries
Use input[type="password"] for native performance
Prevent default on demo forms — official pattern
Validate with .val() after selecting password inputs
Pair with autocomplete attributes in HTML
❌ Don’t
Use bare $(":password") on large pages
Expect :password in querySelectorAll
Confuse :password with :text or :hidden selectors
Log or display .val() in production debug output
Assume text inputs match — check type attribute
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :password
Password-type inputs only.
5
Core concepts
***01
:password
Masked input
API
=02
[type=]
Equivalent
Rule
in03
input:
Prefix it
Tip
demo04
Official
Style count
Demo
CSS05
Native
Faster attr
Perf
❓ Frequently Asked Questions
:password selects every input element whose type attribute is password — the masked fields used for login credentials and secrets. $("input:password") finds all password inputs in the search context. Available since jQuery 1.0.
Yes. Official jQuery docs state that :password is equivalent to $('[type=password]'). For native querySelectorAll performance in modern browsers, prefer input[type="password"] over the :password pseudo-class.
Prefer $("input:password"). Bare $(':password') implies the universal selector — equivalent to $('*:password') — 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 :password directly. Use input[type="password"] for standard CSS attribute matching.
:password matches input[type="password"] only — characters are masked. :text matches plain text inputs. They never overlap; pick the pseudo-class that matches your control type.
The official jQuery form demo styles $("input:password") with a yellow background and red border, then reports how many were found — typically one password field among text, textarea, select, button, and other controls in the sample form.
Did you know?
Official jQuery input-type demos (checkbox, file, password, and others) share the same pattern: style the matched inputs, print For this type jQuery found N., and block form submission with return false so the demo stays on the page.