TIL `hyphens: auto` does not add hyphens for capitalized words (in English at least).
extraordinarily (wraps with hyphen)
Extraordinarily (no wrap no hyphen)
Adding `word-break: break-word` breaks the capitalized word, but still no hyphen 🤨
Demo (applies to Firefox and Chrome, working in Safari): https://codepen.io/zachleat/pen/myeYbJV
14 replies
@zachleat It’s allowed but not required per spec. Safari does hyphenate the capitalized word
@famulimas yeah, I noticed that! I think Safari’s behavior is more predictable here, fwiw
@zachleat Yeah, kind of a bummer, as it doesn’t distinguish between words that are capitalized mid-sentence (probably proper nouns) and words that are capitalized because they start a sentence…
@db I see your point, yeah! That they distinguish based on capitalization seems odd to me
@zachleat Finding bugs in the text layout engine always feels like a special nerdy treat.
@harris I don’t think this is a bug (fwiw) but maybe an intentional choice, per https://front-end.social/@famulimas/115181215027069621
but it was a fun one to learn!
@zachleat yes, this is language dependant. Each browser has hyphenation dictionaries for various languages. In German, you’ll notice that there is hyphenation for capitalized words. This would actually be a very good Interop issue.
I’ve got some demos I made in the past for this…
With English: https://knowler.dev/demos/tp0-gpS?codepen
With a German word: https://knowler.dev/demos/idITprB?codepen@knowler oh great test cases! I noticed the same behavior in English for dictionary words and gibberish too 🤔
@zachleat It gets interesting when you combine `hyphens: auto` and `word-break` haha: https://sunny.garden/@knowler/113964937944456245
@knowler seeing some breaks with hyphens and some not (on the same word) is BOTHERING ME 😅
@zachleat A good place to start could be making some WPTs for this, but I imagine that, like @famulimas notes, since it’s not required by the spec, it might not be accepted. I personally would expect Safari’s behaviour to be correct. I’ve ventured into some browser codebases to see if I could fix this, but I think it could be dependency related.
A pet peeve of mine is that #NetNewsWire, my feed reader which I otherwise love, breaks article titles rather aggressively with hyphens.
This means you get headlines like:
> They Could Not Believe Al-
> pacas Had It All.Which is not about Artificial Intelligence-made pacas, but about Alpacas.