Reputation: 443
I did search about it, and found nothing, so I ask here.
Recently I worked on a grails project in which nested html templates formed html code for emailing like next example, in which each DOCTYPE+Style corresponds to different templates that are used depending on business rules:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
...(styles here)
</style>
<table>
<tbody>
<tr>
<td>
<table>
<tbody>
<style type="text/css">
...(more styles here)
</style>
<tr>
<td>
<table>
<tbody>
<tr>
<td class="greeting">
Hi
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tbody>
<tr>
<td>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<style type="text/css">
...(more styles here)
</style>
</td>
</tr>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<style type="text/css">
...(more styles here)
</style>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<style type="text/css">
...(more styles here)
</style>
...(and a lot more of code like this)
</td>
</tr>
</tbody>
</table>
But the html 4.0.1 standard says that <style>
elements should go in the <head>
of the document, not to mention that DOCTYPE should be the 1st one for a valid html document.
Why does it work?
Why doesn't it need to respect the standard to work?
Why is there a standard if you can skip it this way?
Surely I'm missing something.
I learned today that <html>
root tag is optional too, as many others, but found nothing about this matter.
Thanks.-
Upvotes: 0
Views: 45
Reputation: 943564
Why does it work?
HTML parsers perform a lot of error recovery to handle bad HTML.
Why doesn't it need to respect the standard to work?
Because it is generally considered better to show end users a "best effort" rendering of a webpage instead of an error message.
Why is there a standard if you can skip it this way?
Because pages that follow the standard can expect more predictable behaviour in how parsers handle them (since they won't be triggering error recovery).
Upvotes: 2