Improve Site Performance Increase Site Traffic Monitor Site Uptime Webmaster Resources NetMechanic Home Looking For Help? Partner Programs Privacy Policy Contact Us Press Room
NetMechanic Home LOGIN | HELP | ABOUT US | PRODUCTS | SITE MAP
NetMechanic Menu
Over 52 Million Web Pages Tested!     
 
Positioning tips.
search engine optimization story search.
Search for:


Your Email:

I would like to receive my newsletter in:
HTML format
Text format


Increase traffic.
Volume 8 (2005)
   September
   June
   April
   March
   January

Volume 7 (2004)
   November
   September
   July
   June
   May
   April
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 6 (2003)
   December
   November (Part 2)
   November
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 5 (2002)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 4 (2001)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 3 (2000)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June
   May
   April
   March
   February
   January

Volume 2 (1999)
   December
   November
   October
   September
   July
   June
   May
   April
   March
   February
   January

Volume 1 (1998)
   December
   November
   October
   September

 

HTML Tip:
Eliminate The Mystery Spaces

by Larisa Thomason,
Senior Web Analyst,
NetMechanic, Inc.

  
January 2004
Vol. 7, No. 1
 • HTML Tip
 • Browser Tip
 • Book Review
  

Even when it's carefully written and documented, HTML code can be hard to read. Webmasters are often tempted to break the code into sections so that each tag stands on its own line. That makes the code much easier to read, but often causes unexpected display problems in Internet Explorer.

The Carriage Returns More Than You Expect

Consider this snippet of HTML code:

<img src="blueBox.jpg" width="50" height="50" align="left" hspace="0"><img src="greenBox.jpg" width="50" height="50" align="left"hspace="0"><img src="blueBox.jpg" width="50" height="50" hspace="0"><div class="example">Text content inside a DIV tag</div>

"Hard to read" isn't really an adequate description! This second example is much easier to follow:

<img src="blueBox.jpg" width="50" height="50" align="left" hspace="0">
<img src="greenBox.jpg" width="50" height="50" align="left" hspace="0">
<img src="blueBox.jpg" width="50" height="50" hspace="0">

<div class="example">
Text content inside a DIV tag
</div>

It's pretty clear in the second example that the effect you want is to display three images pressed together directly above a DIV tag that's been styled using a CSS class. According to HTML specifications, the images should appear directly above the DIV tag with no vertical spacing between the elements.

That's exactly what happens in both Netscape 7 and Explorer 6 when they display the first example snipped of unformatted code:

But when we use the code from the second example, we see the extra space that Explorer places between the images and the DIV. The culprit is the line break between the last image and the opening DIV tag:

The only way to remove the space is to place the opening DIV tag on the same line as the final image:

<img src="blueBox.jpg" width="50" height="50" hspace="0"><div class="example">
Text content inside a DIV tag
</div>

Then the extra space disappears! That's because you've removed the so-called "hard return" or "carriage return" placed between them. You place a carriage return inside your HTML code when you create a new line using the ENTER key on the keyboard.

Other Affected Page Elements

An extra carriage return can cause lots of problems with images because you often want an image to appear with no extra spacing around it. Think of all the extra hours you could spend adjusting spacing, margins, and padding with CSS only to discover that the problem was a line break!

Other instances where you need to be alert to this problem include:

  • Tables: An extra carriage return between table content and a closing TD tag forces an extra space to display in Explorer. Place the closing TD tag immediately after the cell content like this:

    <td>cell content</td>

    instead of

    <td>
        cell content
    </td>


  • Paragraph tags: Place the closing paragraph tag on the same line as the paragraph content to avoid the extra space problem. It's usually more a problem when the paragraph contains both text and images rather than text-only content but why risk it?

The frustrating thing is that it doesn't happen with all HTML tags: just closing tags and just with some HTML elements! Because the spaces are not a coding error, HTML validators ignore them. This is a browser display problem, not a coding error.

It's a problem that's been around about as long as HTML and graphical browsers.

Find And Fix Browser Display Problems

In fact, our first newsletter editor, Tom Dahm, noticed this problem and warned subscribers about it in one of our very first newsletter articles: Beware Of The Carriage Return. He noted that extra carriage returns cause display problems in Netscape 4.02 and Explorer 4.0.

Things have a bit changed since then.

In a mixed blessing, Netscape fixed the problem in subsequent versions. Netscape browser versions 6.x and 7.x ignore extra carriage returns and display pages like you expect. So do Opera versions 6.x and 7.x. Both browsers try to adhere rigorously to HTML and XHTML standards.

Unfortunately, the bug is still a problem in Explorer. Even Explorer 6 still pops little spaces in where you least expect it!

That's just one example of browser display problems that can give you fits! Technically, there's nothing wrong with your code when you place some extra carriage returns for increased readability. The difference is in how browsers interpret your code.

Unless you have a professional-quality testing lab in your office, you may never realize there's a problem until a client or customer finds it for you. That's what makes NetMechanic's Browser Photo such a helpful tool for all webmasters - from beginners to experts. Browser Photo shows you actual screen shots of your Web page in 16 different browser and operating system combinations.

Use it to take the initiative. Find and fix display problems before your visitors notice them. Browser Photo is easy-to-use, Web-based, and affordable! It's the best present you can give your Web site this year.



Rate This Tip:
Not Useful Useful Very Useful   
 
NetMechanic Tools
HTML Toolbox
Browser Photo
Server Check
Search Engine Starter
Search Engine Tools
GIFBot
Newsletter
HTML Tutorial and Tips
Search Engine Tutorial
Accessibility Information
Browser Problem Tutorial

Company Info
Products
About Us
Contact
Advertise
Link To Us
Jobs
Privacy Policy
Partner Programs
Press Room
RSS Feed
Support
 



Powered by Overture!

 
     
 
   
 
     


Keynote Home
Copyright © 1996-2007,
Keynote NetMechanic
All rights reserved.