A question came up in which the asker demonstrated cross-browser rendering differences between two complete HTML documents, one with a DOCTYPE:
<!DOCTYPE html>
<img style="width: 100%; height: 100%;" src="image.jpg">
and one without:
<img style="width: 100%; height: 100%;" src="image.jpg">
The only two things missing from either document are the title
element, which has zero impact on rendering since it's not even part of the document body, and an alt
attribute on the img
element, that only affects rendering in some browsers when the image cannot be displayed, and otherwise has zero impact on rendering as with the title
element. (The second snippet is also missing the DOCTYPE itself, but it's there as a point of comparison; the entire point of the question is that the desired behavior is only seen when it's left out.)
But one commenter pointed out that the samples were missing the <html>
and <body>
tags and their markup was invalid and solutions to their problem would not work reliably for that reason (which, of course, is wrong; it is invalid with no side effects for the reasons I just stated above). Another commenter asked what would happen if the asker loaded valid HTML, implying that it would make any difference to rendering in this case (which, again, it doesn't — there's just one img
element).
A third mentioned that the tags are indeed required under certain circumstances — except this wasn't one of them, but I was happy to clear up something they misunderstood about the spec since they made an effort to cite it, unlike the others.
So the asker was forced to add <html>
and <body>
tags to their snippets, tripling the line count on the former and quintupling it on the latter (they have since rolled this back after I corrected everyone else in the comments):
<!DOCTYPE html>
<html>
<body>
<img style="width: 100%; height: 100%;" src="image.jpg">
</body>
</html>
<html>
<body>
<img style="width: 100%; height: 100%;" src="image.jpg">
</body>
</html>
Like, why is this necessary? There are no attributes on either start tag, and there is nothing but a single img
element in the entire document. All it does is make it more difficult to see the problem at hand: that browsers scale the image differently depending on whether or not the DOCTYPE is present.
This is not an isolated case. This happens on a daily basis in html and/or css questions. Askers are forced to add boilerplate that they know isn't required and has zero impact on the problem just because multiple commenters incorrectly think that it is.
The only good reason I can think of for adding these tags is so that readers know these are in fact complete HTML documents, not incomplete fragments. But no one says that. Anyone pointing out missing <html>
and <body>
tags only does so because they think leaving them out makes a page invalid (this is only true in XHTML, who writes that anymore?). And a lot of people think so. Those who think the snippets are incomplete fragments say something along the lines of "Please provide the complete HTML" instead. No one has said that here.
Don't people tend to obsess over the M in MCVE to the point where even a single line of boilerplate will set them off? (Note that the C and V are met even when the boilerplate isn't there — that's why it's called boilerplate.) Don't people dislike HTML for how verbose it can get? So why are readers complaining when the asker is doing them a favor by leaving out unnecessary bloat? Where is the line drawn?
…
or...
) be used to indicate 'stuff left out but it is noise rather than critical'?title
and the missingalt
are errors. Therefore you shouldn't be complaining when people say they are missing.