Where developers & technologists share private knowledge with coworkersProgramming & related technical career opportunities Again remember that we are targeting the iframe/object/embed, not video element.The above approach is remarkable, however, it has several feasible obstacles:if either of those limitations practices to you, you might do not forget a javascript solution. By using our site, you acknowledge that you have read and understand our Of course, you can change the aspect ratio to something else but usually, YouTube video comes with the aspect ratio of 16:9.This code will make the iframe full width according to its container. Lest you get awkward to fill the empty area (not like images, the actual video maintains it’s aspect ratio irrespective of the size of the element).To handle this, We will get through CSS and now not worry about what is declared within the HTML5 video tag.Also, you could also use max-height:100% to ensure that you don’t get any vertical scroll. If you have access to the iframe target site as well, you can also write a solution based on the postMessage API to send the inner content height to the parent site. The usage of the Jquery and javascript library, that seems like this:Let’s see what he did in the javascript function to handle the aspect radio of Vimeo video. ; Demo. That means if the body is 100px and the container is 80px if the iframe is in the container the width will be 80px. Featured on Meta I recommend Youtube embed video method because it will not hurt your server load and nor bandwidth, especially if your video files are quite large.I hope you like this article and find it useful to you. I have on my website I want to add a video with the width 100% and the height something like 400px; I tried the following: .container { position: relative; width: 100%; height: 0; It is vital that you take away the height.In order that the aspect ratio of the video is maintained because it grows and shrinks. I wanted to know how to make a youtube video mobile. position: absolute; This will give the iframe a position relative to the wrapper and let it be positioned over the padding of the wrapper.

Just thought someone will be interested in knowing how to embed a YouTube iframe or any 16:9 video (e.g. (For more information you can visit I am not sure how many peoples know that you guys can easily apply media queries to the source element when providing different source files for your embedded video and audio.By adding a valid media query to a video source, we need to specify the following particular source that should use when a device matches the media query.In the above example, you can see file trailer-small.mp4/webm will only load for devices that have a max-width of 480 pixels. Surprisingly, Youtube does not automatically have a responsive embed code. The standard embed code for YouTube uses the IFRAME tag and the width and height of the video player are hard-coded thus making the player non-responsive. Most people might be using a phone to view it and make sure it resizes when the phone move from vertical to horizontal might be important.Here's the code if you don't want to separate JavaScript with HTML:Personally when i have to deal with youtube video embeds i use In short, the code will look like this, remember to load fitVidJs in your pageI've used this system for a few projects so far and never had issues, it also supports other video platforms but i only used it with youtubeThanks for contributing an answer to Stack Overflow! Twitch live widget, Vimeo etc.) top: 0 and left: 0 are used to position the iframe at the center of the container. Viewed 2k times 2. How to embed YouTube iframe video 100% full width. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Just thought someone will be interested in knowing how to embed a YouTube iframe or any 16:9 video (e.g. Very useful trick for displaying responsive (video) embeds. We have a solution from Believe this: while the page hundreds of all videos are checked out and their component ratio is stored. Otherwise, the trailer.mp4/webm file will be loaded.Instead of using an HTML5 video, I highly recommend using an embed video like YouTube or Dailymotion to make them fully responsive.
There won't be going out of the container and mess up with the responsive design.This code will resize the iframe every time the page is loaded or resized, making sure that it is always maintaining the 16:9 aspect ratio. Note that, unlike for many other elements, using right: 0; bottom: 0; instead of width:100%;height:100% will not (always) work as expected for iframes.. When you embed videos from these services, you embed an iframe. Active 5 months ago. With this method, the HTML5 video scale to fit div and element has the maximum width and height will always be used without any scrolling.However, If you want to use video directly on your website then it is a pretty much bad idea. You may use iframe shortcode to embed content from YouTube, Vimeo, Google Maps or from any external page. Definition and Usage. Basically, when you add a video on your website using HTM5 To make an HTML5 video responsive is a little more complex than an image. By doing this, it gives you the ability to maintain aspect ratio. By clicking “Post Your Answer”, you agree to our To subscribe to this RSS feed, copy and paste this URL into your RSS reader. YouTube uses iframes to allow embedded videos, Google uses them for their OAuth2 authentication, and by SaaS companies such as Mailchimp, Typeform and Outgrow to …