Search code examples
csswebkit

How does the browser/rendering engine know where to hypenate a word?


In my CSS, I am using the following snippet of code:

word-break: break-word;
-webkit-hyphens: auto;
hyphens: auto;

How does the rendering engine know where to cut off a word in all the different languages? In Dutch, it's flawless, like a native speaker would hyphenate.


Solution

  • From the W3c spec

    CSS Text Level 3 does not define the exact rules for hyphenation, however UAs are strongly encouraged to optimize their line-breaking implementation to choose good break points and appropriate hyphenation points. Hyphenation opportunities are considered when calculating ‘min-content’ intrinsic sizes.

    and

    Correct automatic hyphenation requires a hyphenation resource appropriate to the language of the text being broken. The UA is therefore only required to automatically hyphenate text for which the author has declared a language (e.g. via HTML lang or XML xml:lang) and for which it has an appropriate hyphenation resource.

    So, basically, each broswer implements their own definitions of where hyphens should be placed. Combined multilingual dictionaries which are probably proprietary.

    See also hyphenate-resource