Look at this example from the HTML spec
<!-- Example of data from the client database: -->
<!-- Name: Stephane Boyera, Tel: (212) 555-1212, Email: sb@foo.org -->
<DIV id="client-boyera" class="client">
<P><SPAN class="client-title">Client information:</SPAN>
<TABLE class="client-data">
<TR><TH>Last name:<TD>Boyera</TR>
<TR><TH>First name:<TD>Stephane</TR>
<TR><TH>Tel:<TD>(212) 555-1212</TR>
<TR><TH>Email:<TD>sb@foo.org</TR>
</TABLE>
</DIV>
Did you notice something? : There was no closing tag of the <p>
element. a mistake in the specs ? No.
Tip #1: The closing tag of <p>
is OPTIONAL
You may ask: But then how would a <p>
element knows where to stop?
From w3docs:
If the closing tag is omitted, it is considered that the end of the paragraph matches with the start of the next block-level element.
In simple words: a <div>
is a block element and its opening tag will cause the parent <p>
to be closed, thus <div>
can never be nested inside <p>
.
BUT what about the inverse situation ? you may ask
well ...
Tip #2: The closing tag of the <div>
element is REQUIRED
According to O’Reilly HTML and XHTML Pocket Reference, Fourth Edition (page 50)
<div> . . . </div>
Start/End Tags
Required/Required
That is, the <div>
element's end will only be determined by its closing tag </div>
hence a <p>
element inside is will NOT break it.
` is a block level element, and is (supposed to be) used for displaying text, it won't allow other block level elements inside it, but only inline ones like `` and ``.
– Bojangles Dec 06 '11 at 09:46