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.

Revisions

  1. treyharris revised this gist Jul 17, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # 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 could be deleted to make the document shorter in character length:
    which are deleted to make the document shorter in character length):

    ```html
    <!doctype html>
  2. treyharris revised this gist Jul 17, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ you can leave out the `=…` when an attribute is empty. So, we can kill the `="
    </title>
    ```

    or, removing whitespace,
    or, removing whitespace, we get these 42 characters:

    ```html
    <!doctype html><html lang><title>.</title>
  3. treyharris created this gist Jul 17, 2021.
    64 changes: 64 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    # 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 could be deleted to make the document shorter in character length:

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

    With the `.` replaceable by almost any plaintext character.

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

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

    however, the [HTML5 validator](https://validator.w3.org/) 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:

    ```html
    <!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`:

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

    is allowable, and does not even cause warnings. By [the spec](https://html.spec.whatwg.org/multipage/syntax.html#attributes-2),
    you can leave out the `=…` when an attribute is empty. So, we can kill the `=""` part, which gives us

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

    or, removing whitespace,

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

    Is there a shorter one (that is actually HTML5, validates without warnings on the [HTML5 validator](https://validator.w3.org/), and doesn't "cheat" by messing with doctypes or comments)? Comment below!
    5 changes: 5 additions & 0 deletions short-with-whitespace.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    <!doctype html>
    <html lang>
    <title>
    .
    </title>
    1 change: 1 addition & 0 deletions short.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <!doctype html><html lang><title>.</title>
    1 change: 1 addition & 0 deletions shortest-with-warnings.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <!doctype html><title>.</title>