This note continues String Processing for the Web. It mainly records CSS typesetting, in this order: setting the language, wrapping, truncation, trimming the space above and below text, spacing between Japanese and Latin text and punctuation, and palt.
DEMO
Set the language and reading direction
The browser looks at an element's lang and changes wrapping, hyphenation, and the shape of quotation marks. Put the language of the whole page on html. When another language appears in the middle, mark that element as well. An English proper name left under html lang="ja" keeps hyphenation and quotation marks on the Japanese rules.
<html lang="ja">
<p>参照は<span lang="en">Garden Eight</span></p>
</html> Reading direction is set with dir. For a page that proceeds from right to left, such as Arabic, put dir="rtl" on html. The next example also marks that the English name is read from left to right.
<html lang="ar" dir="rtl">
<p>راجع <span lang="en" dir="ltr">Garden Eight</span></p>
</html> Decide where to wrap
A long filename that overflows its box and a heading that leaves only the last character on the next line call for different properties. The demo that compares CSS one property at a time changes one declaration at a time, with the same sample sentence and the same width.
| Property | Role | Main target |
|---|---|---|
white-space | Whether to collapse white space and line breaks, and whether to wrap lines | Short UI, body text, and entered text |
overflow-wrap | Whether to break in the middle only when the text does not fit | Any language |
word-break | Where the usual break opportunities are | Latin text, CJK, and Southeast Asia |
line-break | How strict the CJK line-breaking restrictions are | Mainly CJK |
hyphens | Whether to hyphenate Latin words | Latin text |
text-wrap | How length is distributed across lines | Headings and body text |
white-space
white-space decides whether to preserve spaces and line breaks, and also whether to wrap automatically. The initial value normal collapses consecutive white space and does not keep line breaks in the source as forced breaks.
nowrap treats spaces and line breaks the same way as normal and stops only automatic wrapping. Use it for short elements that should not wrap midway, such as buttons, navigation, numbers, and single-line truncation.
Text from a CMS field or a textarea can keep consecutive spaces and line breaks while still wrapping if you set pre-wrap.
.label {
white-space: nowrap;
}
.user-text {
white-space: pre-wrap;
} break-spaces also preserves spaces and line breaks, but it treats the position after each preserved space as a wrap opportunity, and spaces at the end of a line take width as well. Use it only when the white space itself needs to be visible, not for ordinary body text.
overflow-wrap
This decides whether to break a long word or URL that does not fit on the line. anywhere wraps inside a word only when it does not fit. With the initial value normal, a long URL can overflow the box.
Both anywhere and break-word break a word that does not fit, but they differ in how the box's minimum width is calculated. anywhere includes the mid-word breaks in the minimum width (min-content). break-word does not, so a Flexbox child is more likely to grow wider than its parent.
word-wrap is an alias of overflow-wrap, so it is generally not used. In CSS Text, word-break: break-word is deprecated, and the property that breaks is overflow-wrap.
word-break
This property decides where a word may break. As a rule, leave the initial value normal as it is.
break-all breaks inside English words, so English becomes harder to read. Writing that does not separate words with spaces, such as Thai, also breaks in the middle. keep-all suppresses wrapping between CJK characters. In Japanese, wrapping then happens only at limited positions such as punctuation, so Japanese text overflows easily. In Thai, wrapping at dictionary word boundaries remains, so it does not overflow in the same way as Japanese.
Putting break-all or keep-all on body makes text break too often or not enough, depending on the language.
Some languages also do not separate words with spaces, so a dictionary is needed to decide where to wrap (CSS Text). For Thai body text, set lang="th" and leave word-break at normal. In Korean, the space left at the end of a line changes between normal, which wraps between syllables, and keep-all, which prefers word units.
line-break
line-break sets how strict the restrictions are for CJK punctuation and symbols. In the specification, the required differences among loose / normal / strict appear for CJK. In Japanese, strict makes small kana and the prolonged sound mark less likely to come at the start of a line. In Chinese and Korean, it can also affect how punctuation, iteration marks, and middle dots break. Placing it on English body text barely changes where long English words break.
hyphens
This decides whether Latin words are hyphenated at the end of a line. The initial value manual splits only at soft hyphens (­) placed in the source, and auto splits with the browser's dictionary. The splitting rules for auto depend on lang. Adding it as a shared rule on Japanese body text does not give it the same role.
text-wrap
text-wrap does not break long words. It decides how lines are divided after wrapping. pretty prioritizes layout quality over speed and chooses breaks while looking across multiple lines. That can include avoiding a final line that is too short or reducing differences in line length, but the specific improvements are left to the browser.
When only the last character of a heading is left on the second line, text-wrap: balance can wrap so that the lines come closer in length. Even when the lengths match, a proper name can still break in the middle, so change the heading width and check the break as well.

