Question
What is the minimal valid HTML document?
I usually start with a template like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example</title>
</head>
<body>
</body>
</html>
I wonder if that is the minimal HTML document or if a shorter valid HTML document exists.
Answer
You can easily find the minimal HTML document by using the W3C validator.
Start with a document like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example</title>
</head>
<body>
</body>
</html>
Then try to gradually remove the various tags and see if the document is still valid.
From my testing, this is the shortest valid HTML5 document:
<!DOCTYPE html>
<title>-</title>
This is possible because HTML can automatically infer the presence of tags (e.g. head
or body
) and the closing of tags (e.g. you can open a tag and avoid to explicitly close it).