CodeNewbie Community


Is there a CSS parent selector?

When I'm not coding, you can find me at the beach.
・1 min read

I've been working on upping my CSS skills lately and came across of the question whether or not there are CSS parent sectors - and I haven't been able to figure this one out.

Anyone got some wisdom to impart?

Discussion (3)

alvaro_montoro profile image
Álvaro Montoro • Edited

There isn't an explicit parent selector, but in the CSS selectors of level 4, it is defined the :has() pseudo-class which allows to select an element based on the selectors passed to the :has(). That would allow to select an element based on their children, providing a "parent" selector (e.g. div:has(> img) would select the div that is a direct parent of an img)... Unfortunately, it is not supported by any browser at the moment.

ender_minyard profile image
ender minyard

No, there is no CSS parent selector.

jasonbraganza profile image
Jason Braganza

W3Schools lists the element>element selector.

is this along the lines of what you were looking for?