The Wayback Machine - https://web.archive.org/web/20090206110537/http://www.webreference.com:80/html/tutorial4/6.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

The Paragraph / Line Break Bug

Developer News
Open Source ECM Growing Up
Android's Second Act, G2 Rumors Heat Up
Eclipse Rolls Out PHP Development Tools 2.0

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.

Front Page1234567

http://www.internet.com

Produced by Stephanos Piperoglou

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2008 Jupitermedia Corporation All Rights Reserved.

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Building a Client-Side Ajax Cache · Using Dojo for Client-Side Validation · Apache Basics, Visited
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
SSH at Work: Manage Long-Running Processes with screen · Ingate Systems Smooths the Path Between VoIP Networks · Telecommute Toolkit: 10 Things Mobile Workers Need


All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/html/tutorial4/6.html
Created: July 12, 1998
Revised: July 12, 1998

Morty Proxy This is a proxified and sanitized view of the page, visit original site.