Hacker News new | ask | show | jobs
by lambda 5231 days ago
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.

1 comments

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