Home > Software design >  Why end tags used on void elements don't break the HTML?
Why end tags used on void elements don't break the HTML?

Time:07-11

I'm new to HTML and I'm not understanding what is "ilegal" to do, if I code the following in C I will have a redefinition error.

int a = 2;
int a = 3;

But for example, in HTML Standard I found: " Void elements only have a start tag; end tags must not be specified for void elements." (source) So I would expect that the following HTML would kinda break:

<html>
<p>hello, insert a name <input> </input> </p>
</html>

But it works just fine, So what is illegal, that you "break" html?

CodePudding user response:

If you run that through https://validator.w3.org/, it will tell you "Error: Stray end tag input." So it really is invalid. Browsers are just really, really lenient of invalid HTML and will always try to keep going and guess what you may have meant.

CodePudding user response:

<frong>HTML</frong> is <fnord/> very forgiving <sasquatch/>. Browsers will try to render what they can, even if the input is technically invalid. </input></output></updoot></frobozz>

  •  Tags:  
  • html
  • Related