Favorites

:heading-function() CSS Pseudo Class

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

The :heading() pseudo-class matches headings of the levels you list, such as :heading(2, 3).

☕
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() functional pseudo-class matches heading elements of the levels you list. It takes a comma-separated list of integers: :heading(1) matches level-one headings, and :heading(2, 3) matches level-two and level-three headings. It is defined in the Selectors Level 5 draft.

:heading(1, 2) {
  color: tomato;
}

:heading(3, 4, 5, 6) {
  color: slateblue;
}

The level is the one the browser exposes for the heading, which is normally the number in the tag name (<h3> is level 3). The HTML headingoffset proposal lets a section shift the levels of the headings inside it, and :heading() follows the shifted level, so h1:heading(3) can match an <h1> that is exposed as a level-3 heading. Elements with role="heading" and aria-level are not matched.

Like :heading, it has the specificity of a class (0-1-0). Support is still limited, so provide a fallback with normal type selectors.

Syntax

:heading(<integer>#) {
  /* ... */
}

Values

  • <integer>#One or more comma-separated integers giving the heading levels to match, for example 1 or 2, 3.

Example

<h1>Heading level 1</h1>
<h2>Heading level 2</h2>
<h3>Heading level 3</h3>
<h4>Heading level 4</h4>
body {
font-family: system-ui, sans-serif;
}

/* Levels 1 and 3 */
:heading(1, 3) {
color: tomato;
}

/* Levels 2 and 4 */
:heading(2, 4) {
color: slateblue;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS :heading-function() 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