csswg-drafts icon indicating copy to clipboard operation
csswg-drafts copied to clipboard

[css-variables-2][css-properties-values] Constants in CSS

Open Que-tin opened this issue 1 year ago • 2 comments

Is there a reason that we don't constants in CSS yet?

I was looking trough the open issues and couldn't find a single one asking for it.

e.g. for stuff like font-families or theme independent colors like brand colors it would be great to have something like this to make sure they don't get overwritten.

The syntax could be similar to custom properties by replaying - with _ so __*. These should also be allowed in @property definitions.

I'm not 100% sure whether there should also be a new function to access these constants or whether the underscore are enough to differentiate the two when using var() for both. Open for discussion.

Que-tin avatar May 07 '24 14:05 Que-tin

Try closed issues as well.

PS: #6099 for instance.

Crissov avatar May 08 '24 00:05 Crissov

Closest I've seen is "custom env", https://github.com/w3c/csswg-drafts/issues/2627#issuecomment-386932374.

There are also a few proposals for registering a bunch of custom properties (and their initial values) in a less verbose way.

make sure they don't get overwritten

Does that mean you want the first rule that sets a constant to determine the value, and any further attempts to (re)set the value should be ignored? E.g.:

@env { --foo: 10px; }
@env { --foo: 20px; }
div {
  width: env(--foo); /* --10px */
}

andruud avatar Jun 12 '24 21:06 andruud