jQuery :hidden Selector

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
jQuery extension · jQuery 1.0+

What You’ll Learn

The :hidden selector matches elements that consume no layout space — hidden by display:none, zero size, hidden ancestors, or input type="hidden". jQuery extension since 1.0; opposite of :visible.

01

Syntax

:hidden

02

display

none

03

Official

Count & show

04

:visible

Opposite

05

Not hidden

opacity, visibility

06

.filter()

Performance

Introduction

Toggle panels, reveal accordions, audit form fields, and debug UI state — you often need to find elements that are not shown on the page. jQuery’s :hidden pseudo-class selects every element that consumes no space in the document layout.

jQuery has supported :hidden since version 1.0. Official documentation lists several reasons an element is hidden: CSS display:none, type="hidden" inputs, explicit zero width/height, or a hidden ancestor. Because checking visibility can force layout recalculation, prefer scoping with CSS first, then .filter(":hidden"), or track state with a class when performance matters.

Understanding the :hidden Selector

An element is :hidden when it (or an ancestor) consumes no layout space:

  • display: none → matches :hidden.
  • input type="hidden" → matches :hidden.
  • width: 0; height: 0 (explicit) → matches :hidden.
  • Inside a hidden parent → child also matches :hidden.
  • visibility: hidden or opacity: 0 → still visible to jQuery (uses space).
💡
Beginner Tip

:hidden is about layout boxes, not whether you can see pixels. A transparent or invisible-but-sized element is :visible, not :hidden.

📝 Syntax

Official jQuery API form (since 1.0):

jQuery
jQuery( ":hidden" )

// typical usage:
$( ":hidden" )
$( "div:hidden" )
$( "input:hidden" )

// official demo pattern:
var hiddenElements = $( "body" ).find( ":hidden" ).not( "script" );
$( "div:hidden" ).show( 3000 );

// performance pattern — CSS scope, then filter:
$( "#panel *" ).filter( ":hidden" )

Parameters

  • None:hidden takes no arguments. jQuery evaluates layout and ancestry.

Return value

  • A jQuery object containing every matched hidden element in document order.
  • Empty collection when nothing in scope is hidden.

Official jQuery API example

jQuery
var hiddenElements = $( "body" ).find( ":hidden" ).not( "script" );
$( "span" ).first().text( "Found " + hiddenElements.length + " hidden elements total." );
$( "div:hidden" ).show( 3000 );
$( "span" ).last().text( "Found " + $( "input:hidden" ).length + " hidden inputs." );

⚡ Quick Reference

CSS / markup:hidden?:visible?
display: noneYesNo
visibility: hiddenNoYes
opacity: 0NoYes
input type="hidden"YesNo
Hidden ancestorYes (child too)No

📋 :hidden vs :visible, CSS, and classes

Layout visibility vs pixel visibility vs manual state tracking.

:hidden
$("div:hidden")

No layout box

:visible
$("div:visible")

Opposite set

[hidden]
$("[hidden]")

HTML attribute

.is-hidden
$(".is-hidden")

Class (fast)

Examples Gallery

Example 1 follows the official jQuery hidden demo. Examples 2–5 cover visibility vs display, scoped .filter(":hidden"), hidden inputs, and revealing panels with .show().

📚 Official jQuery Demo

Count hidden elements, animate hidden divs visible, count hidden inputs.

Example 1 — Official Demo: count and div:hidden

Official jQuery demo — count body hidden nodes (excluding script), show hidden divs over 3 seconds, report hidden input count.

jQuery
var hiddenElements = $( "body" ).find( ":hidden" ).not( "script" );
$( "span" ).first().text( "Found " + hiddenElements.length + " hidden elements total." );
$( "div:hidden" ).show( 3000 );
$( "span" ).last().text( "Found " + $( "input:hidden" ).length + " hidden inputs." );
Try It Yourself

How It Works

jQuery walks the DOM and tests layout boxes. Elements with display:none or hidden ancestors match; the official demo excludes script tags from the total count.

Example 2 — display:none vs visibility:hidden

Only display:none matches :hidden — invisible but sized elements stay :visible.

jQuery
console.log( "display:none →", $( "#gone" ).is( ":hidden" ) );
console.log( "visibility:hidden →", $( "#invisible" ).is( ":hidden" ) );
console.log( "opacity:0 →", $( "#transparent" ).is( ":hidden" ) );
Try It Yourself

How It Works

Official docs: visibility:hidden and opacity:0 still consume layout space, so jQuery reports them as visible.

📈 Practical Patterns

Scoped filtering, form fields, UI reveal.

Example 3 — Performance: .filter(":hidden")

Scope to a panel with CSS, then filter — official performance guidance.

jQuery
var count = $( "#panel *" ).filter( ":hidden" ).length;
$( "#report" ).text( "Hidden inside #panel: " + count );
Try It Yourself

How It Works

Limit the candidate set before running the visibility test — faster than scanning the entire document with bare $(":hidden").

