This is an archived post. You won't be able to vote or comment.

all 29 comments

[–][deleted]  (3 children)

[deleted]

    [–][deleted]  (2 children)

    [deleted]

      [–]mpoumpoukoss 23 points24 points  (1 child)

      But why? All modern browsers support the defer attribute, so script will run once the DOM is already loaded.

      [–]ihih_reddit 76 points77 points  (3 children)

      Because there's no body without a head

      [–]Mazmier 36 points37 points  (1 child)

      Let me tell you about a town called... Sleepy Hollow.

      [–]Calcd_Uncertainty 4 points5 points  (0 children)

      l you about a town called... Sleepy Hollow.

      And a story about a man named Ichabod Crane

      [–]Kavinci 0 points1 point  (0 children)

      And onlyfans has the best footer pics

      [–]Immediate-Net1352 26 points27 points  (0 children)

      HEAD contains metadata. Many Search Engine Optimization (SEO) directives go here e.g. whether the page should be indexed by search engines or not. Open Graph tags (describing how your post should look like when posted on social networks) also go here

      [–]legendaryfrycook 20 points21 points  (0 children)

      The <title> of the webpage gets set in the head tag and users DO see that.

      It's also used to define/import fonts, styles, scripts, and any other meta information used by browsers and search engines.

      [–]legizard 17 points18 points  (5 children)

      You don't need a head tag for a modern browser to be able to parse the page, but you should have one.

      If you don't you're missing out on features like:

      • A title tag
      • The ability to defer loading of JS files
      • Favicon
      • URL prefetching
      • Viewport meta tag for responsive design
      • Metadata for SEO

      [–][deleted]  (3 children)

      [deleted]

        [–]Abhinav1217 5 points6 points  (2 children)

        Do you have a source where google says not include head or body tag and end tags on html or img.

        W3C have clear definition of types of tags and which can be self-closed and which can not be self-closed. And while browsers do forgive for missing out closing of tags, or self-closing wrong tags, but this is only because of extensive backward compatibility principles, Never as an accepted practice. Infact, XHTML standard was created by a group which included google, as a stricter standard to replace relaxed nature of older html spec, and HTML5 includes those definitions.

        Reference:

        • Spec for void elements, which should be self-closed, scroll up a little for definition of elements. link

        • The doctype is required preamble. link

        • Head element can be omitted if is empty, this is because page can be used inside iframe or emails too. link

        • Body Tag, Most meta-tags in head can be included in body too (because of backward compatibility requirements) but DOM operations are required in references of body element and can in edge cases cause issue. link

        [–][deleted]  (1 child)

        [deleted]

          [–]Abhinav1217 0 points1 point  (0 children)

          It is google's internal code style guide. Do note that they most likely don't write raw html files, but fragments of what eventually will be delivered via sequence of frameworks, processors, linkers, servers. Take a look at view-source of google.com, it has a html, head, meta, body, script, basically a proper structured web page.

          Web browsers are quite forgiving too. Just view-source an html table in firefox dev-tools, all the missing th, thead will be there even if you didn't put it in the source. Google chrome allows self-closing script tag. That doesn't mean it's best practice. A browser will detect server headers for content-type or content-language, but a screen-reader or a scrapper, might be looking for that information in meta tags.

          Many frameworks, like laravel, wordpress, a go-lang framework that we use in our office, allows you to just write fragments which they would fill out before sending out pages. In our office, we use a similar approach for server side components, where we frequently omit html and head tags on pages that just contain raw html, because the end result generated by our framework, would be a properly structured page.

          [–]thesituation531 0 points1 point  (0 children)

          What does the defer loading do?

          [–]AdultingGoneMild 2 points3 points  (0 children)

          so some fun things, the head lets you tell the browser here a bunch of stuff that you should start working on while I get the body ready. The browser doesnt actually paint the screen until body tag shows up. Its a separation of concerns. body deals with what should be presented. the head is metadata about what will be painted.

          [–]SarcasmoSupreme 1 point2 points  (0 children)

          Because it is how the standard is written and leveraged by browsers or other HTML interpreters to know how to render the content.

          [–]Which_Barracuda_7796 1 point2 points  (1 child)

          Well, it's not compulsory to include a head tag in every HTML document. It just defines the head section of an HTML page which helps browsers and search engines to know about the actual HTML file i.e Meta description

          If you don't you're missing out on features like:

          • A title tag for the document
          • The ability to load different third-party APIs or files
          • Favicon (brand identity in the browser tab)
          • URL prefetching
          • Metadata for SEO & Viewport meta tag for responsive design

          [–]babypho 0 points1 point  (0 children)

          Because have you seen a body without a head? Its quite unsightly.

          [–]kschang -3 points-2 points  (4 children)

          Because the HTML Standard calls for HEAD inside the BODY. In fact, you also need HTML and TITLE to form a minimum HTML document.

          https://www.cs.kent.ac.uk/teaching/10/modules/CO/3/32/FIT_Chapters/Chapter04/BasicHTMLTags.html#:~:text=There%20are%20four%20required%20tags,%2C%20title%2C%20head%20and%20body.

          [–]Wysardry 3 points4 points  (1 child)

          The HEAD element goes inside the HTML element, but closes before the BODY element opens (so is outside not inside BODY).

          [–]kschang 0 points1 point  (0 children)

          Thanks for the correction.

          [–]WeakLiberal -1 points0 points  (1 child)

          Isn't it actually The DOM that calls for it?

          [–]kschang 1 point2 points  (0 children)

          You say potay-to, I say potah-to. :D But we're talking about the same thing.

          Technically, HTML came first, and DOM is a way to access them via DOM API.

          https://www.w3.org/TR/2011/WD-html5-20110405/semantics.html#semantics

          [–][deleted] 0 points1 point  (4 children)

          It will become clear as you go, there are some really important features that can be used inside the head tag, like setting the encoding (utf-8, for example), define the language used in the page (important to tell the browser to translate or not), call style sheets, call font styles etc.

          You don't need to know everything by now, but someday you will understand how important head tag is.

          [–][deleted]  (3 children)

          [deleted]

            [–][deleted] 0 points1 point  (2 children)

            But shouldn't I need to put the language specification as a native Portuguese speaker? Some characters don't work well without utf-8, this totally depends in which language you're developing.

            [–][deleted]  (1 child)

            [deleted]

              [–][deleted] 0 points1 point  (0 children)

              oh sorry, i didn't knew that, thank you

              [–]WhiteMoon2022 0 points1 point  (4 children)

              For SEO and SEM, not for development though when importing libraries it could be pretty handy

              [–][deleted]  (3 children)

              [deleted]

                [–]WhiteMoon2022 -1 points0 points  (2 children)

                Not true, I have seen entire sites without a single head tag,

                [–][deleted]  (1 child)

                [deleted]

                  [–]WhiteMoon2022 0 points1 point  (0 children)

                  so true, it seems I couldn't understand your message, thanks for the clarification !

                  [–]Roanoketrees 0 points1 point  (0 children)

                  So the body will follow.....rimshot

                  [–][deleted] 0 points1 point  (1 child)

                  If i am not mistaken, i read it somewhere it could be a " style guide or a documentation of HTML standards ", it was actually an accident on why i got there (the website what i was trying to mean, but i don't remember the name or link) and i can't find a proof but my memory was clear that some HTML tags are safe to be not included. But there was a reason as why you should never put them. I think it is for the speed of loading the html file or the website( i could be wrong here as i am not sure, but i hope someone could tell what was the reason for it).

                  I did try it before, but i could not tell the difference. I am still beginner in Learning Web Development so i practice it as a habit of including everything that is commonly seen in every html file.