- Home /
WebGL output scale to fit browser window even when window changes aspect ratio
I can't get a webGL object output from Unity to scale in both directions when a user change the window size in the browser.
It will scale perfectly when the height of the window is scaled, but when the width is scaled, the WebGL content isn't scaled with it.
Here is an example of what it is doing right now.
here is an example of what I want it to do (though slapped together with video editing software to show what I'm after)
If anyone has had this problem and solved it, it would be great to hear from them, I've ran a bunch of searches, here, on other sites, and just using search engines. I've come across a few things that claim to have done it, but can't find a working example of it, and none of the things I found worked.
I found something that told me to change the CSS in the template, so that width/height said 100%, which I have tried to no avail.
I found something that had a script which detected the window scaling event and changed the canvas size based on this, but that didn't work either.
It seems to be something within Unity itself that I am somehow missing, as though I've told it to only scale the height, or told it that the width is infinite, which makes some sense, as the default blue background can be seen at the sides when the WebGL object scales with the window if you scale the height.
Can anyone help?
Thanks.
Your answer
![](https://koobas.hobune.stream/wayback/20220612093145im_/https://answers.unity.com/themes/thub/images/avi.jpg)