The :visible selector matches elements that consume layout space in the document — width or height greater than zero (jQuery 3+ includes any layout box). jQuery extension since 1.0; opposite of :hidden.
01
Syntax
:visible
02
Layout
Uses space
03
Official
Click & reveal
04
:hidden
Opposite
05
Still visible
opacity, visibility
06
.filter()
Performance
Fundamentals
Introduction
Attach click handlers only to shown panels, count open tabs, validate what the user can actually see, or style elements that take up space — jQuery’s :visible pseudo-class selects every element that consumes layout space in the document.
jQuery has supported :visible since version 1.0. Official documentation defines visibility by layout boxes, not by whether pixels appear on screen. Because checking visibility can force layout recalculation, prefer scoping with CSS first, then .filter(":visible"), or track state with a class when performance matters.
Concept
Understanding the :visible Selector
An element is :visible when it (and its ancestors) consume layout space in the document:
Normal block or inline content with size → matches :visible.
visibility: hidden or opacity: 0 → still visible to jQuery (uses space).
display: none or hidden ancestor → not:visible.
input type="hidden" → not :visible.
<option> elements → always treated as hidden (never :visible).
💡
Beginner Tip
:visible is about layout boxes, not whether you can see pixels. A transparent or invisible-but-sized element is still :visible.
None — :visible takes no arguments. jQuery evaluates layout and ancestry.
Return value
A jQuery object containing every matched visible element in document order.
Empty collection when nothing in scope is visible.
Official jQuery API example
jQuery
$( "div:visible" ).on( "click", function () {
$( this ).css( "background", "yellow" );
});
$( "button" ).on( "click", function () {
$( "div:hidden" ).show( "fast" );
});
Cheat Sheet
⚡ Quick Reference
CSS / markup
:visible?
:hidden?
Normal sized element
Yes
No
display: none
No
Yes
visibility: hidden
Yes
No
opacity: 0
Yes
No
input type="hidden"
No
Yes
<option>
No
Yes
Compare
📋 :visible vs :hidden, CSS, and classes
Layout visibility vs pixel visibility vs manual state tracking.
:visible
$("div:visible")
Has layout box
:hidden
$("div:hidden")
Opposite set
:selected
$("option:selected")
Dropdown options
.is-shown
$(".is-shown")
Class (fast)
Hands-On
Examples Gallery
Example 1 follows the official jQuery visible demo. Examples 2–5 cover the :hidden complement, visibility vs display, scoped .filter(":visible"), and binding handlers to visible list items only.
📚 Official jQuery Demo
Click visible divs to highlight them; button reveals hidden divs.
Example 1 — Official Demo: div:visible click + reveal hidden
Official jQuery demo — click any visible div to turn its background yellow; click the button to show hidden divs quickly.
jQuery
$( "div:visible" ).on( "click", function () {
$( this ).css( "background", "yellow" );
});
$( "button" ).on( "click", function () {
$( "div:hidden" ).show( "fast" );
});
Click a visible purple div → background turns yellow
Click "Show hidden divs" → hidden divs appear with .show("fast")
Hidden divs become :visible and can be clicked too
How It Works
Only divs with a layout box match div:visible. Hidden divs with display:none are excluded until the button runs div:hidden + .show().
Example 2 — Complement: count :visible vs :hidden
Inside a container, visible and hidden sets partition every child — counts should add up.
Click visible menu items → .active class applied
Toggle reveals extra items; newly visible items match li:visible
How It Works
Combine scoped li:visible with toggles — hidden items stay out of the handler set until shown.
Applications
🚀 Common Use Cases
Interactive demos — $("div:visible").on("click", …) as in the official demo.
Reveal hidden UI — pair with $("div:hidden").show() on a button click.
Tables & lists — count or style only tr:visible or li:visible rows.
Validation — ensure required fields inside visible panels are filled.
Tabs & accordions — operate on the open panel with :visible.
Performance — scope then .filter(":visible") instead of global scans.
🧠 How jQuery Evaluates :visible
1
Build candidate set
Evaluate prefix — all elements, div:visible, or scoped descendants.
Query
2
Check layout boxes
Test whether the element and ancestors consume space — may trigger layout work.
Layout
3
Apply jQuery rules
Treat visibility/opacity as visible; exclude display:none and hidden ancestors; jQuery 3+ includes layout boxes like br.
Rules
4
✓
Return collection
Complement of :hidden — chain .on(), .css(), or read .length.
Important
📝 Notes
Available since jQuery 1.0 — jQuery extension, not native CSS.
Opposite of :hidden — partitions the DOM into two sets.
visibility:hidden and opacity:0are :visible.
All <option> elements are considered hidden — never :visible.
During animations: visible at start of show; hidden until hide animation completes.
Heavy use can hurt performance — prefer classes or scoped .filter().
jQuery 3+: elements with layout boxes (e.g. br, empty inline) are :visible.
Compatibility
Browser Support
The :visible 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(":visible") or state classes when performance is critical.
✓ jQuery 1.0+ · extension
jQuery :visible Selector
Layout-based visibility — not the same as CSS pixel visibility.
100%jQuery only
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
:visibleExtension
Bottom line: Pair with :hidden — scope first, then filter on large pages.
Wrap Up
Conclusion
The :visible selector matches elements that consume layout space — normal content, invisible-but-sized elements, and anything not hidden by display:none or a hidden ancestor. The official demo highlights visible divs on click and reveals hidden ones with a button.
Remember it is the opposite of :hidden, treats visibility/opacity as visible, and prefer scoped .filter(":visible") when performance matters.
Use div:visible for interactive demos and handlers
Re-bind or delegate when toggling visibility often
Track UI state with classes when toggling repeatedly
❌ Don’t
Assume visibility:hidden excludes :visible
Assume opacity:0 excludes :visible
Expect option:visible to match dropdown options
Run bare $(":visible") on huge DOM trees repeatedly
Use :visible in native CSS — jQuery-only extension
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :visible
Layout boxes, not pixel visibility.
5
Core concepts
👁01
:visible
Has layout box
API
:hidden02
Opposite
Complement
Rule
003
opacity
Still visible
CSS
demo04
Official
Click & reveal
Demo
.filter05
Scope
Performance
Tip
❓ Frequently Asked Questions
:visible selects elements that consume space in the document layout — typically width or height greater than zero. Available since jQuery 1.0. It is the opposite of :hidden.
Yes. Elements with visibility:hidden or opacity:0 still take up layout space, so jQuery treats them as :visible. Only elements with no layout box match :hidden.
Yes. Every element selected by :visible is not selected by :hidden, and vice versa. Together they partition the DOM into two complementary sets.
No. jQuery considers all option elements hidden, so they never match :visible. Use :selected to work with dropdown options instead.
No. It is a jQuery extension and does not work in native querySelectorAll(). Official docs recommend selecting with a CSS scope first, then .filter(":visible") for better performance.
Starting with jQuery 3, elements that have a layout box — including br tags and empty inline elements — count as :visible even when width and height are zero. This refines how :visible and :hidden 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.