Example 4 — Form Fields: input:hidden

Select hidden inputs — CSRF tokens, IDs, and other non-visible form data.

jQuery
$( "input:hidden" ).each(function () {
  console.log( this.name + " = " + this.value );
});
Try It Yourself

How It Works

type="hidden" inputs never render visibly — jQuery always reports them as :hidden.

Example 5 — Reveal UI: div:hidden + .show()

Click a button to reveal every hidden panel inside a container.

jQuery
$( "#reveal-btn" ).on( "click", function () {
  $( "#accordion div:hidden" ).slideDown( 400 );
});
Try It Yourself

How It Works

Combine scoped div:hidden with effects — only panels with no layout box are targeted.

🚀 Common Use Cases

  • Debug UI — count hidden nodes with $("body").find(":hidden").not("script").
  • Reveal panels$("div:hidden").show() as in the official demo.
  • Forms — iterate input:hidden tokens and IDs.
  • Accordions — open closed sections with div:hidden + .slideDown().
  • Validation — ensure required visible fields are not inside hidden parents.
  • Performance — scope then .filter(":hidden") instead of global scans.

🧠 How jQuery Evaluates :hidden

1

Build candidate set

Evaluate prefix — all elements, div:hidden, or scoped descendants.

Query
2

Check layout boxes

Test whether the element or any ancestor consumes space — may trigger layout work.

Layout
3

Apply jQuery rules

Ignore visibility/opacity; treat type=hidden and display:none as hidden; jQuery 3+ skips elements with no boxes.

Rules
4

Return collection

Complement of :visible — chain .show(), .each(), or read .length.

📝 Notes

  • Available since jQuery 1.0 — jQuery extension, not native CSS.
  • Opposite of :visible — partitions the DOM into two sets.
  • visibility:hidden and opacity:0 are not :hidden.
  • Hidden ancestors hide descendants — children also match :hidden.
  • Official demo excludes script from body hidden counts in some browsers.
  • Heavy use can hurt performance — prefer classes or scoped .filter().
  • jQuery 3+: elements without layout boxes (e.g. empty inline, br) are :hidden.

Browser Support

The :hidden pseudo-class is a jQuery extension and works in jQuery 1.0+. Visibility tests run through jQuery’s engine consistently across browsers, but may force layout recalculation. Use scoped .filter(":hidden") or state classes when performance is critical.

jQuery 1.0+ · extension

jQuery :hidden Selector

Layout-based hiding — not the same as CSS visibility or opacity.

100% jQuery only
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
:hidden Extension

Bottom line: Pair with :visible — scope first, then filter on large pages.

Conclusion

The :hidden selector matches elements that consume no layout space — through display:none, zero size, hidden ancestors, or input type="hidden". The official demo counts hidden nodes and animates hidden divs visible.

Remember it is the opposite of :visible, ignore visibility/opacity for matching, and prefer scoped .filter(":hidden") when performance matters.

💡 Best Practices

✅ Do

  • Scope with $("#panel *").filter(":hidden")
  • Use input:hidden for form token audits
  • Pair mentally with :visible — opposite sets
  • Exclude script when counting body hidden nodes
  • Track UI state with classes when toggling often

❌ Don’t

  • Assume visibility:hidden matches :hidden
  • Assume opacity:0 matches :hidden
  • Run bare $(":hidden") on huge DOM trees repeatedly
  • Use :hidden in native CSS — jQuery-only extension
  • Confuse with HTML [hidden] attribute alone

Key Takeaways

Knowledge Unlocked

Five things to remember about :hidden

Layout boxes, not pixel visibility.

5
Core concepts
:visible 02

Opposite

Complement

Rule
none 03

display

Hidden

CSS
demo 04

Official

Count & show

Demo
.filter 05

Scope

Performance

Tip

❓ Frequently Asked Questions

:hidden selects elements that are hidden — they consume no space in the document layout. Common cases include display:none, input type="hidden", zero width/height, or a hidden ancestor. Available since jQuery 1.0.
No. Elements with visibility:hidden or opacity:0 still take up space in the layout, so jQuery treats them as visible. Only elements that consume no layout space match :hidden.
Yes. Every element selected by :hidden is not selected by :visible, and vice versa. They are complementary filters in jQuery.
No. It is a jQuery extension and does not work in native querySelectorAll(). Official docs recommend selecting with a CSS scope first, then .filter(":hidden") for better performance.
In some browsers, $("body").find(":hidden") also matches head, title, script, and other non-visible document nodes. The official demo excludes script tags before counting user-facing hidden elements.
Starting with jQuery 3, elements without layout boxes — such as br and empty inline elements — are considered :hidden. This slightly refines how :hidden and :visible divide the DOM.
Did you know?

During show/hide animations, jQuery treats elements as :visible at the start of a show animation and as :hidden until a hide animation completes. That timing affects which elements match during transitions.

Continue to :visible Selector

After :hidden, learn the complementary :visible filter — layout boxes, official click demo, and performance tips.

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