8
<!DOCTYPE html>
<meta charset="utf-8">
<body>
Hello, world!

SOURCE FOR CODE

If so, besides removing "Hello, world!" is there any tag that's able to be removed and it still be valid, and how do you know it's still valid?

blunders
  • 3,619
  • 10
  • 43
  • 65
  • Hmm, there's exactly one tag missing and one other tag which can be removed. Smells a bit like *homework*. – Kevin Stricker Aug 13 '12 at 21:00
  • @mootinator: Source is this [presentation on D3](http://bost.ocks.org/mike/d3/workshop/), put I can't figure out how to link to the slide, so I just linked to the code. Thought it was interesting, but didn't look valid. More to the point, no, it's not HW. – blunders Aug 13 '12 at 21:02
  • Ah, but a contrived example for the purpose of discussion nonetheless :) Interesting that it was in that presentation, but *isn't* valid actually. – Kevin Stricker Aug 13 '12 at 21:03
  • possible duplicate of [Bare minimum HTML5 - is it valid?](http://stackoverflow.com/questions/28360273/bare-minimum-html5-is-it-valid) -- I realize it's my question and it's -2 but the answer there is much better than the one here. – Qix - MONICA WAS MISTREATED Apr 05 '15 at 18:42

4 Answers4

12

It's not valid. To check it you can run it in W3C Validator

The error is: Element head is missing a required instance of child element title.

...

UPDATE

As vcsjones stated the head element is optional. That's the title one is required. Credit to mootinator for pointing out that the body is also optional.

So the simplest valid document will be:

<!DOCTYPE html>
<title></title>
Zoltan Toth
  • 46,981
  • 12
  • 120
  • 134
5

(Assuming the HTML syntax of HTML5.)

Note that in some situations the title element is optional, too.

From HTML5’s definition of head:

The title element is a required child in most situations, but when a higher-level protocol provides title information, e.g. in the Subject line of an e-mail when HTML is used as an e-mail authoring format, the title element can be omitted.

So the minimal markup for a document that gets a title from a "higher-level protocol" is this:

<!DOCTYPE html>

If the document is the value of an iframe-srcdoc it’s this (assuming a title is provided by the container document):

<html>

And for a stand-alone document it’s this (the title element needs some actual content, as noted by kapep, so the "…" is just an example):

<!DOCTYPE html>
<title>…</title>
Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360
  • Note that with the last HTML code snippet, the [Nu Html checker](https://validator.w3.org/nu/) (the only HTML validator currently endorsed by the WHATWG) outputs: ‘Warning: Consider adding a `lang` attribute to the `html` start tag to declare the language of this document.’ So the minimal document without error and warning seems to be: ` ` – Géry Ogam May 27 '21 at 15:24
  • @Maggyero: It’s of course a good thing to provide `lang`, but as it’s not required for conformance (because a warning is not an error), it wouldn’t be the most minimal valid document. – unor May 27 '21 at 20:41
3

The title tag can't be empty or only consist of whitespace. So if the document is in a context where the title tag is required, you will have to set a valid title value.

The title content model is defined as "Text that is not inter-element whitespace".

"Empty Text nodes and Text nodes consisting of just sequences of [space characters]" are inter-element whitespace. Space characters are space, tab, line feed, form feed and carriage return.

If the title tag is empty, the W3C Validator complains that "Element title must not be empty". The Validator is fine with only adding just spaces, even though that is not correct according to the specs.

It is valid if you add another non-space character:

<!DOCTYPE html>
<title>x</title>

You could use other space characters like non-break space or zero-width non-break space if you want to fake an "empty" title.

kapex
  • 28,903
  • 6
  • 107
  • 121
0

The smallest HTML document for which the Nu Html Checker (the only HTML validator currently endorsed by the WHATWG) does not produce any errors nor warnings is the following:

<!DOCTYPE html>
<html lang="">
<title>x</title>
Géry Ogam
  • 6,336
  • 4
  • 38
  • 67