Skip to content

[css-properties-values-api] Allow custom properties to be used for initial-value inside @property #1140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ianthedev opened this issue Mar 22, 2025 · 1 comment

Comments

@ianthedev
Copy link

If I define a custom property explicitly with the @property at-rule by using a straightfoward color value for initial-value, it works. Working example below:

@property --my-color1 {
    syntax: "<color>";
    initial-value: magenta;
    inherits: false;
}

But if I use a previously defined custom property for initial-value, it does not work. Not-working example below:

:root {
    --color-primary: magenta;
}

@property --my-color1 {
    syntax: "<color>";
    initial-value: var(--color-primary);
    inherits: false;
}

Please allow the not-working example to work. It kinda defeats the purpose of custom properties if we still have to write their values after defining them (inside @property, in this case).

The reason for involving @property in this case is to animate CSS gradient, as illustrated in this Stack Overflow answer. Such an animation/transition normally wouldn't work without @property.

@jedrichards
Copy link

jedrichards commented May 18, 2025

Furthermore, you cannot even use one @property variable as an input to another, even if defined with @property

@property --foo {
  inherits: true;
  initial-value: red;
  syntax: '<color>';
}

@property --bar {
  inherits: true;
  initial-value: var(--foo); // ❌ Invalid
  syntax: '<color>';
}

So it becomes quite tricky to build up a set of variables (say for a design system) that may reference each other, without duplicating information in :root

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants