Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In HTML and CSS, how do I make japanese text break lines correctly?

I'm writting a simple paragraph in both English and Japanese, using only HTML and CSS. The English text breaks lines normally (when a word doesn't fit on a line anymore, it's pushed to the next one).

With Japanese though, not a whole word is pushed to the next line, but part of it only. I've tried setting word-wrap to break-word and normal, but nothing changes (with the Japanese text).

How to I make whole words in Japanese jump to the next line like it happens in English?

like image 824
Rodrigo Bezerra Avatar asked Mar 09 '11 17:03

Rodrigo Bezerra


People also ask

What is line break in CSS?

CSS line-break Property The line-break property specifies how to break lines of Chinese, Japanese, or Korean text working with punctuation and symbols. But, these languages have different rules. This line break might not occur.

How to break text in Japanese?

Alternatively, if you know the start and end of the words, you could perhaps wrap each one in a span - then use CSS to ensure each span wraps to a new line as a whole when it doesn't fit. Show activity on this post. Japanese has specific rules that are followed when breaking text. They are called 禁則処理 (kinsoku shori).

Is there a line break between hyphens in Chinese and Japanese?

But, these languages have different rules. This line break might not occur. For example, if the value is set to "strict", break before hyphens are not allowed in Chinese and Japanese languages. The CSS specification emphasizes rules only for Chinese, Japanese and Korean.

Can I use word breaks for Chinese/Japanese/Korean (CJK)?

Word breaks should not be used for Chinese/Japanese/Korean (CJK) text. Non-CJK text behavior is the same as value "normal" Sets this property to its default value. Read about initial Inherits this property from its parent element.


2 Answers

English separates words with spaces, Japanese doesn't.

Whether characters in Japanese form a word or not depends on context. In many cases, looking for certain grammatical (Kana) particles could be used to separate words - but this wouldn't even be close to being reliable.

Essentially, you'd need a Japanese dictionary / understanding of the language to identify where the words start and end - a browser won't know how to do this.

Alternatively, if you know the start and end of the words, you could perhaps wrap each one in a span - then use CSS to ensure each span wraps to a new line as a whole when it doesn't fit.

like image 170
Michael Avatar answered Sep 19 '22 11:09

Michael


Japanese has specific rules that are followed when breaking text. They are called 禁則処理 (kinsoku shori). Here is a link explaining the rules. The rules are mostly concerned with special characters. Have a look at any popular Japanese webpage and you will see that multi-character (kana and kanji) words are often split. I often see です split between lines.

Update: I stumbled across this tool recently. I haven't tried it out yet, but the theory is solid. If someone is looking to improve the line breaks with Japanese text this could be a good solution.

like image 33
John Avatar answered Sep 19 '22 11:09

John