Skip to content

[css-values-4] Ratio of 0/0? #4954

Closed
Closed
@tabatkins

Description

@tabatkins

So, the old <ratio>, since it only allowed integers, could meaningfully restrict its values to "greater than zero", so all ratios you could write were meaningful.

Now that we've relaxed it to <number>, we can't do that - can't do open ranges. So 0 is allowed.

And mostly that's fine! A ratio of 0/1 is just infinitely tall; a ratio of 1/0 is infinitely wide; CSS is okay with infinities. The "division results" are well-defined too - 0 and infinity, respectively.

But what about 0/0? We can't reject this at parse-time, since a calc() might be hiding a 0. But it definitely doesn't have a meaning; the division result is NaN.

Two possibilities I see:

  1. Define that it produces an "invalid ratio", and places that take <ratio> have to define what that means. The 'aspect-ratio' property would define that it doesn't give an aspect ratio (same as "none"); the (aspect-ratio) MQs would define that it always fails to match.

  2. Make it act the same as calc(0/0): it produces a NaN, which is censored into an infinity, so it's the same as saying 1/0 for the ratio.

I'm mildly leaning toward option 2. It's more consistent with 0/0 in general, and it means we don't need to ensure that every place that uses <ratio> defines what an "invalid ratio" does.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions