August 12, 2016

What is the minimum needed to create an HTML5 document?

html

<!doctype html>
<html lang='en'>
  <head>
    <meta charset='utf-8'>
    <title>Minimum HTML5 Document</title>

xhtml

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
  <head>
    <meta charset="utf=8"/>
    <title>Minimum xhtml5 Document</title>
  </head>
  <body>
  </body>
</html>

polyglot [ both html and xml in the same document ]

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' lang='en' xml:lang='en'>
  <head>
    <meta charset="utf=8"/>
    <title>Minimum Polyglot HTML5 Document</title>
  </head>
  <body>
  </body>
</html>

notes

Doctype may be either upper or lower case for html; it must be ALL CAPS for xhtml or polyglot.

Specified language (en) and charset (utf-8) is for example purposes; use whatever is appropriate for your situation.

HTML is very tolerant of sloppy markup. XHTML requires closing tags. Refer the DTD to see which tags can be self-closing and which cannot. An example of a self closing tag is <img/>. Compare that to an element that requires a closing tag, <p></p>.

Modern browsers are very tolerant of noncompliant markup. If you're feeling lazy you could create a web page containing only your markup and save it with the extension .html and it would probably display correctly.

straight from the horse's mouth

Get the DTD here: W3C HTML5 Recommendation Always check your work: Nu Consolidated Validator