Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Why does Google 404 serve invalid HTML?
1 point by philip1209 on Aug 9, 2016 | hide | past | favorite | 2 comments
e.x. http://google.com/notfound

The "html" tag is not closed. "body" does not exist. CSS refers to elements that do not exist.

Are they minifying to the extreme and relying on the browser to add <body> and close the HTML?




The Google Style Guide[0] for HTML recommends omitting all optional tags. That includes <html>, <head>, <body>, <p> and <li>.

[0] https://google.github.io/styleguide/htmlcssguide.xml#Optiona...

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.)

  <!-- Not recommended -->
  <!DOCTYPE html>
  <html>
    <head>
      <title>Spending money, spending bytes</title>
    </head>
    <body>
      <p>Sic.</p>
    </body>
  </html>

  <!-- Recommended -->
  <!DOCTYPE html>
  <title>Saving money, saving bytes</title>
  <p>Qed.


That's interesting to know. A Body css without a <body> tag..!!




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: