How to Embed a YouTube Video in HTML and Make it Responsive

How to Embed a YouTube Video in HTML and Make it Responsive

By IsraeliPanda

HTML5 has a local <video> label that permits you to remember recordings for your site page by characterizing a source. Nonetheless, there’s a danger the client’s program will not help the configuration of your video, and adding various sources may be a bit of a problem.

Seeing how to implant a YouTube video in HTML can save you a great difficult situation. The stunt is utilizing an iframe rather than the <video> labels:

The iframe represents an inline outline and permits you to install one site page into another – for this situation, a YouTube page. Along these lines, you don’t have to stress over if your record design is upheld.

Bit by bit: How to Embed a YouTube Video

To implant a video from YouTube, open its page and discover the Share button under the video player:

As you click it, you will see a couple of sharing choices, including different online media stages. The absolute first on the rundown is Embed. Snap-on it with your cursor:

YouTube will create a code for you to utilize naturally. The <iframe> label will have the URL of the video source, tallness and weight of the player, and a couple of more characteristics notwithstanding:

For our situation, the code resembled this:

<iframe width=”560″ height=”315″ src=”” frameborder=”0″ allow=”accelerometer; autoplay; scrambled media; gyrator; picture-in-picture” allowfullscreen></iframe>

All you need to do now is click Copy and glue the code into your HTML page.

Modifying a YouTube Video in HTML5

Since you realize how to insert a YouTube video in HTML, you ought to likewise see how to alter the manner in which it works. By adding a few boundaries to the furthest limit of the URL in the installing code, you can influence the conduct of the player. To utilize a boundary, incorporate a question mark (?) toward the finish of the URL, and afterward, add one or numerous boundaries alongside their qualities.

The autoplay boundary permits you autoplay YouTube implanted recordings on your page. Adding autoplay=1 to the URL will make the video begin playing following the principle page and the video loads, while autoplay=0 will not.

The circle boundary allows you to circle the video endlessly or until the client stops it physically. Utilizing loop=1 makes the video begin once more after it closes, while loop=0 implies it will stop in the wake of playing once.

The playlist boundary determines if different YouTube recordings ought to be played consistently in continuous request. This permits you to make an individual playlist on your site.


Have you at any point attempted to make a YouTube video responsive? Assuming this is the case, it very well may be fairly precarious. I went over a little issue while adding a video from YouTube to one of my blog entries about the Childish Gambino site that we made.

Since this site is completely responsive, I required the YouTube video to re-size contingent upon the program size or gadget width. Nonetheless, when I added the install code, the video had decent tallness and width. (ugh!) This looked fine on PCs, however basically broke the plan when seeing on a cell phone. I needed to realize how to make a youtube video portable. Along these lines, we required a responsive YouTube video install code.

One would feel that recordings that with 100% width would naturally resize to the encompassing holder. Indeed, that isn’t the situation. Shockingly, Youtube doesn’t naturally have a responsive insert code.

The fix was very straightforward. Here’s the way to make a youtube video versatile:

You should wrap the responsive youtube implant code with a div and indicate a half to 60% cushioning base. Then, at that point indicate the youngster components (iframe, object implant) 100% width, 100% stature, with the outright position. This will drive the install components to extend fullwidth consequently. Magnificent! Precisely what we need.

First, you should add the accompanying to your template.


  • .video-holder { position: relative; cushioning base: 56.25%; cushioning top: 30px; tallness: 0; flood: stowed away; }
  • .video-compartment iframe, .video-holder object, .video-holder implant { position: total; top: 0; left: 0; width: 100%; tallness: 100%; }
  • Then, alter add some HTML around your implant code.

Note: this responsive youtube implant code has been refreshed in 2020 to be more consistent and follow best practices for installing Youtube recordings for the responsive plans.

%d bloggers like this: