Re: [csswg-drafts] [css-env] Adding custom env() variables (#2627)

@clarfonthey 

> This is also why @env personally makes the most sense to me as a syntax, rather than @constants or something else -- it makes it clear that we're defining envs instead of vars. If we relied on :root, it would confusingly define both an env and a var, and then people would start to conflate the two.

I think part of the issue @ghost is pointing out is that an env variable would theoretically be global for the environment (the window), which could lead you to the same types of problems when we used to do global vars in JavaScript, which is global pollution but also naming clashes. Probably an explicit import would be preferable, which maybe points to a 3rd type of variable, or a way to define importable local variables, similar to what @jonathantneal originally posted, but combined with the syntax that @ghost mentioned.

As in:
```css
// vars.css
@var --breakpoint-s 320px;
```
```css
// main.css
@import "vars.css" --breakpoint-s;
@media screen and (min-width: var(--breakpoint-s, 300px)) {
    body {
       background: red;
    }
}
```
It maybe has some confusion about _where_ the value would be available, or which var could be used where, but other languages also have scoping rules for variable access. Otherwise there might have to be a third "variable" construct.

-- 
GitHub Notification of comment by matthew-dean
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/2627#issuecomment-1472307821 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 16 March 2023 16:30:50 UTC