What happens if we follow bad syntax in HTML

html xhtml

41 观看

1回复

1 作者的声誉

I wanted to know the difference b/w HTML and XHTML. When I was searching on google I came to know that XHTML is nothing but HTML with stricter syntax. And they also said even if we write html with bad syntax it works fine. My doubt is if it works fine with bad syntax also with normal HTML then what is the need of XHTML? Why should we follow strict syntax? I just want to know what will go wrong with bad syntax in html when it is working fine as expected.

Thank you in advance

作者: varun 的来源 发布者: 2017 年 9 月 15 日

回应 1


0

36926 作者的声誉

I wanted to know the difference b/w HTML and XHTML.

There are many differences. Most webpages about HTML vs XHTML mention a number of differences, but there aren't really any pages that really mention all. I made a longer list here on my own site, but it's probably not 100% complete either.

When I was searching on google I came to know that XHTML is nothing but HTML with stricter syntax.

"Simplified" syntax would be better. And there's more. Different MIME type, an actually working DOCTYPE declaration etc.

And they also said even if we write html with bad syntax it works fine. My doubt is if it works fine with bad syntax also with normal HTML then what is the need of XHTML?

That answers your own question. XHTML disallows "bad syntax", so it's better! There are many errors that XHTML can't handle and HTML can, which cause differences in display between browsers. So XHTML forces better cross-browser compatibility.

Why should we follow strict syntax? I just want to know what will go wrong with bad syntax in html when it is working fine as expected.

That depends on what you expect. If you expect different browsers to handle errors differently, then sure, go ahead! Keep the errors!
If, on the other hand, you want your pages to look the same in different browsers, make sure to correct all of them.
For some examples of errors that cause different behaviour in different browsers, I've got a list here (again, on my own site).

作者: Mr Lister 发布者: 2017 年 9 月 22 日
32x32