"<title> should be in a <head> element; <h1> and <h2> should be inside the <body>..."

Allow me to blow your mind... they already are!

Many HTML elements have optional closing tags. For example:

<p>Foo <p>Bar

When an HTML parser encounters the second opening <p> tag, it can infer that the first <p> element must have closed, because paragraphs cannot be legitimately nested. (Well, actually they can if you use the right interleaving elements, but that's another story...)

This is not just browsers being forgiving. It's part of the HTML spec; even allowed by the strict versions of HTML. (But not by XHTML obviously, which is an entirely different kettle of fish altogether.)

Now, here's the mindblowing bit. And it relies on you being able to divorce tags and elements a little in your mind. We've seen how an element can legitimately exist without a closing tag; it's also possible for an element to exist without an opening tag!

Given the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <title>Foo</title> <p>Bar</html>

... when a parser encounters the <title> tag, it infers that not only the <title> element has been opened, but that <html> and <head> have too. When it encounters <p> it infers that <head> must have closed (because <p> cannot be used within <head>) and <body> must have begun.

The Foo Bar document above is a complete, valid HTML 4.01 Strict document. Don't believe me?

spec ref

Now, you could argue that omitting optional start tags is bad style. I might even agree with you. But it's very, very common. (Hint: take a look at the content model for the <table> element.)

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

In reply to Re^2: Dancer and Template-Toolkit by tobyink
in thread Dancer and Template-Toolkit by nathaniels

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.