:heading-function() CSS Pseudo Class
The :heading() pseudo-class matches headings of the levels you list, such as :heading(2, 3).
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
1or2, 3.
Example
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.
Desktop





Tablets & Mobile





