Description
HTML whitespace collapsing behavior makes it very difficult to directly manage individual spaces rendered in an HTML document. Whitespace collapsing has a few problems today:
- Content management systems cannot just blindly pass text written by a non-developer through to an HTML rendering context. If a user types
Hello, World
in a CMS system, it will be rendered asHello, World
in HTML. The CMS can't really do anything about this to get the document to render as intended by the author without forcing all strings to usewhite-space: pre;
. white-space: pre;
applies to the whole element, but the user might want two spaces in a particular place within that element. For example, maybe I'm one of those people who insists on two spaces at the end of every sentence.
sounds like an easy fix for "Just add a space here", but forces non-breaking and a forced-width behavior the user may not want (when line wrapped,
always takes up one space of width, even when that's not needed). See the line wrapping behavior of this demo as the viewport shrinks. 
is the unnamed entity for a single space, which sounds like it would be a good alternative given that I really want the behavior for a simple space. However, 
is also subject to whitespace collapsing so it can't really solve this kind of problem. This feels especially weird since whitespace collapsing exists as an affordance to developers who want to format their HTML source code differently from the rendered output, but any developer who writes 
clearly wants that space to be rendered as-is. Collapsing those spaces goes directly against developer expectations.
This is a shorter, more focused breakdown on some of the problems with whitespace collapsing, however I wrote a whole blog post digging deeper into the complexity at play here which motivated this particular issue and gives additional context and motivation.
I propose a new &ncsp;
entity which is treated identically to a regular space, however is not subject to whitespace collapsing. You could write Hello,&ncsp;&ncsp;&ncsp;&ncsp;&ncsp;World
and actually get multiple adjacent spaces like Hello, World
.
Edit: It seems it is not possible to add new HTML entities so &ncsp;
as a syntax won't work. However, the key feature request is a non-collapsible space character. The exact syntax for producing that character is an implementation detail.
This would address the above challenges because:
- Content management systems can output
&ncsp;
where white space is significant. - Developers could use
&ncsp;
without having to opt-in an entire element into the rules ofwhite-space: pre;
. &ncsp;
could serve as a drop-in replacement for existing usages of
but present better line wrapping behavior.&ncsp;
would work in the way I wish 
worked and behave in a more predictable fashion.
I'm not 100% which standards body is the right one to own this particular issue, however I filed it here because whitespace collapsing seems to be a part of the css-text
standard. In theory, &ncsp;
is just an alias for a standard space, one which just gets ignored by the whitespace collapsing algorithm. However, as I understand it based on the current layering of browsers, the HTML parser would resolve &ncsp;
into a regular space character, and it would then be impossible for the CSS to disambiguate spaces which originated from &ncsp;
entities. Therefore I suspect this would actually require a brand new Unicode character. If one were added for this purpose, then the existing css-text
standard likely wouldn't need to be changed at all. However, it feels weird to add one solely to solve an HTML issue like this and I'm not sure that's feasible. What exactly would a non-collapsible space do in a non-HTML context? An alternative approach might be for the HTML parser to convert &ncsp;
to a different, user-space Unicode character known by the white-space
spec which gets rendered as a standard space but is otherwise ignored for collapsing. I'm not sure that's a great architectural idea, but its the one solution which comes to mind here.
Feel free to move this issue to whichever standards body makes the most sense to evaluate it.