Explain it simply
Explain it simply
Open a well-made book and you will notice that the lines have room to breathe, and no line is so long that your eyes have to travel far to the right. Text on a website needs the same care. In CSS, the text properties leave the letter shapes alone and control the space between lines, the alignment, the spacing between letters, underlines and how lines wrap.
Myanmar text has vowel signs and stacked consonants above and below the base letters, so it usually needs more line-height than English. In this lesson readability comes before decoration.
Problem → Why → Solution
The problem: a fixed-height box that stops fitting its text
A developer gives a notice bar a fixed height: 48px so it matches the design exactly. With a short English sentence it looks fine. Then the Myanmar translation goes in, the text wraps onto a second line, spills out of the bottom of the box and overlaps the content below. The same thing happens when a user zooms the browser to 200%.
.notice {
height: 48px; /* fits one short English line only */
line-height: 48px; /* "vertical centering" that breaks on line two */
white-space: nowrap; /* later added to hide the overflow... */
}Why does this happen?
With a fixed height the browser cannot grow the box when the content grows, so the extra text overflows and is drawn outside the box. line-height: 48px only looks centered for one line; a second line needs 96px. Hiding it with nowrap just cuts the sentence off. Let the content decide the height, using padding and a unitless line-height instead.
Core concept: the parts of a readable line
line-height sets the height of each line box, and the space beyond the font-size is split between the top and bottom of the line. A unitless number such as line-height: 1.8 is multiplied by each element's own font-size. A value with a unit, such as 1.5em or 24px, is computed once on the parent and the resulting pixel value is inherited, so a 32px heading inside it gets a 24px line-height and its lines overlap. Body text usually sits between 1.5 and 1.8, headings between 1.1 and 1.3.
Line length matters as much as line-height. When lines are very long, the eye struggles to find the start of the next line. max-inline-size: 65ch stops a block from growing wider than 65 "0" characters. inline-size is the size along the writing direction, left to right for English and Myanmar, so for these languages this logical property behaves exactly like width.
text-align: start instead of left automatically aligns right in right-to-left languages such as Arabic. justify tends to open wide gaps between words in narrow columns. Keep letter-spacing for headings and short uppercase labels; extra spacing in body text slows reading, and in scripts such as Myanmar it can make words look broken apart. text-transform: uppercase only affects scripts that have letter case and changes nothing in Myanmar text.
The last piece is wrapping. The browser breaks lines at spaces (for Myanmar it estimates word boundaries instead). A long URL with no spaces offers no break point, so it runs straight out of its box. overflow-wrap: anywhere allows a break between any two characters, but only when there is no better place. All of these properties work best when the content, not a fixed height, decides how tall the box is.
| Property | Useful value | Purpose |
|---|---|---|
| line-height | 1.5 – 1.8 (unitless) | Space between lines |
| max-inline-size | 60ch – 75ch | Line length |
| text-align | start | Align with writing direction |
| overflow-wrap | anywhere | Break long URLs |
- Width comes from inline-size
- Words are wrapped into that width
- Each line gets line-height of height
- text-align places words in the line
A text box's height should come from line count times line-height, never from a fixed height.
General pattern
selector {
max-inline-size: 65ch; /* line length */
line-height: number; /* unitless ratio */
text-align: start | center | end;
letter-spacing: small-em; /* labels and headings */
overflow-wrap: anywhere; /* long words or URLs */
text-decoration: line style color;
}Decide in order: width limit, line spacing, alignment, letter spacing, wrapping, decoration lines. Writing letter-spacing in em keeps it proportional when the font-size changes.
Example: article text and a link style
This example has two classes. .article-text makes blog paragraphs easier to read, and .article-link removes the default underline and replaces it with a border line in the link's own color. Notice that a line is still there, so readers can still see it is a link.
.article-text {
text-align: left;
line-height: 1.8;
letter-spacing: 0.01em;
}
.article-link {
text-decoration: none;
border-bottom: 1px solid currentColor;
}Code breakdown
- Line 2
text-align: left;Left-aligned lines share one straight left edge, so the eye finds the next line easily. If you support right-to-left languages, start is the better choice.
- Line 3
line-height: 1.8;Unitless, so it is 28.8px at a 16px font-size and 36px for 20px text inside, keeping the ratio at every size. 1.8 also leaves room for Myanmar marks above and below the letters.
- Line 4
letter-spacing: 0.01em;One hundredth of the font-size, barely visible. In body text, letter-spacing should stay this small or be left out.
- Lines 8-9
border-bottom: 1px solid currentColor;text-decoration: none removes the underline and border-bottom draws a line along the bottom of the link's box. currentColor makes the line follow the link color. The line sits a little lower than an underline and never cuts through descenders.
Paragraphs in .article-text are left-aligned, with lines spaced 1.8 times the font-size apart (28.8px at 16px) and a hair of extra letter spacing. .article-link has no underline; instead a 1px line in the link's own color runs along the bottom of the link.Styling underlines and truncating text
Modern browsers let you keep the underline and restyle it: text-underline-offset moves the line away from the text and text-decoration-thickness sets its weight. To cut a single-line card title off with an ellipsis, you need all three properties below; without the first two, text-overflow does nothing.
a {
text-decoration-thickness: 2px;
text-underline-offset: 0.2em;
}
.card-title {
white-space: nowrap; /* 1. keep it on one line */
overflow: hidden; /* 2. clip what does not fit */
text-overflow: ellipsis; /* 3. show "..." at the cut */
}
.comment { overflow-wrap: anywhere; } /* long URLs wrap instead of overflowing */An ellipsis hides text
Truncated text cannot be read at all. Only use it when the full title is available elsewhere, for example on the detail page.
In real projects
Where this shows up in real projects
News sites, documentation and blogs cap the article column at roughly 60 to 75ch and set line-height around 1.6; typography presets such as Tailwind's prose class bundle exactly these rules. Bilingual Myanmar and English sites often target the lang attribute with a :lang(my) selector to give Myanmar text a separate, roomier line-height.
E-commerce sites truncate product names in grids with an ellipsis, and wrap long strings in user comments, such as pasted links, with overflow-wrap: anywhere; otherwise one long URL makes the whole phone layout scroll sideways. Accessibility audits check that text still fits and stays readable at 200% zoom, which is why reviewers flag fixed heights on text containers.
Common mistakes
Common mistakes
1. Setting line-height with px or em on a parent
body { font-size: 16px; line-height: 1.5em; } passes the computed 24px all the way down to h1. When a 32px heading wraps onto two lines, the lines overlap. Write line-height: 1.5 without a unit.
2. Giving text containers a fixed height
Buttons, badges and notices with height: 40px overflow as soon as a translation is longer, the user zooms in or prefers a larger font. Create the height with padding and use min-height when you need a minimum.
3. Removing link underlines with no replacement
With only text-decoration: none, links are told apart by color alone, and users with color-vision deficiencies cannot find them. Keep the underline and adjust its offset and thickness, or replace it with a border line as the example does.
Best practices
Best practices
- Set a unitless body line-height once on body and override it only for headings.
- After styling, test with the longest Myanmar translation, one long URL and 200% zoom.
- Reserve letter-spacing and text-transform for short labels and headings, never whole paragraphs.
Mini challenge
Mini challenge: a release notes page
Style a release notes article so it reads well on phones and desktops. The long URL at the bottom must not cause sideways scrolling on a 360px screen.
- Cap .post at 65ch and give it a unitless line-height of 1.7
- Give h2 a tighter line-height of 1.25
- Keep the link underline but make it 2px thick with a 0.2em offset
- Uppercase .label with 0.08em letter-spacing, and let .url wrap anywhere
<!doctype html>
<html lang="en">
<style>
.post {
/* TODO: limit line length, add padding, comfortable line spacing */
}
/* TODO: headings need tighter line spacing than body text */
/* TODO: keep the link underline, but thicker and further from the text */
/* TODO: small uppercase label with a little letter-spacing */
/* TODO: let the long URL wrap */
</style>
<article class="post">
<p class="label">Release notes</p>
<h2>What changed in version 2</h2>
<p>Read the <a href="#guide">migration guide</a> before you upgrade.</p>
<p class="url">https://example.com/docs/releases/version-2/migration-guide-for-teams</p>
</article>
</html>Expected: On desktop the article is a column about 65 characters wide; at 360px it fits the screen. Body lines are 30.6px apart (18px font), the heading is tighter, the link has a 2px underline, and the URL wraps over several lines with no sideways scrolling.
Show hint
The ch unit is the width of one "0" character. Put overflow-wrap: anywhere on .url only, not on every paragraph.
Show solution
<!doctype html>
<html lang="en">
<style>
.post {
max-inline-size: 65ch;
padding: 16px;
font-size: 1.125rem;
line-height: 1.7;
text-align: start;
}
.post h2 {
line-height: 1.25;
}
.post a {
color: #1d4ed8;
text-decoration-thickness: 2px;
text-underline-offset: 0.2em;
}
.post .label {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.post .url {
overflow-wrap: anywhere;
}
</style>
<article class="post">
<p class="label">Release notes</p>
<h2>What changed in version 2</h2>
<p>Read the <a href="#guide">migration guide</a> before you upgrade.</p>
<p class="url">https://example.com/docs/releases/version-2/migration-guide-for-teams</p>
</article>
</html>Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- Write line-height without a unit so every child recomputes it from its own font-size.
- Cap line length at roughly 60 to 75ch with max-inline-size.
- Never give text containers a fixed height; use padding and min-height.
- Restyle underlines instead of removing them; an ellipsis needs nowrap, overflow: hidden and text-overflow together.
CSS reference — MDN Web Docs