tags:

views:

204

answers:

9

Does it matter ever , Whitespace between HTML elements in source? when we give style through CSS? and need cross browser compatibility

For any browser?

+1  A: 

Compare these two lines in a browser:

<img src="..." /> <img src="..." />
<img src="..." /><img src="..." />

You'll see that there is a space between the images in the first line, but not the pair in the second.

Douglas
+5  A: 

Yes, for example: pretty much any time the data is inline.

Compare:

<p>H<b>e</b>llo, world</p>

and

<p>H <b>e</b> llo, world</p>
David Dorward
so should we always remove whitespace in source?
metal-gear-solid
No. `<b>Hello</b> world` has whitespace that you want to keep. Whitespace is significant and cannot be arbitrarily added or removed.
David Dorward
A: 

No browsers always ignore whitespace as long as its between tags.

aWrongun
+1  A: 

Depending on the amount of whitespace within the html, css, or other files, it could have an impact on how long it takes to download to the user's system.

Mike Chess
+1  A: 

ie6 used to put gaps inbetween some tags when rendered. It also matters when Office 2009 renders it's html emails using word. If you have linespaces it can put in 2px gaps.

DavidYell
+1 can u give any example of IE6?
metal-gear-solid
From another forum,You're allowing IE6 to introduce its whitespace bug.IE sees a space inside an empty div, and applies line-height to it. Thediv will then be expanded in IE6 (and older) to accommodate this space.There's your gap.Simplest solution is to make sure IE6 understands that the empty divreally _is_ empty, by putting a comment inside it and make sure there'sno line-break.Change to this...</div><!-- /footer --><div class="bottomsm"><!-- --></div></div><!-- /sidebar -->...and there will be no more gap.
DavidYell
+2  A: 

Whitespace does matter, but all whitespace is treated as one space. For example,

<span>hello</span> <span>there</span>

Will be rendered by a browser exactly the same as

<span>hello</span>         <span>there</span>

Unless a <pre> tag is being used.

Graham Clark
or the whitespace: pre css style is used: http://www.quirksmode.org/css/whitespace.html eg, you can't know whether whitespace is important without also knowing what css is used.
Douglas
Or          if          the   whitespace                  is          of          the          non-breaking          variety.
Brock Adams
A: 

As pointed out by Douglas and David Dorward, white space does matter.

However, in HTML blocks (i.e. not javascript or other embedded content-types), all consecutive white space are equivalent to a single white space. That is, hello <b>world</b> is equivalent to

hello   
            <b>world</b>

The exception to this rule is within <pre>..</pre> blocks, which are white space sensitive by specification.

fmark
`"all consecutive white space are equivalent to a single white space"`This is not true! See           non-breaking           whitespace,           for example.
Brock Adams
A: 

It depends on the content model of the element containing the whitespace. If the model is text-derived, including when it is mixed elements and text, then the whitespace matters (though multiple whitespace characters are usually collapsed into one and leading/trailing space removed entirely, with the exception of inside a <pre>). If the model only admits element content, then whitespace has no significance at all; e.g., whitespace between a <ul> and its <li>s is supposed to be wholly unimportant.

Donal Fellows
+2  A: 

Text areas are also affected with whitespace between opening and closing tags as it assumes any content between the two are its content that it should show....

Andy