:header (since jQuery 1.2) selects all heading elements — h1 through h6 — in one expression. It matches real heading tags only, not “title-looking” div or p elements.
Remember
$(":header") // all h1–h6 on the page
$("article :header") // headings inside article only
$("#main *").filter(":header") // faster scoped pattern
// Same matches as:
$("h1, h2, h3, h4, h5, h6")
Chain methods — .css(), .each(), .text(), and so on.
On large pages, prefer $("#scope *").filter(":header").
Remember: classed “titles” that are not heading tags are ignored.
Piece
Required?
Role
:header
Yes
Match h1–h6
Context / prefix
No
Limit search (e.g. article :header)
.filter(":header")
No
Recommended performance pattern
Return value
—
jQuery set of heading elements
Pseudocode
Pseudocode
call $(":header") // or $("context :header")
for each element in the document (or context):
if tagName is h1, h2, h3, h4, h5, or h6:
include it in the result set
return the jQuery set of those headings
Reference
Cheat Sheet
Keep these facts handy when selecting headings.
Topic
Detail
Syntax
$(":header") · $("context :header")
Since
jQuery 1.2
Matches
h1, h2, h3, h4, h5, h6
CSS?
No — jQuery extension
CSS equivalent
h1, h2, h3, h4, h5, h6
Faster pattern
$("#el *").filter(":header")
Does not match
Styled div / p “titles”
Try it
Live Preview
Click Run to list every :header match in the sample markup below.
Guide
Intro paragraph (not a header).
Chapter One
Details
Fake title class — ignored
Only real h1–h6 tags match. The paragraph with class title is skipped.
Result
Ready — click Run to list headings.
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.
TOC appears at top:
• Guide
• Chapter One
• Chapter Two
Each links to its heading id
How It Works
Collect.$(":header") finds every heading.
Ids. Each heading gets a unique id.
Links. TOC entries point to those ids.
Prepend. The list is inserted at the top of body.
Edge Cases & Pitfalls
Watch these when heading counts look “wrong.”
tags
Only real h1–h6 tags
A div.title or bold p never matches, no matter how it looks.
perf
Bare $(":header") can be slow
On big pages, scope first: $("#main *").filter(":header") or use h1, h2, …, h6.
scope
Page-wide by default
Without a context, you also pick nav/footer headings. Scope when you mean “article only.”
css
Not valid in plain CSS files
:header works in jQuery only. Stylesheets need h1, h2, h3, h4, h5, h6.
Compatibility
Browser Support
:header has been part of jQuery since 1.2. It works in every browser that runs your loaded jQuery version — it is implemented by jQuery, not by the browser’s CSS engine.
✓ Stable · jQuery 1.2+
jQuery :header
Supported across jQuery 1.x, 2.x, and 3.x. Prefer a current jQuery 3.x build. For native CSS speed, use h1–h6 lists instead.
100%With jQuery
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
:headerUniversal
Bottom line: Safe everywhere jQuery runs. Remember it is a jQuery extension — scope or filter for best performance on large DOMs.
Analysis
Performance Notes
Approach
Cost
Best for
$("h1, h2, h3, h4, h5, h6")
Fastest
Native CSS path
$("#el *").filter(":header")
Fast
Scoped jQuery-extension use
$(":header") page-wide
Slower
Small pages / quick demos
Official guidance: select with pure CSS first, then .filter(":header"), so you keep the convenience without a full-page extension scan.
Remember
Key Takeaways
Role: one selector for all h1–h6 tags — since jQuery 1.2.
Tags only: ignores styled non-heading elements.
Scope:$("article :header") or .filter(":header").
Extension: not CSS — prefer tag lists when speed matters.
One line::header grabs every real heading tag — short to write, scope or filter when the page is large.
Frequently Asked Questions
:header selects every heading element — h1, h2, h3, h4, h5, and h6. One pseudo-class replaces writing h1, h2, h3, h4, h5, h6 when you need all heading levels. Available since jQuery 1.2.
No. :header only matches real h1–h6 tags. A div with class "title" or a bold paragraph is not a header unless it uses a heading tag.
No. It is a jQuery extension and cannot use the native querySelectorAll() boost. The CSS-equivalent selector is h1, h2, h3, h4, h5, h6.
Official docs recommend a pure CSS select first, then .filter(":header"). Example: $("#main *").filter(":header") instead of bare $(":header") on large pages when you only care about one region.
Yes. Prefix with a container — $("article :header") matches only headings inside article elements.
:header matches element type (heading tags). :contains() matches text substrings. :has() matches parents that contain a descendant. They solve different problems.