I am trying to simply center video in HTML, how can I do it without using "margin:0 auto", is there any other way to center video using CSS or HTML? Below is my sample HTML
<div>
<video controls>
<source src="video.mp4" type="video/mp4" />
</video>
</div>
Thanks
There are many ways to center a video using HTML, here are few
video.center {
display: block;
margin-left: auto;
margin-right: auto;
}
Fiddle: https://jsfiddle.net/4nupg1a8/
video {
margin-left: 50vw;
transform: translate(-50%);
}
<center>
<video width="400" controls>
<source src="mov_bbb.mp4" type="video/mp4">
Your browser does not support HTML video.
</video>
</center>
Fiddle: https://jsfiddle.net/4th0dpy6/
.container video {
display: flex;
justify-content: center;
}
You can also review this Responsive center image using pure CSS or Bootstrap 3/4 which can be helpful.
Hope it helps.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly