

The minimal code required in a HTML5 page - cjain
http://dev.chetankjain.net/2011/12/minimal-required-code-in-html5.html

======
Wilya
The fact that it works is completely irrelevant. It has always worked, in
about all versions of HTML/XHTML, in that type of simple cases.

The important fact is that omitting the html, body, head tags is valid markup.
Whether browsers conform to this is another matter. [1] suggests there are
some issues with that.

[1] [http://stackoverflow.com/questions/5641997/is-it-
necessary-t...](http://stackoverflow.com/questions/5641997/is-it-necessary-to-
write-head-body-and-html-tags)

~~~
masklinn
The only browser to still have an issue with this should be MSIE, and that
should be resolved with IE10 which will feature an HTML5 parser[0]:
[http://blogs.msdn.com/b/ie/archive/2011/07/06/html5-parsing-...](http://blogs.msdn.com/b/ie/archive/2011/07/06/html5-parsing-
in-ie10.aspx)

All other major browsers have already switched to an HTML5 parser

* Firefox since Firefox 4: [http://hacks.mozilla.org/2010/05/firefox-4-the-html5-parser-...](http://hacks.mozilla.org/2010/05/firefox-4-the-html5-parser-inline-svg-speed-and-more/)

* Webkit since ~early 2011: <http://www.webkit.org/blog/1273/the-html5-parsing-algorithm/> I don't have the exact dates for stable versions of Chrome and Safari

* Opera since December 2011: <http://www.opera.com/docs/changelogs/windows/1160/>

[0] "html5 parser" is used as a shortcut for "parser implementing the HTML5
parsing algorithm"

------
mathias
Note that `<title>` is only optional in a few edge cases. This post has a more
in-depth explanation: <http://mathiasbynens.be/notes/minimal-html>

------
Pound6F
Just so we are clear: Never actually do this.

The point of the post is that the syntax for writing html is getting better
(just using 'html' as a doctype is great). But in terms of application, there
is none.

If you want to write a web site/service and you want to support more users
than just your friends, you have to do things right to support older browsers
(and IE) and this means things like including all of the tags that FF/Chrome
are automatically adding.

~~~
cjain
I would like to point out that the % of older browser usage is going down
significantly. We are talking < 35% of web population and shrinking by the day
... <http://gs.statcounter.com/#browser-ww-monthly-201111-201201>

------
creativityhurts
Here's a list of smallest possible syntactically valid files of different
types <https://github.com/mathiasbynens/small>

~~~
mathias
Also see <http://mathiasbynens.be/notes/minimal-html> for a list of the
smallest possible (X)HTML files per version.

------
lambda
Before you ask what the minimal code for an HTML5 page is, you have to decide
what constraints you are putting. Are you talking about the minimal valid,
independent web page? The minimal code that your browser will parse as HTML
and generate a DOM for? The minimal code that is allowed in an <iframe
srcdoc>?

If you're talking about the minimal valid code for an independent web page, it
is:

    
    
        <!DOCTYPE html><title></title>
    

The title element is required, and is not automatically inserted if the tags
are missing the way <html>, <head>, and <body> are.

If you're talking about the minimal thing the browser will parse, you can
provide an empty document (with Content-type: text/html), and the browser will
treat it as if it's an HTML document, generating the appropriate elements
automatically. It will parse it in quirks mode, but if you don't care about
validity, and are talking about an empty document, that doesn't matter much.

If you're talking about what you can embed in <iframe srcdoc>, again, an empty
document is acceptable. In that context, the doctype and title are both
optional.

~~~
mathias
Note that `<title>` is optional in a few edge cases. This post has a more in-
depth explanation: <http://mathiasbynens.be/notes/minimal-html>

------
ChrisLTD
The author mentions that you can leave the type attribute off of <script>
tags. You can do the same with <style> tags as well, since it defaults to CSS.

------
DiabloD3
Wouldn't <html/> be the smallest?

~~~
eliam
Smallest what? There's no DOCTYPE.

~~~
knowtheory
It's worth adding that the DOCTYPE is what specifies what HTML rendering
engine IE 7 and 8 use. A document without the DOCTYPE directive will render in
quirks mode, and nobody wants that.

------
Craiggybear
I think I recall Paul Irish once saying even closing tags of certain types
(<li>, <p> etc) were also unnecessary. The start of the next tag should also
signal the close of the previous one (unless you want to nest stuff) -- so
whether the </p> or </li> tag or whatever is there or not makes no difference.

HTML parsers cope quite well with that (and have done for a while) but I don't
do it. Although I _am_ guilty of not bothering with the type declaration in
scripts that _are_ JavaScript <script src="..." />

I know I'm just plain lazy and wrong.

