I've been trying to better understand (at least at a high level) why the early versions of HTML were designed the way they were. Most of the decisions make sense; I can deduce (at least at a high level) the probable thought process that lead to the design.

But one design decision doesn't make sense to me - whitespace collapsing. In a procedural langauge, whitespace collapsing makes total sense - you wouldn't want different types of whitespace to have different meanings. But HTML is a markup language. Pressing the newline key to start a new line just makes sense; pressing "space" twice when you want two spaces just makes sense. But HTML doesn't let you do this - you have to use <p> or <br> or &nbsp;. Why?

So I had a bit of a Google. And I found an early (earliest?) version of the spec which states

The division of the stream of characters into lines is arbitrary, and only made in order to allow the text to be passed through systems which can only handle text with a limited line length.

But for me - not having lived through the early internet - this just raises more questions. What are "systems which can only handle text with a limited line length", and why would an HTML document need to "pass through" them? And my original question still stands - why was "division of the stream of characters into lines" defined to be "arbitrary"?

Any insight as to what the Cern guys might have been thinking as they designed this would be appreciated.


3 Answers 3


In HTML, line breaks are inserted at rendering time in order to make the line length fit the width of the screen. This is in contrast to both plain text formats and layout formats like PDF where line breaks are inserted at authoring time and fixed.

The purpose is to make HTML readable to various screen sizes and dimensions. A fixed line length is a problem on smaller screen since you have to scroll back and forth for each line, or you have to scale the page down, making the text too small to read. HTML gracefully adapt to any screen size, and allow you to scale the text to a readable size.

HTML does allow forced line breaks with <br> and <pre>, but this should be the exception. Most of the time line breaks should be decided at rendering time. But if a linebreak character in the HTML was interpreted as a forced linebreak, you would have to write a typical HTML document as one single long line in the editor!

Collapsing whitespace allows the author to use line breaks to format the document source in a readable manner, without affecting the readability of the rendered document.

  • Moreover, the tradition of splitting raw text and rendered output predates HTML. You can find it in nroff and LaTeX for instance.
    – mouviciel
    Commented Apr 14, 2022 at 7:38
  • @mouviciel: Yes, HTML itself inherits the principle from previous SGML languages.
    – JacquesB
    Commented Apr 14, 2022 at 8:21

In a procedural langauge...

Why would it matter whether or not the language is "procedural?" HTML is a computer language. It isn't used to describe "procedures," but there are many computer languages that describe things other than procedures. Some of them even count as programming languages.

HTML, like most computer languages, is designed to be viewed as source code in a text/plain editor. The reason why you would not want the number of space characters in between two printing characters to have significance in HTML is the same as the reason why you would not want it have significance in most other text/plain languages. It's not always easy to see how many spaces are there when you're reading the source code.

you have to use <p> or <br> or &nbsp;

Sigh! HTML is a weird mash-up that describes text on multiple levels. <p> is a high-level command that tells the meaning of the text that follows. It says, "Please start a new paragraph, and format it appropriately." <br> takes direct control of the formatting, "I want a line-break here, and don't ask me why." And, &nbsp; is the lowest level of all: It's more a part of the content of the document, and not a formatting instruction at all.

In the realm of markup languages, HTML is old and ad-hoc. I may be wildly speculating here, but if Tim Berners-Lee hadn't been contaminated by exposure to SGML, I wonder if the first web pages might have looked more like Markdown.


Being able to "pass through" systems here means that the meaning of an HTML document should not change when a couple of line breaks are added at arbitrary positions.

Line breaks could be added when you copy and paste your document into an email message. Or in Notepad with "Wrap lines" checked. Or, probably more real-world at the time, when someone types it into an 80x25 characters IBM terminal and (literally) enters the lines one by one, none of which could be longer than 80 characters.

So even within an element (like <p>), any sequence of whitespace must be interpreted as a single space. If you want some particular whitespace you must be explicit about it by using a dedicated element or an entity reference (of the form &somecode;).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.