Skip to content Skip to sidebar Skip to footer

Sentence Spacing

What is the best way to present the additional spacing that should come between sentences (using [X]HTML+CSS)?

Lorem ipsum. Dolor sit amet.

^^ wi

Solution 1:

You can use white-space: pre-wrap to preserve sequences of spaces, while still wrapping text:

<p style="white-space: pre-wrap;">Lorem ipsum.  Dolor sit amet.</p>

This is not supported in IE until IE 8 in IE 8 mode, nor in Firefox until 3.0.

You could also use &emsp; or &ensp; for spaces one em or one en wide. I do not know how widespread support of these is, but they seem to work on the latest WebKit and Firefox on Mac OS X.

A sequence of two &nbsp; characters will prevent line breaks in that space; that's what &nbsp; means, non-breaking space. The sequence A sentence. &nbsp;Another. causes the &nbsp; to appear on the second line, indenting text slightly, which is probably undesireable. The sequence A sentence.&nbsp; Another. works fine, with line breaking and not adding any extra indentation, though if you use it in justified text, with the &nbsp; at the end of the line, it will prevent that line from being properly justified. &nbsp; is intended for the case of writing someone's name, like Mr.&nbsp;Torvalds, or an abbreviation ending with a ., in which typographical convention says that you shouldn't split it across lines in order to avoid people being confused and thinking the sentence has ended.

So, using sequences of &nbsp; is undesirable. Since this is a stylistic effect, I'd recommend using white-space: pre-wrap, and accepting that the style will be a bit less than ideal on platforms that don't support it.

edit: As pointed out in the comments, white-space: pre-wrap does not work with text-align: justify. However, I've tested out a sampler of different entities using BrowserShots (obnoxious ads, and somewhat flaky and slow, but it's a pretty useful service for the price, which is free). It looks like a pretty wide variety of browsers, on a pretty wide variety of platforms, support &ensp; and &emsp;, a few that don't still use spaces so the rendering isn't too bad, and only IE 6 on Windows 2000 actually renders them broken, as boxes. BrowserShots doesn't let me choose the exact browser/OS combos I want, so I can't choose IE 6 on XP to see if that's any different. So, that's a plausible answer as long as you can live with IE 6 on Win2K (and maybe XP) broken.

Another possible solution would be to find (or create) a font that has a kerning pair for the ". " combination of characters, to kern them more widely apart. With @font-face support in all of the major browsers at this point, including IE back to IE 5.5 (though IE uses a different format than the other browsers), using your own font is actually becoming reasonable, and falling back to the users default font if not supported would not break anything.

A final possibility might be to talk the CSS committee into adding a style feature that would allow you to specify that you want wider spacing at the end of sentences (which would be determined by a period followed by a space; acronyms and abbreviations would need an &nbsp; in order to avoid getting the wider space). The CSS committee is currently discussing adding more advanced typography support, so now might be a good time to start discussing such a feature.


Solution 2:

For all you 'antiquated' and 'mono-space-only' naysayers - Read a book. Professional publishers have used a single &emsp; between sentences for time immemorial, and THAT is where the monospace two-space standard came from. Learn from history instead of spouting rhetoric with no basis in fact. I have to admit, though, that an &ensp; looks better in most browsers: &emsp; is just too wide. What do you think of the readability of this paragraph? Stackoverflow's editor allows some HTML, and I'm using &ensp; between all sentences.


Solution 3:

Wrap each sentence in a span, and style the span perhaps. (Not a great solution).


Solution 4:

&nbsp; isn't the correct character to use, semantically speaking. It's a non-breaking space: a space which won't be used as a line break. Perhaps use a space an a &ensp; or a single &emsp;, or (my personal recommendation) don't bother with the antiquated double-space style on your page.


Solution 5:

Just wanted to throw out there that if your goal is to override the default browser whitespace implementation to provide "proper" sentence spacing, there is actually some debate as to what constitutes proper spacing. It seems that the double-space "standard" is most likely just a carryover from when typewriters used monospace fonts. Money quote:

The Bottomline: Professional typesetters, designers, and desktop publishers should use one space only. Save the double spaces for typewriting, email, term papers (if prescribed by the style guide you are using), or personal correspondence. For everyone else, do whatever makes you feel good.

Unless you have this as a strict requirement, it does not seem worth the effort to try and "fix." (I realize this is not an answer to your stated question per se, but wanted to make sure that you are aware of this info as it might influence your decision to spend a lot of time on it.)


Post a Comment for "Sentence Spacing"