Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Implement Bootstrap Responsive Video

DZone's Guide to

How to Implement Bootstrap Responsive Video

If you're new to web development, check out this article on how utilize Bootstrap to create responsive videos on your web page.

· Web Dev Zone ·
Free Resource

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

If you are using any video on your website make sure they are responsive. A responsive video very well adapts to the screen size of the user.

In this tutorial, you will learn how to implement Bootstrap Responsive Video in your website.

How to Put Videos on a Website

Mostly we use the video tag to put a video on a website. The video tag is:

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
</video>

However, we can also embed videos from third party websites like Youtube and Vimeo.

In Youtube, click the “Share” button then the “embed” button to copy the embed code. To show this video in your website simply paste this embed code into your web page and that’s all, this video will show up and run whenever that page is opened in a browser.

In the below picture I have marked how to copy the Video’s embed code from Youtube.

how to get embed video code in youtube

Bootstrap Responsive Code

In Bootstrap the video should be placed in two ways – an aspect ratio of 16:9 or 4:3. The code for this is:

<!-- 16:9 aspect ratio --> 
<div class="embed-responsive embed-responsive-16by9"> 
    //add video code 
</div> 

<!-- 4:3 aspect ratio --> 
<div class="embed-responsive embed-responsive-4by3">
    //add video code
</div>

Note: there is a prerequisite that you should know how to use bootstrap on your website so that you know how to create a bootstrap grid and where to place the video in the grid system.

So if you want to place a video tag then the above code will become:

<!-- 16:9 aspect ratio --> 
<div class="embed-responsive embed-responsive-16by9"> 
    <video width="320" height="240" controls>
        <source src="movie.mp4" type="video/mp4">
    </video>
</div> 

<!-- 4:3 aspect ratio --> 
<div class="embed-responsive embed-responsive-4by3">
    <video width="320" height="240" controls>
        <source src="movie.mp4" type="video/mp4">
    </video>
</div>

In the same way, if you are using a Youtube embed code for a video then the Bootstrap Responsive Video Code will become:

<!-- 16:9 aspect ratio --> 
<div class="embed-responsive embed-responsive-16by9"> 
    <iframe width="560" height="315" src="https://www.youtube.com/embed/VS6UOyTb5eU" 
frameborder="0" allowfullscreen></iframe>
</div> 

<!-- 4:3 aspect ratio --> 
<div class="embed-responsive embed-responsive-4by3">
    <iframe width="560" height="315" src="https://www.youtube.com/embed/VS6UOyTb5eU" 
frameborder="0" allowfullscreen></iframe>
</div>

Testing Bootstrap Responsive Video

Let me show you how this responsive video will look in different screen sizes.

a. Responsive Video in Smartphones

responsive video in smarphones



b. Responsive Video in Tablets

responsive video in tablets

c. Responsive Video in Laptops

responsive video in laptops

You can check this DEMO HERE

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

Topics:
bootstrap ,html ,css ,responsive web design ,web dev

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}