Csswg-drafts: [css-cascade] !default declarations proposal

Created on 4 Feb 2018  路  2Comments  路  Source: w3c/csswg-drafts

!default declarations, opposite to !important declarations, could set a default property value, if it has not been set yet, or if another !default declaration is more specific. User agent styles should be overridden with !default (of course excluding ones with !important).

Consider this example:

<body class="default-theme new-theme">
  <button>Style me!</button>
</body>
.new-theme button {
  border: thin solid black;
}

button {
  border: 1px dotted grey !default;
}

.default-theme button {
  border: none !default;
}

The button would have a thin solid black border in result. Having the !default declaration possible would make it so much easier to do theming or reset CSS.

css-cascade-5

Most helpful comment

Just want to point out some implications of using !default vs. :is():

  • !default takes the specificity into account, :is() does not
  • !default applies to individual properties, :is() to the whole rule
  • Both keep the effects of the !important annotation untouched

Sebastian

All 2 comments

I don't like !important very much, and this would be a similar hack. And I don't think it's necessary, because you should be able to achieve a similar behavior by using selectors with 0 specificity (#1170), e.g.

:is(.default-theme button) {
  border: none; /* default */
}

Just want to point out some implications of using !default vs. :is():

  • !default takes the specificity into account, :is() does not
  • !default applies to individual properties, :is() to the whole rule
  • Both keep the effects of the !important annotation untouched

Sebastian

Was this page helpful?
0 / 5 - 0 ratings