Sometimes, we want to get HTML5 video element dimensions with JavaScript.
In this article, we’ll look at how to get HTML5 video element dimensions with JavaScript.
How to get HTML5 video element dimensions with JavaScript?
To get HTML5 video element dimensions with JavaScript, we can use the videoHeight and videoWidth properties.
For instance, we write
<video id="foo" src="foo.mp4"></video>
to add a video element.
Then we write
const vid = document.getElementById("foo");
const height = vid.videoHeight;
const width = vid.videoWidth;
to select the video element with getElementById.
And then we get the intrinsic video height and width with videoHeight and videoWidth.
Conclusion
To get HTML5 video element dimensions with JavaScript, we can use the videoHeight and videoWidth properties.