Favorites

:heading CSS Pseudo Class

:heading
CSS Pseudo ClassThis pseudo class is supported in some modern browsers, but not all.
Updated 22nd November 2026

The :heading pseudo-class matches all heading elements, h1 to h6.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

Description

The :heading pseudo-class matches every element that is a heading: the h1 to h6 elements. It is a shorter way of writing h1, h2, h3, h4, h5, h6 and is defined in the Selectors Level 5 draft.

:heading {
  font-family: Georgia, serif;
  color: #2c3e50;
}

Two details differ from the long list of type selectors. First, :heading has the specificity of a pseudo-class (0-1-0, like a class) rather than of a type selector (0-0-1), so :heading beats h2 in the cascade. Second, it only matches elements that are headings in HTML; an element such as <div role="heading"> is not matched, so use an attribute selector for those.

To target only some levels, use the functional form :heading(), for example :heading(1, 2). Support is still limited, so keep a fallback such as h1, h2, h3, h4, h5, h6 in a separate rule.

Syntax

:heading {
  /* ... */
}

Example

<h1>Mastering CSS</h1>
<h2>Chapter 1: Selectors</h2>
<p>A selector describes which elements a rule applies to.</p>
<h3>1.1 Pseudo-classes</h3>
<p>Pseudo-classes select elements based on state or position.</p>
body {
font-family: system-ui, sans-serif;
}

/* Every heading level, in one selector */
:heading {
color: tomato;
font-style: italic;
border-left: 4px solid tomato;
padding-left: 8px;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS :heading pseudo class. Hover over a browser icon to see the version that first introduced support for this CSS pseudo class.

This pseudo class is supported in some modern browsers, but not all.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee