Difference between `:open` and `[open]`

I've just realized that :open is not supported on Safari. From what I can tell the [open] attribute selector should be a drop-in replacement (at least for my use case, styling a <dialog>). Can't find anything backing that up aside from Google's AI summary when I search for it. Does that seem right?
9 Replies
ἔρως
ἔρως3w ago
[open] is a property :open is a pseudo-class it means that xyz[open] will match xyz, but xyz:open won't that is for something like <xyz open>
davidhurwich
davidhurwich3w ago
what he said :this:
ἔρως
ἔρως3w ago
https://developer.mozilla.org/en-US/docs/Web/CSS/:open there are more differences but it's not a whole lot more than what i said
capt_uhu
capt_uhu3w ago
the MDN article for <details> has a note about this: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/details
No description
ἔρως
ἔρως3w ago
you can also use the open attribute in other elements - it doesn't have an effect, but you can the :open won't match those as they don't have an open state
capt_uhu
capt_uhu3w ago
:open might be relatively new? unfortunately browser implementation of details/summary has been a bit of a mess
ἔρως
ἔρως3w ago
it is very new exactly 6 months old
Pete (he/him)
Pete (he/him)OP2w ago
Thanks! I mostly wanted to know, for my use case, if I can use dialog[open] as a replacement for dialog:open, it seems like I can
ἔρως
ἔρως2w ago
you should use dialog[open] for a few years

Did you find this page helpful?