-1

I have a question related to HTML. In order to demonstrate my simple question, I will use a minimal example.

Consider the following HTML content:

<html>
Foo: Bar 
</html>

When you call this in a browser, it displays "Foo: Bar" in one line. So far so good.

However had, when you do almost the same, and store this:

<html>
Foo
: Bar 
</html>

In other words, if you add a newline right before the ':' character, then suddenly the display becomes this here:

"Foo : Bar"

Now I wonder where from the ' ' comes? Because that character is not part of the original source.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
shevy
  • 920
  • 1
  • 12
  • 18
  • http://stackoverflow.com/editing-help – Matt Ball Oct 27 '13 at 19:02
  • possible duplicate of [Why does the browser renders a newline as space?](http://stackoverflow.com/questions/588356/why-does-the-browser-renders-a-newline-as-space) and [How do line breaks in your HTML affect your resulting page's spacing?](http://stackoverflow.com/q/14886354/139010). The short version (as always): because [that's what the spec says.](http://www.w3.org/wiki/CSS/Properties/white-space#Values) – Matt Ball Oct 27 '13 at 19:04

1 Answers1

1

In HTML a carriage return or line feed in the source code is treated as white space and rendered as a space. Multiple spaces or white space (CR, LF, tabs, etc.) amount to a single white space on the rendered page.

So if you have 50 carriage returns in your source code between Foo and : Bar it will render a one space (Foo : Bar) when th HTML page is displayed in the browser.

From the HTML 4.01 spec: Controlling line breaks.

Sébastien
  • 11,860
  • 11
  • 58
  • 78