Sometimes, we want to get the width and height of an HTML5 canvas with JavaScript.
In this article, we’ll look at how to get the width and height of an HTML5 canvas with JavaScript.
How to get the width and height of an HTML5 canvas with JavaScript?
To get the width and height of an HTML5 canvas with JavaScript, we use the width
and height
properties.
For instance, we write
const { width, height } = document.getElementById("mycanvas");
to get the canvas with getElementById
.
Then we get its width
and height
properties from the element returned.
Conclusion
To get the width and height of an HTML5 canvas with JavaScript, we use the width
and height
properties.