Body CSS by language
This is an example of applying the settings above to body text on a multilingual site. Handling for long URLs goes on .prose as a shared rule, and only the differences are added for each language. Japanese, Chinese, and Korean receive line-breaking restrictions, and English receives hyphenation. Korean wraps between syllables. keep-all is also a candidate when word units should be kept. Thai stays on the shared rules.
/* Shared */
.prose {
overflow-wrap: anywhere;
word-break: normal;
}
/* Japanese and Chinese */
.prose:lang(ja),
.prose :lang(ja),
.prose:lang(zh),
.prose :lang(zh) {
line-break: strict;
}
/* Korean */
.prose:lang(ko),
.prose :lang(ko) {
line-break: strict;
/* Add word-break: keep-all when wrapping by word */
}
/* Thai stays on the shared rules */
/* English */
.prose:lang(en),
.prose :lang(en) {
hyphens: auto;
} Truncate to a set number of lines
When a heading on a list card should stop at two lines, wrap it and hide from the third line on. .line below is an example that turns the end that does not fit on one line into “…”, and .clamp is an example that shows up to two lines. Both leave the full text in the HTML, so a wider card shows more characters.
.line {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.clamp {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
} Single-line truncation stops wrapping with white-space: nowrap, so an overflow-wrap rule that breaks a long URL in the middle no longer applies.
With the initial value of text-overflow, clip, drawing stops at the overflow, so a glyph can be cut in the middle. The specification says ellipsis hides text by grapheme cluster and then places “…”. A custom string and values for both ends of a line also exist, but support depends on the environment.
When the limit is a character count, handle the cut in JavaScript rather than CSS. How to count is summarized in String Processing for the Web.

Trim the space above and below text with text-box-trim
In a horizontal paragraph, the first line can leave space above the letters and the last line can leave space below them. With text-box-trim, you can trim these outer edges while keeping the spacing between lines. For example, if a heading sits beside an image and its letters start a little below the top of the image, apply trim-start to the heading to trim just the top of the first line.
.text {
line-height: 1.5;
text-box-edge: cap alphabetic;
text-box-trim: trim-both;
} The demo sets “FILM” and “FESTIVAL” on two lines. All four examples use the same line height. none keeps the original spacing, trim-end trims below the last line, and trim-both trims both outer edges, as in the code above. The distance between the two baselines stays the same.
text-box-edge sets the font metrics used for trimming. Here, cap alphabetic uses the cap height and the alphabetic baseline. A lowercase “g” can extend below that baseline. For a Japanese heading, check the distance to the edge with the actual typeface and text.
Spacing between Japanese and Latin text, and trimming punctuation
The demo that compares CSS one property at a time also compares the boundary between Japanese and alphanumeric characters, and brackets at the start of a line.
Writing 「画像をWebPに変換する」 can make the gap between 「を」 and 「W」, and between 「P」 and 「に」, look tight. Adding a half-width space in the body leaves that space in a copied string as well. text-autospace can adjust the visible spacing while keeping the original string.
.prose:lang(ja) {
text-autospace: ideograph-alpha;
}
.prose:lang(ja) h2 {
text-spacing-trim: trim-start;
} In this example, spacing is inserted only at the boundary between Japanese and Latin letters, so the spacing in 「第3回」 stays as it is. When spacing is also wanted beside digits, specify ideograph-alpha ideograph-numeric.
When a heading starts with a bracket, as in 「『作品名』について」, the line of the bracket looks inset from the body text even with the same left alignment. text-spacing-trim: trim-start trims the spacing included in an opening bracket at the start of a line. It also applies to the start of a wrapped line, so check a two-line heading in the font you actually use.
In a browser that does not support text-autospace or text-spacing-trim, those declarations are ignored and the text is shown as before.
Changing character widths with palt
font-feature-settings: "palt" is Proportional Alternate Widths. OpenType fonts for Japanese advance each character on a full-width basis, but palt leaves the glyph as it is and changes that width to a proportional width. Some fonts have kerning built for the widths after palt, so add kerning with font-kerning: normal.
font-variant-east-asian: proportional-width is the separate feature pwid, which substitutes proportional-width glyphs. It is not used together with palt.
There is also the option of placing Yaku Han JP first in font-family when only punctuation should be half-width.
References
- CSS Text Module Level 4 — Spacing
- CSS Text Module Level 4
- CSS Overflow Module Level 4
- Design Notes 04: Language and Form
- ※ This article is an AI translation of the Japanese original.









