Skip to content

Instantly share code, notes, and snippets.

@treyharris
Last active July 17, 2021 21:30
Show Gist options
  • Save treyharris/3c521e16f2232c9d49e7a04fcacdfc02 to your computer and use it in GitHub Desktop.
Save treyharris/3c521e16f2232c9d49e7a04fcacdfc02 to your computer and use it in GitHub Desktop.
The shortest possible HTML5 validatable without warnings?

In search of the shortest HTML5 document

I was curious what wass the minimum-allowed HTML5 document. I think it is (neglecting newlines and indention whitespace, which are deleted to make the document shorter in character length):

<!doctype html>
<html lang>
  <title>
    .
  </title>

With the . replaceable by almost any plaintext character.

If you don't care about warnings, this works:

<!doctype html><title>.</title>

however, the HTML5 validator suggests:

Consider adding a lang attribute to the html start tag to declare the language of this document.

To remove the warning, you could write something like:

<!doctype html>
<html lang="en">
  <title>
    .
  </title>

Since all allowed lang subtypes have at least two characters, there's no language shorter than en (or de or fr or ja, etc.). However, an empty lang:

<!doctype html>
<html lang="">
  <title>
    .
  </title>

is allowable, and does not even cause warnings. By the spec, you can leave out the =… when an attribute is empty. So, we can kill the ="" part, which gives us

<!doctype html>
<html lang>
  <title>
    .
  </title>

or, removing whitespace, we get these 42 characters:

<!doctype html><html lang><title>.</title>

Is there a shorter one (that is actually HTML5, validates without warnings on the HTML5 validator, and doesn't "cheat" by messing with doctypes or comments)? Comment below!

<!doctype html>
<html lang>
<title>
.
</title>
<!doctype html><html lang><title>.</title>
<!doctype html><title>.</title>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment