CSS :has() Selector
Example
Selects h2 elements that are immediately followed by a p element, and applies the style to h2:
h2:has(+p) {
color: gray;
border: 2px dotted red;
}
Try it Yourself »
Definition and Usage
The :has()
selector
is used to select a parent element or previous sibling element, and apply a
style to it.
Version: | CSS4 |
---|
Browser Support
The numbers in the table specifies the first browser version that fully supports the selector.
Selector | |||||
---|---|---|---|---|---|
:has() | 105 | 105 | 121 | 15.4 | 91 |
CSS Syntax
:has(relative-selector-list) {
css declarations;
}