Re: [csswg-drafts] [css-images] Behaviour of SVG degenerate aspect-ratios (#6286)

In Servo, the natural aspect ratio of an svg is:
 
```rs
        let ratio = if let (Some(width), Some(height)) = (width, height) {
            if !width.is_zero() && !height.is_zero() {
                Some(width.px() / height.px())
            } else {
                None
            }
        } else {
            svg_data.ratio_from_view_box()
        };
```

That is, no natural ratio when `width` or `height` are present, even if they are zero. I guess I got this logic from Firefox.

I have no problem aligning with Blink, it actually seems simpler:

```rs
        let ratio = match (width, height) {
            (Some(width), Some(height)) if !width.is_zero() && !height.is_zero() => {
                Some(width.px() / height.px())
            },
            _ => svg_data.ratio_from_view_box(),
        };
```

The other difference with Blink is that if there is no natural width, we fall back to 300px, and then this is the size that we transfer thru the aspect ratio. Which I guess it's a bug, because then we ignore the natural height.

-- 
GitHub Notification of comment by Loirooriol
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6286#issuecomment-3887668884 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 11 February 2026 22:50:16 UTC