Sarath
Sarath

Reputation: 9156

Does indenting or white space matter in html?

Ofcourse indenting is need on our markup , but that really matter the way the browser render.?

I have an simple structure with label , span and input. The middle one without indent got a alignment change , why this is happening ?

enter image description here

<label class="field-row">                
       <span class="label-text" >Email</span>
       <input type="email" />
 </label>
 <label class="field-row">
       <span class="label-text" >Email</span><input type="email" />                
 </label>

Demo issue in firefox and chrome

Upvotes: 5

Views: 7436

Answers (2)

Ren&#233; Roth
Ren&#233; Roth

Reputation: 2106

Whitespace makes a difference in the rendering of inline elements, but everything beyond a single one is always reduced to one whitespace.

This means, unless you use the tag <pre>, five white spaces get rendered just the same as a tab or fifty line breaks.

Upvotes: 2

BrotherBallan
BrotherBallan

Reputation: 369

Whitespace does make a difference in page rendering, howevera string of whitespaces longer than one will just be rendered as one whitespace, so this (line break)

<label class="field-row">                
   <span class="label-text" >Email</span>
   <input type="email" />
</label>

and this (no line break, but a whitespace between the span and input)

<label class="field-row">                
   <span class="label-text" >Email</span> <input type="email" />
</label>

will be rendered the same, while this (no whitespace)

<label class="field-row">                
   <span class="label-text" >Email</span><input type="email" />
</label>

will be rendered without that extra space in between the elements.

Upvotes: 7

Related Questions