44

I'm trying to validate my website with the W3C validator but it doesn't work. I have a YouTube iframe and this is the error:

The frameborder attribute on the iframe element is obsolete. Use CSS instead.

Screenshot:

enter image description here

And this is my index.html (cropped):

<!-- Video -->
<div class="video-container box-size">
  <iframe width="700" height="312" src="http://www.youtube.com/embed/OfUPsnAtZMI" frameborder="0" allowfullscreen></iframe>
</div>

How can I correct it?

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
  • Does this answer your question? [HTML5 and frameborder](https://stackoverflow.com/questions/3601273/html5-and-frameborder) – BuZZ-dEE Jun 29 '20 at 09:15

5 Answers5

67

As they state themselves "The frameborder attribute is not supported in HTML5. Use CSS instead."

The equivalent of frameborder in css is border: 0px;. Add it to your iframe in css.

user2950291
  • 694
  • 6
  • 7
  • 4
    according to answer for [question] (http://stackoverflow.com/questions/3601273/html5-and-frameborder) you can replace `frameborder` in css with `border: none;` – ahmed hamdy Mar 26 '15 at 13:27
  • 3
    Furthermore, `border: 0px` should otherwise be `border: 0` – Thomas Williams Sep 12 '20 at 10:00
  • "should" is not true. It could be `border: 0`, but `border: 0px` is [perfectly fine](https://stackoverflow.com/a/16484713/735926). – bfontaine Aug 31 '23 at 08:58
16

Your HTML5 markup contains an <iframe> element with a frameborder attribute in the form:

<iframe frameborder="0" … />

This attribute is no longer present in HTML5. Use CSS instead:

<iframe style="border:0;" … />

Source: Frameborder is obsolete

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Abhishek Agarwal
  • 1,190
  • 2
  • 19
  • 38
10

This works in your css

iframe{
    border-width: 0px;
}
Harry Bosh
  • 3,611
  • 2
  • 36
  • 34
0

You can use hidden as border-style or none.

I made this to show the difference:

const button = document.getElementById("submit");
const hidden = document.getElementById("hidden");
const none = document.getElementById("none");
const solid = document.getElementById("solid");
const iframe = document.getElementById("iframe");
const error = document.getElementById("error")
button.addEventListener("click", function() {
  if (hidden.checked) {
    iframe.style.borderStyle = "hidden";
  } else if (none.checked) {
    iframe.style.borderStyle = "none";
  } else if (solid.checked) {
    iframe.style.borderStyle = "solid";
  } else {
    error.textContent = "Choose the border then click Apply";
    setTimeout(function(){ error.textContent = "" },1000);
  }
});
#iframe {
  border-style:solid;
}
#error {
color:red;
font-size:larger;
}
<div align="center">
  <iframe id="iframe" allowfullscreen="allowfullscreen"></iframe>
  <br />
  <input type="radio" name="mode" id="hidden"><label for="hidden">Hidden border</label>
  <input type="radio" name="mode" id="none"><label for="none">No border</label>
  <input type="radio" name="mode" id="solid"><label for="solid">Solid border</label>
  <br />
  <button id="submit">Apply</button>
  <div id="error">
  </div>
</div>
bfontaine
  • 18,169
  • 13
  • 73
  • 107
Justin Liu
  • 581
  • 6
  • 21
0

I have a manual workaround which is to remove the frameborder="0" attribute by adding the code in the post admin.

   <iframe title="K8 ký kết hợp đồng chính thức với Manchester City" src="https://www.youtube.com/embed/mNBbhn_pJik?feature=oembed" width="640" height="360" allowfullscreen="allowfullscreen"></iframe>

remove frameborder