Can I use CSS to justify text with hyphenating words at the end of a line?

user1158415 picture user1158415 · Mar 1, 2012 · Viewed 16.8k times · Source

I have a div that is too narrow to text-align:justify (gaps too wide), but yet looks un-uniform when right- or left-justified, because then there is a large gap at the end of lines. Left-justified looks best, but could I use hyphenation, like in books? Using CSS?

Answer

Jukka K. Korpela picture Jukka K. Korpela · Mar 1, 2012

You can use hyphens: auto provided that you have declared the content language in HTML, e.g. using <html lang=en-US>.

Browser support is still limited but getting better, see http://caniuse.com/css-hyphens

For good quality, you may need to manually control hyphenation e.g. by using soft hyphens (&shy;) in words that might otherwise be hyphenated wrong.