Skip to content

[css-properties-values-api] Make initial-value descriptor optional #1109

Open
@LeaVerou

Description

@LeaVerou

Currently writing @property rules is fairly verbose and repetitive. All three descriptors are mandatory, and often forgotten, causing hard to debug bugs.

It’s unfortunate that inherits cannot be optional since the only default value that makes sense is also the slowest, but what about initial-value?

I think we can compute a sensible initial value for any syntax string except * (in which case it should be mandatory). In addition to making code shorter, it is often nontrivial to specify a suitable, computationally independent initial value (e.g. for <image>, especially before image() is implemented).

In some cases there is no obvious initial value, but that is a problem for authors as well: there should be a suitable initial value for each value type. If there isn't, it's a bug with the value type.

  • <url>. Built-in CSS properties solve this by accepting a keyword as well (e.g. none).
  • <transform-function>: what if we added none as a value? It would be compatible with existing properties, and would mean authors wouldn't need to keep doing <transform-function> | none
  • <transform-list>, see above

The other elementary types are pretty straight forward:

  • 0 for <number> and <integer>
  • 0{unit} for any dimension type (<length>, <angle>, <percentage>, <length-percentage> etc)
  • transparent for <color>
  • image(transparent) for <image>
  • keyword → itself

For more complex syntax constructs, a suitable initial value can be generated recursively:

  • A | BA
  • A+A
  • A# → A

cc @tabatkins

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions