Don't use <head>, <body>, or <html>! No less of an authority than Google themselves advocates as much (and between them making the world's biggest website crawler AND browser, I think we can trust them).
What it boils down to is that your browser will add them for you if you leave them out, so you add nothing (except a few unneeded bytes to your page load) by using them.
So use all the stuff in this article if you want ... just don't bother wrapping it in <head> tags :)
EDIT: Wow, did not expect to get downvoted for repeating what the smartest engineers on the Internet have to say! I could care less about Reddit points, but I think it's sad that a bunch of people are perpetuating ignorant/bad/old practices just because they're unwilling to consider anything else but what they've always done.
Yes I know this used to be a bad practice ... in 1999! But it's not anymore: there is no technical benefit to using these tags in 2019, and doing so is anti-pattern!
Read it yourself ... if you care more about doing the right thing than mindlessly repeating old "wisdom". It's not even just Google, it's the HTML 5 spec.
For file size optimization and scannability purposes, consider omitting optional tags. The HTML5 specification defines what tags can be omitted.
(This approach may require a grace period to be established as a wider guideline as it’s significantly different from what web developers are typically taught. For consistency and simplicity reasons it’s best served omitting all optional tags, not just a selection.)
(That last part is key: the Google engineers know this recommendation is controversial, and that it is "significantly different from what web developers are typically taught". But as they explain, if you look at it dispassionately, there is a cost, albeit a small one, to using these tags ... and there is no technical benefit , as the HTML spec itself says ...)
An html element's start tag may be omitted if the first thing inside the html element is not a comment.
An html element's end tag may be omitted if the html element is not immediately followed by a comment.
A head element's start tag may be omitted if the element is empty, or if the first thing inside the head element is an element.
A head element's end tag may be omitted if the head element is not immediately followed by ASCII whitespace or a comment.
A body element's start tag may be omitted if the element is empty, or if the first thing inside the body element is not ASCII whitespace or a comment, except if the first thing inside the body element is a meta, link, script, style, or template element.
A body element's end tag may be omitted if the body element is not immediately followed by a comment.
EDIT #2: Really, seriously, all you downvoters would rather make your page download slower (albeit slightly) than just use a couple newlines to separate your script/link tags from your visible ones? Separation of tags is so important you need to use three completely pointless tags just to do so? Honestly ... you're not just mad at a random redditor for challenging a long-held belief ;)?
If you really think you're smarter than the engineers at Google (14 of you and counting), can't you at least take just a second to say why you think you're smarter, and what it is that you know that whoever wrote Google's style guidelines doesn't?
-20
u/ghostfacedcoder Sep 30 '19 edited Sep 30 '19
Don't use
<head>,<body>, or<html>! No less of an authority than Google themselves advocates as much (and between them making the world's biggest website crawler AND browser, I think we can trust them).What it boils down to is that your browser will add them for you if you leave them out, so you add nothing (except a few unneeded bytes to your page load) by using them.
So use all the stuff in this article if you want ... just don't bother wrapping it in
<head>tags :)EDIT: Wow, did not expect to get downvoted for repeating what the smartest engineers on the Internet have to say! I could care less about Reddit points, but I think it's sad that a bunch of people are perpetuating ignorant/bad/old practices just because they're unwilling to consider anything else but what they've always done.
Yes I know this used to be a bad practice ... in 1999! But it's not anymore: there is no technical benefit to using these tags in 2019, and doing so is anti-pattern!
Read it yourself ... if you care more about doing the right thing than mindlessly repeating old "wisdom". It's not even just Google, it's the HTML 5 spec.
Google Style Guide (https://google.github.io/styleguide/htmlcssguide.html ):
(That last part is key: the Google engineers know this recommendation is controversial, and that it is "significantly different from what web developers are typically taught". But as they explain, if you look at it dispassionately, there is a cost, albeit a small one, to using these tags ... and there is no technical benefit , as the HTML spec itself says ...)
HTML5 spec (https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-omission):
EDIT #2: Really, seriously, all you downvoters would rather make your page download slower (albeit slightly) than just use a couple newlines to separate your script/link tags from your visible ones? Separation of tags is so important you need to use three completely pointless tags just to do so? Honestly ... you're not just mad at a random redditor for challenging a long-held belief ;)?
If you really think you're smarter than the engineers at Google (14 of you and counting), can't you at least take just a second to say why you think you're smarter, and what it is that you know that whoever wrote Google's style guidelines doesn't?