title: HTML whitespace: spaces before and after <br>
body: <p>I am trying to better understand the HTML whitespace processing model. Right now I'm comparing two HTML snippets:</p>
  
  <pre><code>&lt;div&gt;a &lt;br&gt;z&lt;/div&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;div&gt;a&lt;br&gt; z&lt;/div&gt;
  </code></pre>
  
  <p>The first snippet, when renered, yields two lines: <code>"a "</code> and <code>"z"</code> (So the first line has a trailing space.)</p>
  
  <p>The second snippet yields two lines: <code>"a"</code> and <code>"z"</code>. There is no leading space on the second line.</p>
  
  <p>My question is: why? I'm currently using this <a href="http://www.w3.org/TR/CSS2/text.html#white-space-model">http://www.w3.org/TR/CSS2/text.html#white-space-model</a> as a reference. It states</p>
  
  <blockquote>
    <ol>
    <li>If a space (U+0020) at the beginning of a line has 'white-space' set to 'normal', 'nowrap', or 'pre-line', it is removed.</li>
    <li>All tabs (U+0009) are rendered as a horizontal shift that lines up the start edge of the next glyph with the next tab stop. Tab stops occur at points that are multiples of 8 times the width of a space (U+0020) rendered in the block's font from the block's starting content edge.</li>
    <li>If a space (U+0020) at the end of a line has 'white-space' set to 'normal', 'nowrap', or 'pre-line', it is also removed.</li>
    <li>If spaces (U+0020) or tabs (U+0009) at the end of a line have 'white-space' set to 'pre-wrap', UAs may visually collapse them.</li>
    </ol>
  </blockquote>
  
  <p>A naive reading of this would indicate that, since a space that the beginning <em>or</em> end of a line is to be removed (when 'white-space' is 'normal'), the first of my snippets ought to result in no trailing space. But that isn't the case.</p>
  
  <p>So what's going on?</p>
  
  <p>My current theory is that the <code>&lt;br&gt;</code> is secretly counted as a "character" which, in the first snippet, prevents the trailing space from being at the "end" of its line. But I really have no idea.</p>
  
  <p>EDIT: To be clear, I know how to use <code>&amp;nbsp;</code> to create spaces at will. My question is about what rule (with regard to some spec) induces the above behavior.</p>