Re: Error in Checking invalid HTML code

 Chuck Houpt (chuck@habilis.net) wrote:

>
> In recent versions of HTML, some elements/tags are optional and their
> absence won't be flagged as errors.


Recent? The <html>, </html>, <head>, </head>, <body>, and </body> tags have
been optional since the dawn of HTML. They were (and are) required only in
XML format HTML (”“XHTML”), which was invented long after HTML. And the
optionality of tags is not related to optionality of elements. Every HTML
document contains the html, head, and body elements, though perhaps empty.


> Of course, it can be confusing when the tags for the top level elements
> html/head/body are omitted and their existence is only implied.


Can it? Then there might be something confused in the teaching.


> When teaching HTML, it is best to make those elements explicit.
>

  The <html>, </html>, <head>, </head>, <body>, and </body> tags have never
served any purpose beyond being informative in some vague sense.

The original question was also about the emptiness of the body element.
That’s certainly allowed. Even though it may look odd when considering HTML
documents as static objects, it makes perfect sense when all of the content
is generated dynamically with a client-side script (JavaScript code), It
may well be simpler to start with an empty body element and append children
to it.

Yucca

Received on Tuesday, 22 November 2022 20:12:00 UTC