CodeNewbie Community 🌱


Posted on

Is there a CSS parent selector?

Hello! This is my first post here on the CodeNewbie Forem and I'm kicking it off with a very beginner question. I'd love your thoughts!

Is there any way to select the parent of an element in CSS only?

Thanks 🙏

Top comments (4)

murkrage profile image
Mike Ekkel

Currently there is no way of doing that with just CSS, unfortunately. There is a working draft for the ‘has()’ pseudo-class that does what you are looking for, but browser support is just not there. Read more about it here:

In the meantime: what are you trying to achieve?

reggie_hazel profile image

Thank you so much for this response! I'm trying to work with a menu via a CMS and I can't move the active element to

  • — at least not easily.

    This is helpful, though :)

  • Collapse
    eineki profile image

    Like @murkrage said, you can't do it at the present.

    If you need to style an element when one of his children is focused there is an handy pseudo-class you can actually use. It is supported in all major browser (maybe all)
    You can read more about it here:

    reggie_hazel profile image

    Thank you!!

    Some comments may only be visible to logged-in visitors. Sign in to view all comments.