Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does it ever matter , Whitespace between HTML elements?

Tags:

css

xhtml

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

For any browser?

like image 554
Jitendra Vyas Avatar asked Jun 08 '10 13:06

Jitendra Vyas


4 Answers

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>
like image 182
Quentin Avatar answered Oct 16 '22 10:10

Quentin


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.

like image 29
Graham Clark Avatar answered Oct 16 '22 11:10

Graham Clark


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.

like image 2
Douglas Avatar answered Oct 16 '22 11:10

Douglas


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....

like image 2
Andy Avatar answered Oct 16 '22 12:10

Andy