How to canvas width and height in HTML5 with JavaScript?

Spread the love

Sometimes, we want to canvas width and height in HTML5 with JavaScript.

In this article, we’ll look at how to canvas width and height in HTML5 with JavaScript.

How to canvas width and height in HTML5 with JavaScript?

To canvas width and height in HTML5 with JavaScript, we set the width and height properties.

For instance, we write

const [canvas] = document.getElementsByTagName("canvas");
canvas.width = 800;
canvas.height = 600;

to select the canvas with getElementsByTagName and destructuring.

Then we set its width and height by setting the width and height properties.

Conclusion

To canvas width and height in HTML5 with JavaScript, we set the width and height properties.

Leave a Reply

Your email address will not be published. Required fields are marked *