views:

260

answers:

4
+5  Q: 

Sentence Spacing

+8  A: 

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.

Brian Campbell
This disables `text-align: justify`, otherwise it seems like it would be the best answer.
Roger Pate
Hmm. If you care about exact spacing, why would you use `justify`? In that case, then, I would test out ` ` on a variety of browsers, and see if that works for you.
Brian Campbell
I use justified text for other reasons, but sentence spacing should still be wider than word spacing.
Roger Pate
Can't arbitrarily kern ". ", as it appears with "Dr. Z" or even "U.S. of A.". ensp and emsp have the same problem as nbsp, in that you get whitespace before and after individual lines, but I do agree they are better choices than nbsp.
Roger Pate
For those cases, what you would do is kern ". " but not ". ". I wouldn't guarantee that browser rendering engines will actually use different kerning for those two pairs; in fact, I believe that WebKit doesn't do kerning at all (I know it doesn't do ligatures for English text). So, really, until the browsers get a lot more serious about good typography, and are willing to sacrifice rendering speed for it, I don't think that there will be an ideal solution for your problem.
Brian Campbell
I initially missed your requirement of nbsp after non-sentence-terminating periods. I think that would kill such a proposal for practical reasons, even if such interpretations required a special CSS property. And yes, the additional rendering time (I couldn't measure it), and even extra bandwidth, wasn't an issue for me in this project.
Roger Pate
+1  A: 

&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.

nickf
+2  A: 

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

Gazzer
I had thought of this and almost included it in my "obvious solution" list, but discarded it. However, it is currently the only suggested solution that meets the requirements with the least presentation drawbacks. (Source code drawbacks notwithstanding.) I used padding-right in my sample.
Roger Pate
I'm curious why it was downvoted, could you leave a comment?
Roger Pate
Yeah, this idea is possibly the most practical solution today, even though it does involve adding a lot of markup.
Brian Campbell
It's interesting because perhaps there is a semantic reason to wrap a complete utterance (usually a sentence) in a span. For children learning, foreign languages, blind readers and so forth it might come in handy somehow. I'm not saying I'd do it myself, but I don't see a semantic reason to dismiss it outright. Other solutions have suggested adding spaces of some sort, and since we are adding something anyway I'd thought along the lines of 'why not this as you're not affecting the content'.
Gazzer
I've run into issues with nested tags, but only because I wasn't using this before, and they were easy enough to resolve. This really is a content issue better resolved by a character than XML tree---saying "end of a sentence, *right here*", just like space characters between words say "end of word, start a new one"---but emsp and related are currently unsatisfactory. I guess that character is supposed to be periods, but it's overloaded too much to easily distinguish. Anyway, I implemented this solution for the project.
Roger Pate
+2  A: 

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.)

bmoeskau
Interestingly the poll on the linked page (currently 14584 votes) has 47% in favor of additional sentence spacing, with an additional 8% that apparently use or work with the additional spacing daily (the third option).
Roger Pate
Personally I still double-space most of my writing out of habit, although I've noticed that when typing in IM or on my iPhone I've changed to single space to save keystrokes (not sure why I still use 2 in other media...) I think it's become more of a stylistic thing nowadays than a matter of correctness. I'd be curious to hear what a professional editor would say about it.
bmoeskau
Various sources I've read agree that after WW2, companies like magazines and book publishers adjusted many previous practices in the interest of saving paper and cost; and that such practice became precedent for today. That justification doesn't apply to me (but not obviously so, it's certainly possible to use HTML for print layout), but my audience is different from theirs anyway.
Roger Pate