Skip to content

[css-cascade-4] Add an alias to !important #9778

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

Closed
francescorn opened this issue Jan 10, 2024 · 8 comments
Closed

[css-cascade-4] Add an alias to !important #9778

francescorn opened this issue Jan 10, 2024 · 8 comments

Comments

@francescorn
Copy link
Contributor

francescorn commented Jan 10, 2024

css-cascade-4

! is the logical not operator. When adding ! in front of important, it should mean it is not important, as in not taking precedence.

* would make more sense to be in front since it covers all of the elements.

My proposed task would be to:

  1. Add an alias for !important such as *important because it is closer to meaning more/most important of all elements.
@francescorn francescorn changed the title [css-cascade-4] Rename and reassign !important [css-cascade-4] Add an alias to !important Jan 10, 2024
@Loirooriol
Copy link
Contributor

! is the logical not operator

CSS doesn't have a logical not operator

Add an alias for !important

At this point it doesn't seem feasible to deprecate !important, so adding an alias will just increase confusion IMO.

*important

That's problematic, because that's valid in a <declaration-value>. But a top-level ! is not, so it can act as a delimiter.

In particular, this would break:

document.body.style.cssText = "--foo: bar*important";
document.body.style.getPropertyValue("--foo"); // "bar*important"

@Loirooriol Loirooriol added the css-cascade-4 Current Work label Jan 10, 2024
@astearns
Copy link
Member

It definitely is confusing, and on our list of mistakes.

It might be possible to come up with an alias that works better, but I expect this would need to be a longer keyword instead of adding some special character. And I’d like the new thing to make it more clear how important declarations interact with origins and contexts https://www.w3.org/TR/css-cascade-4/#cascade-origin

@francescorn
Copy link
Contributor Author

francescorn commented Jan 10, 2024

What about mostImportant or moreImportant?

@francescorn
Copy link
Contributor Author

@fantasai @litherum What are your thoughts on a better alias name?

@litherum
Copy link
Contributor

I’m categorically against aliases.

  • They have maintenance cost for implementers
  • They don’t offer authors any functionality that they didn’t have before
  • The web is the biggest platform in the world. As such, it is totally capable of defining its own conventions.

@Crissov
Copy link
Contributor

Crissov commented Jan 11, 2024

Do XML and HTML get the same kind of comments for having <!DOCTYPE and <!--?

@francescorn
Copy link
Contributor Author

What about important/importance or priority? Maybe we can add number priorities/importance such as first-priority, second-priority, third-priority etc. or add a number attached such as priority-1, priority-2, priority-3... etc. Or important-1, important-2, important-3, important-4... etc.

Or we could also maybe assign them in categories with 3 importances/priorities such as: high-importance, medium-importance, low-importance. Or high-priority, medium-priority, low-priority.

@tabatkins
Copy link
Member

Yes, I'm just going to close this issue. !important, while historically somewhat confusing, is decades old and long-established at this point. It's not used often, and when it is, it's rather obvious that the property isn't "not important", since it wins over most other things.

As noted, there are also parsing concerns with using any other character besides ! at this point, due to custom properties accepting any syntax.

Aliases are something we very intentionally use only rarely, when the previous name is just actively bad for some reason. (For example, some -webkit-* prefixed properties that became necessary for the web ended up aliasing a proper standardized name.)


For the separate issue of wanting more levels of "importance", that's what we designed Cascade Layers for. We don't anticipate expanding !important itself, and in general !important can be better replaced by Cascade Layers. (Tho we do reserve the right to add additional !-prefixed things in the future, if we find something that requires it.)

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

No branches or pull requests

6 participants