Add video as background in webpage? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Add video as background in webpage?

I want to add video as background. How can I do that using only HTML and CSS?

19th Dec 2016, 7:52 PM
Md. Omar Sohrab Hossain
Md. Omar Sohrab Hossain - avatar
3 Answers
+ 1
Is it a long video or short? If short you could transform it to a gif
19th Dec 2016, 7:57 PM
R P
R P - avatar
+ 1
I would like to know this too!
19th Dec 2016, 8:37 PM
John Doe
+ 1
If you are using HTML5 they added <video> command which allows you to insert a video in your website. Example : <video playsinline autoplay muted loop poster="example.jpg" id="exampleID"> /* ONLY ONE OF THESE 2 IS NEEDED <source src="example.webm" type="video/webm"> <source src="example.mp4" type="video/mp4"> */ </video> Than you can style it with CSS : video#example { position: fixed; top: 50%; left: 50%; min-width: 100%; min-height: 100%; width: auto; height: auto; z-index: -100; -ms-transform: translateX(-50%) translateY(-50%); -moz-transform: translateX(-50%) translateY(-50%); -webkit-transform: translateX(-50%) translateY(-50%); transform: translateX(-50%) translateY(-50%); background: url(example.jpg) no-repeat; background-size: cover; } CSS is for placing it in the back and controlling some of its features.
19th Dec 2016, 9:46 PM
Lummos
Lummos - avatar