The :header selector matches every heading element — h1, h2, h3, h4, h5, and h6 — in one jQuery expression. jQuery extension since 1.2; official docs recommend scoping with CSS first, then .filter(":header") for performance.
01
Syntax
:header
02
Tags
h1–h6 only
03
Official
Page styling
04
.filter()
Performance
05
Scope
article :header
06
CSS list
h1, h2, …
Fundamentals
Introduction
Pages often mix six heading levels. When you want to style every heading at once — add a background, unify color, build a table of contents, or attach click handlers — listing h1, h2, h3, h4, h5, h6 every time is repetitive. jQuery’s :header pseudo-class selects all of them in a single expression.
jQuery has supported :header since version 1.2. Official documentation describes it as selecting all elements that are headers, like h1, h2, h3, and so on. Because it is a jQuery extension, prefer $("h1, h2, h3, h4, h5, h6") or $("article *").filter(":header") when you need native selector speed on large documents.
Concept
Understanding the :header Selector
Think of :header as a shortcut for “any heading tag”:
<h1>Title</h1> + :header → matches.
<h3>Section</h3> + :header → matches.
<p>Not a heading</p> + :header → no match.
<div class="title">…</div> styled like a title → no match (not an h1–h6 tag).
💡
Beginner Tip
Do not confuse :header with HTML <header> landmark elements or HTTP headers. This selector only targets h1 through h6 tags.
📋 :header vs tag list, <header>, and other selectors
Heading tags vs landmark elements vs text filters.
:header
$(":header")
h1–h6 tags
Tag list
h1, h2, …, h6
Native CSS
<header>
$("header")
Landmark tag
:contains
h2:contains("Intro")
Text substring
Hands-On
Examples Gallery
Example 1 follows the official jQuery :header demo. Examples 2–5 cover the .filter(":header") pattern, scoped headings, CSS-equivalent lists, and a table-of-contents helper.
📚 Official jQuery Demo
Style every heading with gray background and blue text.
Example 1 — Official Demo: $(":header")
Official jQuery demo — all h1–h6 elements get background #ccc and blue text; paragraphs stay unchanged.
UL#toc prepended with links to each heading
Clicking a link scrolls to the matching h1/h2
How It Works
:header gathers every heading in one pass — ideal for TOC plugins, anchor IDs, and outline navigation.
Applications
🚀 Common Use Cases
Global styling — unify all headings with $(":header").css(...) as in the official demo.
Documentation — build table-of-contents links from every heading.
CMS themes — add anchor IDs to h1–h6 in article bodies only.
Accessibility audits — count headings with $(":header").length.
Print styles — add page-break rules to all heading levels at once.
Performance — scope with CSS, then .filter(":header") on large pages.
🧠 How jQuery Evaluates :header
1
Build candidate set
Evaluate any prefix — e.g. all elements, or descendants of article.
Query
2
Test tag name
Keep elements whose node name is h1, h2, h3, h4, h5, or h6.
Filter
3
Preserve order
Return headings in document order — top to bottom as they appear in the DOM.
Sort
4
✓
Return collection
Chain .css(), .each(), or .on() on every heading at once.
Important
📝 Notes
Available since jQuery 1.2 — jQuery extension, not native CSS.
Matches h1, h2, h3, h4, h5, and h6 only — not <header> landmark elements.
CSS equivalent: h1, h2, h3, h4, h5, h6.
Prefer $("region *").filter(":header") over bare $(":header") on large documents per official docs.
Combine with descendant scope — article :header, #main :header.
Not related to HTTP headers or jQuery .header() (no such method).
Compatibility
Browser Support
The :header pseudo-class is a jQuery extension and works in jQuery 1.2+. It runs through Sizzle/jQuery’s selector engine, so behavior is consistent wherever jQuery runs. Use h1, h2, h3, h4, h5, h6 when you need native querySelectorAll without jQuery.
✓ jQuery 1.2+ · extension
jQuery :header Selector
Use h1–h6 tag lists for native CSS; use :header for concise jQuery collections.
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
:headerExtension
Bottom line: Scope with CSS first, then .filter(":header") on large pages.
Wrap Up
Conclusion
The :header selector matches every heading element — h1 through h6 — in one expression. The official demo applies background and text color to all headings on the page.
Use it for global heading styles and table-of-contents helpers, scope it with container selectors, and prefer .filter(":header") after a CSS scope when performance matters.
Prefer .filter(":header") after a CSS region selector
Use h1, …, h6 when you need native querySelectorAll
Combine with .each() for TOC and anchor generation
Pick specific levels (h2) when you only need one
❌ Don’t
Confuse :header with <header> landmark tags
Expect styled divs to match — only h1–h6 tags count
Run bare $(":header") on huge DOM trees unnecessarily
Use :header in native CSS stylesheets — it is jQuery-only
Confuse with :contains() or :has() — different filters
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :header
All heading tags in one selector.
5
Core concepts
H01
:header
h1–h6 tags
API
602
Levels
All six
Rule
.filter03
Performance
Scope first
Tip
demo04
Official
.css() all
Demo
h1…h605
CSS list
Native alt
Compare
❓ Frequently Asked Questions
:header selects every heading element in the matched set — h1, h2, h3, h4, h5, and h6. One pseudo-class replaces writing h1, h2, h3, h4, h5, h6 when you need all heading levels at once. Available since jQuery 1.2.
No. :header only matches actual h1–h6 tags. A div with class "title" or a p with bold text is not a header unless it uses a heading tag.
No. It is a jQuery extension and does not work in native querySelectorAll(). The CSS-equivalent selector is h1, h2, h3, h4, h5, h6.
Official jQuery docs recommend selecting with a pure CSS selector first, then narrowing with .filter(":header"). Example: $("article *").filter(":header") instead of bare $(":header") on huge pages when you only care about one region.
Yes. Prefix with a container — $("article :header") matches only headings inside article elements. $("section.main :header") adds a class filter too.
:header matches element type (heading tags). :contains() matches visible text substrings. :has() matches parents that contain a descendant. They solve different problems.
Did you know?
HTML5 introduced the <header> landmark element for page sections, but jQuery’s :header predates it and still only matches h1–h6 tags. To style a landmark region, use $("header") — the element selector — instead.