w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.46k stars 658 forks source link

[css-text-4] typographic widows/orphans #2396

Closed fantasai closed 1 year ago

fantasai commented 6 years ago

In https://www.w3.org/mid/0BD85DFF-A147-44EF-B18A-FF03C3D67EF0@verou.me @LeaVerou wrote:

In typography, orphans are lone words at the end of a line. However, in CSS, the orphans property controls the minimum number of lines in a block container that must be left at the bottom of a page, not the minimum number of words at the end of a line. Is there anything planned for typographic orphans?

fantasai commented 1 year ago

Some earlier discussion on this topic: https://www.w3.org/Style/CSS/Tracker/issues/241.html

litherum commented 1 year ago

I actually implemented this years ago (named -apple-trailing-word: -apple-partially-balanced) as a nonstandard property because we got some internal requests for this. (I then removed support once our internal teams stopped using it). And now we're getting more internal requests for this.

It's not just internal requests, though:

This is something we'd like to see added to CSS.

We could either do it the way I did years ago (a simple on/off switch) or we could mirror the design of orphans and widows and have it take an integer value.

faceless2 commented 1 year ago

See also https://github.com/w3c/csswg-drafts/issues/7704 on the same topic

I made the comment there that I liked the syntax used by PrinceXML - they use a non-standard extension to widows for this:

Another feature in Prince for Books are the "fractional widows": the widows property is allowed a value expressed as percentage.

    p {
      widows: 50%;
    }

This indicates that one widow line is accepted, as long as the line width is at least the given percentage value of the available page width, to avoid the worst case of having a widow line that is only one or two words long.

See https://www.princexml.com/doc/prince-for-books/#fractional-widows

clagnut commented 1 year ago

In https://clagnut.com/blog/2424/ I wondered about a value for text-wrap whose sole purpose is to prevent widows, without any other formatting involved. One could borrow a bit from the widows property:

text-wrap: 2 widows

Where 2 in this case specifies the minimum number of words allowed on the final line of a text block. There would have to be slightly more to it than this, in particular a single word should be allowed if the final two words together would be too long to fit inside the text block.

kojiishi commented 1 year ago

Is it the number of words or the width of the last line authros want to control? In other words, do you want to avoid 1 word in the last line even if it's a very very long word, or are you happy with the last line having 3 very short words?

Note that the text-wrap property will be reset to wrap by the white-space property, so you might want a separate property.

clagnut commented 1 year ago

This topics seems to be covered in a few places now. Might be best to bring it all together: the discussion in this thread is not identical but closely related and will probably involve the same conclusion, and relates more directly to the relevant section in Text Module Level 4.

litherum commented 1 year ago

Duping to https://github.com/w3c/csswg-drafts/issues/3473