The Paragraph / Line Break Bug
Most of the things you've learned so far fall under the heading of "harmless" when it comes to browsers. In other words, Navigator and Explorer handle them as you would expect them to. There are a few exceptions, while some of them are ignored by both Navigator and Explorer.
Most notably, both browsers blatantly ignore Document Type Declarations. This is very important to remember. The chief problem with both browsers is that they don't know which version of HTML they are processing, so they use various techniques to make sure they process older HTML documents as well as new ones.
One of these is the famous paragraph / line break bug. In the
previous tutorial, we introduced the HR
element, that
inserts horizontal separators in HTML documents. Here is a fragment of
HTML containing two paragraphs separated by a horizontal rule:
<P>This is the first paragraph.</P> <HR> <P>This is the second paragraph.</P>
This is the first paragraph.
This is the second paragraph.
This is fine, and if you're viewing this page using either Netscape Navigator or Microsoft Internet Explorer, the above will be displayed as you expect it to be displayed.
Now last time we also mentioned that the end-tag to the
P
element can be omitted when it is implied. In the example
above, HR
is a block element following P
(also
a block element), so it cannot be contained within P
.
Hence, the end-tag is implied and can be omitted. Let's see what happens
when we ommit the end-tag:
<P>This is the first paragraph. <HR> <P>This is the second paragraph.</P>
This is the first paragraph.
This is the second paragraph.
According to any of the three HTML specifications and any program that checks your documents, both of the examples are identical and should hence be handled identically if they appear in the same context. But if you're reading this on Navigator or Explorer, you'll notice that there is no horizontal margin after the first paragraph in the second example! If you've been omitting end-tags to save typing when writing your documents and seen that so far it hasn't had any effects, you would be mystified if this happened to one of your documents, and no amount of checking using validators or other syntax checkers would point out the problem!
The paragraph / line break bug appears when certain block elements
follow a P
element for which the end-tag has been omitted.
The obvious and simple workaround is to always explicitly include the
end-tag in P
elements. This way your document still
conforms to the specification and is handled correctly by Navigator and
Explorer.
This is an example of a document that conforms to the specification
but is handled incorrectly by the two browsers. Though this is a
relatively harmless bug in some respects, some of the more serious ones
(such as Internet Explorer 3.0's bugs in the handling of the
OBJECT
element, which we'll cover in the future) can even
cause the browsers to crash without any warning!
Some of these bugs are fixed in newer versions. Some, like the
paragraph / line break bug, are not fixed on purpose. You see, authors
who didn't use the workaround of including the end-tag did other crazy
things such as inserting empty paragraphs before HR
, and
their documents would appear strange if the bug was fixed. The debate on
whether this is the correct approach or not is a long one. My personal
opinion is that if the browsers recognized Document Type Declarations
they could exhibit the buggy behaviour for older documents in order to
display them as the author expected and comply to the specification for
newer ones. If you feel this way, go ahead and write a letter to
Microsoft and Netscape complaining. But the paragraph / line break bug
is only the tip of the iceberg. And for the moment, if you wish to reach
the vast majority of people browsing the Web, you'll have to learn about
bugs like this and work around them.
Produced by Stephanos Piperoglou
All Rights Reserved. Legal Notices.
URL: https://www.webreference.com/html/tutorial4/6.html
Created: July 12, 1998
Revised: July 12, 1998