How do I match an element containing two matching child elements with CSS?
12:33 29 Mar 2026

I want to make a CSS selector that matches an element which contains both of two specified matching child elements. For example, let's say I want to match a

element that contains both an

element and an element with the .subtitle class.

Header text

Header text

I know that :has() can select containing elements, but specifying two selectors will make it select elements that contain either of the two matching elements rather than both.

selection:has(h2, .subtitle)

How can I select an element only if it contains both of two matching elements?

html css