I have a website with a responsive theme optimized for mobile.

Despite that, many pages don't pass the "mobile-friendly test" from Google (https://search.google.com/test/mobile-friendly)

Here is the result of the validation attempt on Google's tool:

The reasons why the validation fail are: text too small; clickable elements too close (the reasons why the validation fail are: text too small; clickable elements too close to each other)

I've found out that all the pages of my site unable to pass this test contain an embedded YouTube video.

If I remove the video, each of these pages passes the test.

The video is added with the following code:

 <div class="video-container">
     <iframe width="853" height="480" src="https://www.youtube.com/embed/UbtGFrUpri4"
     frameborder="0" allowfullscreen></iframe>

The CSS is:

.video-container {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;

.video-container iframe,
.video-container object,
.video-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

The video scales responsively on my mobile device.

My question is: is there a way to have my page mobile-friendly embedding a YouTube video?

Also I would be curious to know whether it's normal that Googlebot doesn't parse CSS and JS, and shows the "your browser doesn't support this feature" snippet instead of the video.

2 Answers 2


Ok, this was tricky because Google's suggestions are deceitful: Google talks about "clickable elements too close to each other" and "small text", but looking at the screenshot, the problem is that the video container is too big (despite the responsive wrapper).

Considering that there's an error type in the tool called "content bigger than the screen", I have no idea why Google didn't make this case fall into this category.

Anyway, forget about small text, forget about the fact that the actual video is scaling responsively on any actual mobile phone: Googlebot will see a large iframe going off-screen, marking your site mobile-unfriendly.

The only solution I found was to remove the width and height attribute in the HTML code of the iframe. In other words, you have to alter the normal youtube embedding code that will now look like this:

 <iframe src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0" allowfullscreen>

This lets me pass the mobile friendly test on all the offending pages.

Hopefully, the removal of the height and width attributes won't create any problems to the normal output of the video for normal browsers.

Let me know if you have a better solution or think it could cause any issues.

  • 1
    That shouldn't cause any issues. The iframe is still constrained by the container which defines its size. If this is what is taken to get Google to accept their own ruddy code, then that's what it takes. Commented Nov 22, 2019 at 12:09
  • Perfect solution. If somebody is using bootstrap framework then use responsive class for embed. No need to worry about custom height & width getbootstrap.com/docs/4.0/utilities/embed
    – Keyul
    Commented May 25, 2020 at 0:18

I can't read the language the report is in, but I am guessing from what I can gather that the reason is that the default YouTube embed method involves an iframe which is a default number of pixels.

While this is fine for a computer's browser to handle, it's not best practice for mobile devices. It is possible to embed in a responsive way, so that the video is scaled to the screen and the content around it.

If you're comfortable with writing the CSS or JS requires, CCS-Tricks have a couple of workable solutions which should resolve your issues.

This is their suggestion for doing this with CSS to force the video into a responsive window.

<div class="videoWrapper">
    <!-- Copy & Pasted from YouTube -->
    <iframe width="560" height="349"
 frameborder="0" allowfullscreen></iframe>

Using this CSS to style the container.

.videoWrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 25px;
    height: 0;
.videoWrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

An alternative uses jQuery to dynamically resize the video.

// Find all YouTube videos
var $allVideos = $("iframe[src^='//www.youtube.com']"),

    // The element that is fluid width
    $fluidEl = $("body");

// Figure out and save aspect ratio for each video
$allVideos.each(function() {

    .data('aspectRatio', this.height / this.width)

    // and remove the hard coded width/height


// When the window is resized
$(window).resize(function() {

  var newWidth = $fluidEl.width();

  // Resize all videos according to their own aspect ratio
  $allVideos.each(function() {

    var $el = $(this);
      .height(newWidth * $el.data('aspectRatio'));


// Kick off one resize to fix all videos on page load

Alternatively, if you're not comfortable with implementing these, a service such as EmbedResponsively would handle everything for you. I can't personally attest to how robust this solution is as I've not used it, but it is the first Google result for YouTube embed responsive.

  • thanks, unfortunately i had already implemented a similar solution, and the video is indeed scaling nicely on mobile. My question was edited because it contained a link, but I think it's helpful so here it is again: areammo.it/sparatutto/news/… Also I've edited the original question with more details.
    – Sifro
    Commented Nov 22, 2019 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.