@matuzo from memory when I saw this pop up a while back, essentially –
someone wrote it like that in the spec and here we are.
@sturobson @matuzo But is it top root? I thought it was encapsulated?
So if I create a component with :root it doesn't leak to parent :root? Or did I miss something?
@matuzo cuz we think it's the top most node that will reach to all items in the page... but nope
i put mine on html instead of :root so they're easy to overwrite
there's been CSSWG chatter about a new location that would be true root and would be available to all elements AND pseudo elements. but it's not complete.
@matuzo A few reasons I can think of:
- Only the root element updates root units (rem). If that root font size relies on a design token, it's needed on html.
- If properties (eg direction, writing-mode, background, overflow) need to propagate to the viewport, they should be set on html instead of body.
- If html is a container, it can be queried by the body.
Those may only require a small subset of custom props, but once you start… are there any reasons not to use the root element?
@mia cool, thanks. I need some time to digest that. :)
I mean, I don't really have reason not to use it, but if I want to do something like in this CodePen it feels strange to change the variables I've originally defined on :root, on body.
@matuzo You will be surprised but many people thing they should be defined inside :root . They think it won't work otherwise.
like @sturobson said, one person did it on root and everyone is following thinking its how it works.
I almost never define them inside root