:heading CSS Pseudo Class
The :heading pseudo-class matches all heading elements, h1 to h6.
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
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.
Desktop





Tablets & Mobile





