jQuery :password Selector

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Form inputs

What You’ll Learn

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

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.

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.

📝 Syntax

Official jQuery API form (since 1.0):

jQuery
jQuery( ":password" )

// recommended — prefix with input:
$( "input:password" )
$( "#login-form input:password" )

// equivalent attribute form:
$( "input[type=password]" )

// native CSS (better performance):
document.querySelectorAll( 'input[type="password"]' )

// avoid on large pages:
$( ":password" )   // implies *:password

Parameters

  • 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" );

⚡ Quick Reference

Elementinput:passwordinput[type="password"]
<input type="password">MatchesMatches
<input type="password" autocomplete>MatchesMatches
<input type="text">No matchNo match
<input type="hidden">No matchNo match
Native querySelectorAllNot supportedSupported

📋 :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

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; } );
Try It Yourself

How It Works

Only type="password" inputs match — the official form mixes many control types to show specificity.

Example 2 — Equivalence: [type=password]

Official docs — :password and the attribute selector return the same matched set.

jQuery
console.log( ":password →", $( "input:password" ).length );
console.log( "[type=password] →", $( "input[type=password]" ).length );
Try It Yourself

How It Works

Both forms select the same DOM nodes — choose attribute syntax when native speed matters.

📈 Practical Patterns

Scoping, validation, and native queries.

Example 3 — Scoped Login: $("#login input:password")

Style password fields in one form without affecting a signup form on the same page.

jQuery
$( "#login input:password" ).css( "borderColor", "#2563eb" );

// #signup password fields unchanged
Try It Yourself

How It Works

Official docs recommend scoping — prefix with a form id or class before the input type pseudo-class.

Example 4 — Empty Check: highlight blank password fields

On submit, flag password inputs with no value before sending credentials.

jQuery
$( "#auth" ).on( "submit", function( e ) {
  e.preventDefault();
  $( "input:password", this ).each( function() {
    $( this ).toggleClass( "error", !this.value );
  });
});
Try It Yourself

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']" );
Try It Yourself

How It Works

Because :password is not standard CSS, attribute matching lets the browser optimize the query.

🚀 Common Use Cases

  • Login forms — select input:password for styling or validation.
  • Signup flows — highlight confirm-password fields scoped to one form.
  • Admin panels — count password fields before enabling submit.
  • Accessibility — pair with labels via $("#form input:password").first().
  • Security UX — toggle visibility buttons bound to password inputs only.
  • 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.

📝 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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
:password Universal

Bottom line: Scope to forms with input:password; prefer [type="password"] when performance matters.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about :password

Password-type inputs only.

5
Core concepts
= 02

[type=]

Equivalent

Rule
in 03

input:

Prefix it

Tip
demo 04

Official

Style count

Demo
CSS 05

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.

Continue to :image Selector

Learn how to select input[type=image] graphical submit buttons in forms.

:image selector tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful