W3C home > Mailing lists > Public > www-style@w3.org > August 2013

Re: [CSS21][css3-text] letter-spacing, word-spacing and justification

From: Bert Bos <bert@w3.org>
Date: Wed, 14 Aug 2013 17:05:24 +0200
To: www-style@w3.org
Message-Id: <201308141705.24797.bert@w3.org>
On Friday 09 August 2013 05:21:58 fantasai wrote:
> On 07/31/2013 06:18 PM, Bert Bos wrote:
> > That changes the meaning of 'letter-spacing' as it has been used
> > until now (and which I've been relying on).
> You're relying on the fact that UAs do not put gaps between
> Latin letters in order to justify the documents you've written.
> I don't think you need to worry: I'm pretty sure this will
> continue to be true as long as there as at least one space
> character within each line of your text. :)

I'm not so sure. Given that there are newspapers (even mainstream ones) 
that squeeze or stretch the letter spacing rather than fall back to 
ragged margins, and given that CSS was explicitly written to allow that, 
I think there will be and very likely already are implementations of CSS 
that vary the letter spacing as well as the word spacing.

It is difficult to specify limits on how much letter spacing and word 
spacing may shrink or stretch. It depends on the line height and on how 
much they stretch in the previous and next lines. And thus CSS2 didn't 
provide such controls and instead expected implementations to seduce 
users by the quality of their algorithms. There are many authors but few 
typographers, and thus their expertise should go into the 
implementations, to benefit all authors.

But with letter-spacing, unlike with word-spacing, there is also a 
simple switch that is clear to everybody and whose effect is visible to 
the untrained eye, and that is whether letter spacing is used for 
justification at all or not. (I'm not talking about micro-adjustments, 
such as the Zapf's Hz program does; letter-spacing is not meant to 
forbid that.) Many people prefer a ragged margin over visibly squeezed 
or spaced letters, and thus CSS provides that switch.

I often put 'letter-spacing: 0' in documents I care about. I don't know 
what implementations people use (or will use in the future) to render 
those documents, but I can express that in my chosen style correct 
kerning is preferred over justified margins, in case such a conflict 

And you say "as long as there is at least one space." But what about the 
case that there is none? My preference of correctly kerned letters over 
justification does not depend on how many word spaces there are.

I don't want

1)  T h e   p e n u l t i m a t e
    impoverishment  was  not  the
    last one.

(non-zero letter spacing) nor

2)  The               penultimate
    impoverishment  was  not  the
    last one.

(uneven word spacing) nor

3)  T             h             e
    impoverishment  was  not  the
    last one.

(letter spacing again) but rather

4a) The  penultimate
    impoverishment  was  not  the
    last one.

4b) The
    impoverishment  was  not  the
    last one.

It is easy for people to recognize 1 and 3 and say they don't want it, 
and that is why CSS2 provides 'letter-spacing: 0'. Exactly how bad 2 is 
is difficult to express, and so I'd leave it to the implementations.

(Maybe implementations can provide knobs just for the user (not for the 
author) to adjust details of the layout. That might be useful to fine-
tune the printing, e.g.)

> Are you concerned that you have lines of text without spaces
> that would suddenly start being letter-spaced for justification?
> > Besides, using inter-letter spacing for justification is something
> > you don't want to happen by default. If you have a really
> > difficult text, you may want to explicitly enable it, if there is
> > no other option.
> Non-Western texts will hit the "really difficult text" situation
> much more frequently, and the spec needs to allow for that.

The default in CSS is to allow automatic letter spacing (when the UA 
decides it is suitable, e.g., based on the font). You're talking about 
the case where you want to set a non-zero letter spacing and still want 
to allow the letter spacing to vary (a little). That's a feature that is 
not yet in CSS, but we can add it. E.g.:

a) Added to 'letter-spacing':

    letter-spacing: 0.2em 0.3em 0.5em /* min/optimal/max */

b) Added to 'letter-spacing':

    letter-spacing: 0.3em flexible    /* leave to implementation */
    letter-spacing: 0.3em normal      /* same, re-using the keyword */

c) Added via a new property:

    text-justify: distribute

(Option b might be best, see below.)

> > I propose explaining under the <length> value of 'letter-spacing'
> > that the space between letters may still be varied for the
> > purposes of
> > 
> > justification if 'text-justify' is set to 'distribute':
> >      User agents may not further increase or decrease the
> >      inter-character space in order to justify text <ins>except if
> >      'text-justify' is 'distribute'</ins>.
> This isn't sufficient, because a lot of justification in CJK
> is not of the 'distribute' variety. The 'distribute' version
> distributes spaces equally between Latin letters as between
> CJK letters. But usually justification will distribute space
> between CJK letters on the line and *not* between Latin letters.
> Besides, it's confusing if the meaning of 'letter-spacing: 0'
> changes based on 'text-justify'!

The meaning of 'text-align' also changes based on 'text-justify', so I'm 
wondering if what is confusing isn't the existence of 'text-justify' 
as such.

Besides, the name is wrong, because it is not really the *justification* 
algorithm you want to influence, but the line breaking one, because even 
in text with ragged margins, you don't want the margins to be too 
ragged, the last line too short or too long, two lines to start with the 
same word, or "rivers" of white to occur.

What typographers expect, beyond letter spacing on or off, is a way to 
set relative weights for the different aspects of justification. There 
are almost no absolutes in typography, everything is interdependent.

Justification can be done in part by squeezing and stretching the spaces 
between words. There is a lower limit, obviously, but no hard upper one; 
it depends on the line height, the line should also not look too 
different from the previous and the next and the whole paragraph should 
not look darker than the previous and the next.

It can also be done by hyphenating words. Hyphenation should be avoided 
unless the lines would look too full or too empty without it; and 
several hyphenated lines in a row start looking like a pattern, so that 
should be avoided even more; but again there is no hard limit.

You can also squeeze the letters closer together or space them out 
(unless they are connected, such as in fonts that mimic handwriting, or 
in Arabic). If you do that to a whole paragraph and only a very little 
bit, it may be better than not having justification at all. Some 
typographers in some contexts might even prefer justification over quite 
bad letter spacing. My guess is that ideographs can be spaced more than 

You can also change the letter shapes in small ways (Zapf's Hz program).

You can also change the font size. That can be done to a paragraph if it 
is quite isolated (a heading, e.g.), or you can do it to the whole page.

You can try replacing words or phrases by synonyms, if the author 
provided some. (That is a feature HTML should provide, I think.)

You can also allow the last line of the paragraph to be a bit shorter or 
longer than is desirable to relieve the stress on the preceding lines.

Printers in past centuries also replaced words by abbreviations, but I 
think in current practice it is better to leave it to the author to 
explicitly provide an abbreviation as an alternative. (Maybe in Braille 
there are standard abbreviations that can be applied automatically.)

And at some point you give up and just make the line short (or long, if 
it cannot be broken).

TeX provides the notion of "badness" for this: each of the aspects (in 
so far as TeX supports them; I actually hoped (some) CSS implementations 
would do better than TeX, given that computers had become thousands of 
times faster...) can be given a numeric value, which is meaningless in 
itself, but can be compared with the values of the other aspects. And 
there is another value that represents the maximum overall badness: if 
you reach that value, you give up and let some line be short or long.

The problem is that it is quite difficult to express a policy through 
those numbers. In practice, when line breaks turn out bad or 
justification fails, you tweak things locally. And in fact, the first 
thing you do is rewrite the text. Then, if justification is really 
important in that paragraph, you might try to increase the maximum 
allowed badness by a little bit. And then you give up, or do something 
radical, like adding an extra image or put the whole paragraph in bold.

Letter spacing really makes the text look different, that's why CSS has 
an explicit switch for that. Plus, with certain cursive fonts it cannot 
be used at all. Font size is also quite visible, and I think that should 
have an explicit switch as well. The other aspects (word spacing, glyph 
squeezing, amount of hyphenation, number of hyphens in a row, 
alternative content, min/max length of last line) are very gradual in 
their effect, and how much you notice them depends not just on their own 
magnitude, but also on how different they are from one line to the next 
and from one paragraph to the next.

No doubt some typographers will want to have control over the balance 
between these methods, but I think what they really want is not so much 
to set the balance for a whole document as to use their own smarts 
rather than the computer's to decide in each difficult case what the 
best solution is: in one paragraph it may be an extra hyphenation and in 
the next one a longer last line. That is because not just the visual 
aspects, but also the meaning of the text and its function on the page 
play a role in that decision.

Manual intervention is fine in print or PDF (there is only one rendering 
and potentially thousands of readers will see it) but not when the line 
breaks depend on the screen size, on the screen resolutions, on the 
rendering software, on the speed of the hardware, on the available 
fonts, on the user's preferences, etc.

I guess what I'm heading towards is

  - Drop 'text-justify'
  - Add 'letter-spacing: <length> && normal' to mean that <length> is
    added between the letters, but that the UA may add a little more or
    less if necessary to get acceptable line breaks.
  - Add a <choose> element to HTML with <option> children and a CSS
    property to say 'CHOOSE {display: alternatives}' or something like
  - Add something on 'font-size' to say that the actual font size may be
    a bit more or a bit less in order to get better justification of the
    paragraph, maybe 'font-size: 2em variable'.

Variable letter spacing may be different (a little bit) between 
successive lines. Word spacing may also differ a bit between 
successive lines. Font size should scale by the same factor for the 
whole paragraph.

For the rest it is up to each renderer to do the best it can given 
current technology and current hardware. (And that may be quite 
different from one implementation to the next. As it already is, of 
course. Or between now and five years from now. At least I hope it 

W.r.t. variable font sizes, maybe there should be a distinction based on 
whether the height (block progression direction) is fixed or not: if it 
is and the font size is variable, then the font size should be as large 
as possible so that the contents still fit in the box, and font size is 
then not used for justification...

> I don't think what you're worried about -- excessive use of
> letter-spacing between Western letters -- is going to be a
> problem in practice. UAs will do sensible things for Western
> text: we just have to allow them to do sensible things for
> non-Western, texts, too!

CSS was designed more then 10 years after TeX and thus I expected many 
implementations of CSS to deliver better layout than TeX, given the 
advances in computers and algorithms. CSS was written so as to allow 
implementations to do the best they could and improve as technology 
advanced, without requiring changes in the style sheet, let alone in CSS 
itself. E.g., avoiding "rivers" of white in a paragraph was too 
expensive in 1982, but in 1998 I expected some browsers would add it. 
But even in 2013 they still don't.

Anyway, css3-text describes some reasonable ways for implementations to 
apply variable spacing and I'm not sure we need to give authors more 
control than whether to allow/disallow variations in letter-spacing and 

In some cases, such as for high-volume printing, the typographer should 
have ways to tweak individual paragraphs, because any automatic layout 
will fail sometimes. But I'm not convinced it is useful to add those 
tweaks to CSS.

> Also, on a consistency note, right now
>    word-spacing: normal;
> and
>    word-spacing: 0;
> both mean the same thing: the space between words is not altered
> from its default, but is allowed to justify. It's more consistent
> if
>    letter-spacing: normal;
> and
>    letter-spacing: 0;
> also meant the same thing: the space between letters is not
> altered from its default, but is allowed to justify.
> Don't you think that makes sense?

No, why should they be "consistent"? What is consistency in this case? 
They are different properties with different functions in typography. 
There are almost no use cases for 'word-spacing', but 'letter-spacing' 
is quite common. 'Word-spacing: normal' was a mistake that I regretted 
almost as soon as it became REC. There shouldn't have been such a 
keyword. We also have 'line-height' with the values 'normal' and '0', 
which is consistent with 'letter-spacing', because the two values do not 
mean the same thing.

  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos                               W3C/ERCIM
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France
Received on Wednesday, 14 August 2013 15:05:59 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:33 UTC