Text Alignment, Indentation, Spacing and text-transform
Arranging text in its box: text-align with logical start and end, justification and text-align-last, text-indent with hanging indents, letter-spacing and word-spacing, text-transform and its language rules, hanging punctuation and text-autospace.
kvi5hnuCode Sprout team member7 min readOn this page
Font properties choose the glyphs; text properties arrange them. This article covers horizontal alignment, indentation, spacing between letters and words, and case changes. Line breaking and white space are in article 91, and line height in article 93.
text-align
text-align aligns the inline content of a block, line by line, inside the block's content box. It's inherited.

| Value | Effect |
|---|---|
start (initial), end | the start or end of the line in the writing direction |
left, right | physical sides, whatever the direction |
center | centered |
justify | lines stretched to fill the width; the last line is aligned to the start |
match-parent | like inherit, but start and end are resolved using the parent's direction; Chrome only accepts it as -webkit-match-parent |
Use start and end rather than left and right: in a right-to-left language, start is the right side. Tested in Chrome: inside dir="rtl", text-align: start computes to start and aligns to the right.
text-align aligns inline content, including inline-blocks and images, not block children. To center a block itself, use margin-inline: auto (article 39), or flexbox or grid alignment.
Justified text
justify gives straight edges on both sides by widening the spaces. In narrow columns this produces rivers, uneven gaps running down the text, which hurt readability, especially for people with dyslexia. If you justify:
- Turn on hyphenation,
hyphens: autowith alangattribute (article 91), so fewer spaces need stretching. - Keep lines long enough, at least about 45 characters.
- Prefer
startfor body text on the web; WCAG 1.4.8 (AAA) recommends against justified text.
text-justify picks the method: auto, inter-word (widen spaces), inter-character (also between letters, for East Asian text) or none; Chrome 145 and Firefox, not Safari.
text-align-last aligns the last line, and any line before a forced break: text-align-last: center, for example, or justify to stretch the last line too.
text-indent
text-indent indents the first line of a block:
p + p { text-indent: 1.5em; margin-block-start: 0; } /* book-style paragraphs */
Tested in Chrome: text-indent: 2em at 16px computes to 32px. A negative value pulls the first line outward. Two keywords change what is indented:
hanging: indent every line except the first, for bibliographies and definitions:text-indent: 2em hanging.each-line: indent the first line after each forced line break (<br>), too.
Both work in Firefox, Safari and Chrome 146. Without them, a hanging indent is a positive padding-inline-start with an equal negative text-indent:
.references li { padding-inline-start: 2em; text-indent: -2em; }
letter-spacing and word-spacing
letter-spacing adds space after every character; word-spacing adds space to each space between words. Both accept lengths and normal:
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; }
h1 { letter-spacing: -0.02em; } /* tighten large display text slightly */
Rules of thumb:
- Uppercase and small caps need a little extra spacing, about 0.05–0.1em, because capitals are designed to be next to lowercase.
- Large headings often look better slightly tighter; small text never does.
- Use
em, so the spacing scales with the font. Note that the computed value is an absolute length: tested in Chrome,0.1emat 20px computes to 2px, and a child with a different font size inherits that 2px, not 0.1em. Set it on the element that needs it. - Non-zero
letter-spacingturns off common ligatures (article 86).
WCAG 1.4.12 (Text Spacing) requires that content still works when a user overrides spacing to letter-spacing 0.12em, word-spacing 0.16em, line-height 1.5 and paragraph spacing 2em. Avoid fixed heights on text containers, so text can grow.
text-transform
text-transform changes the displayed case, without changing the text in the HTML:
| Value | Effect |
|---|---|
uppercase, lowercase | all capitals, all lowercase |
capitalize | the first letter of each word in capitals |
none | as written |
full-width | characters in their full-width forms, for mixing with East Asian text: Firefox and Safari |
full-size-kana | small kana as full-size, for ruby text: Firefox and Safari |
math-auto | italic for single-letter math identifiers: Chrome and Firefox |
The rules depend on the language, so set lang. Tested in Chrome:
- With
lang="tr",uppercaseturned "istanbul" into "İSTANBUL", with the Turkish dotted capital I. - "straße" became "STRASSE", while the DOM text stayed "straße". That mapping isn't language-specific: it happened with
lang="en"too. capitalizeproduced "Hello World-Wide O'neil": letters after a hyphen were capitalized, but not after an apostrophe.
Write text in normal case in the HTML and apply uppercase in CSS. Text typed in capitals is more likely to be spelled out letter by letter by screen readers, as if it were an acronym. Styled uppercase is usually read as normal words, though VoiceOver may still spell out short ones. What gets copied to the clipboard, the source or the displayed case, varies by browser.
Hanging punctuation and script spacing
hanging-punctuationlets opening quotes and other punctuation sit outside the text box, so the letters align:hanging-punctuation: first last. Safari only.text-autospaceadds a small space between Chinese or Japanese characters and Latin letters or digits:text-autospace: normal; Chrome 140, Firefox 145, Safari 18.4. Tested in Chrome: Japanese text with Latin letters and digits was 15px wider at 30px withnormalthan without it, while leaving the property unset gave no gaps.text-spacing-trimtrims the space around full-width punctuation in East Asian text: Chrome 123.

The last panel shows no-autospace, then normal. The specification makes normal the initial value, but Chrome 157 computes no-autospace unless you set it, so write text-autospace: normal explicitly. The small gaps between the Japanese characters and CSS3 or 100 come from the browser, not from spaces in the text.
body { font: 0.8rem system-ui, sans-serif; margin: 1rem; }
label { margin-inline-end: 0.6rem; }
.eyebrow { margin: 0.7rem 0 0.2rem; text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.7rem; font-weight: 700; color: #8a3b12; }
.col { inline-size: 15rem; font: 0.95rem/1.5 Georgia, serif; text-align: var(--a, start); }
.col.hy { hyphens: auto; }
.col p { margin: 0; }
.col p + p { text-indent: 1.5em; } /* book-style indent instead of a gap */
.refs { list-style: none; padding: 0; margin-top: 0.8rem; inline-size: 15rem; }
.refs li { padding-inline-start: 2em; text-indent: -2em; margin-bottom: 0.3rem; } /* hanging indent */
Pick justify and look for uneven gaps, then turn on hyphenation and see them shrink. The second paragraph uses a first-line indent instead of a margin, and the references use a hanging indent.
What's current
text-indent: hangingandeach-line: all browsers since Chrome 146.text-justify: Chrome 145 and Firefox.text-autospace: all browsers;text-spacing-trim: Chrome only;hanging-punctuation: Safari only.
Common questions
Why doesn't text-align: center center my div?
It centers inline content inside the element, not the element. Use margin-inline: auto with a width, or flex or grid alignment on the parent.
Should I use left or start?
start, so the alignment follows the writing direction.
Why does my justified text have big gaps?
Narrow columns and long words. Add hyphens: auto with lang, widen the column, or use start.
Should I type headings in capitals?
No. Type them normally and use text-transform: uppercase.
Summary
text-alignaligns inline content per line; preferstartandend;justifyneeds hyphenation and wide columns.text-align-lastandtext-justifyrefine justification.text-indentindents the first line;hangingandeach-linechange which lines.letter-spacingandword-spacingtakeemvalues, but compute to absolute lengths that inherit.text-transformchanges displayed case using language rules; keep the source text in normal case.
Practice questions
Write CSS for a bibliography list with hanging indents of 2em, in a way that works in all browsers.
Answer
.bibliography li { padding-inline-start: 2em; text-indent: -2em; }
Or text-indent: 2em hanging, which needs Chrome 146 or later.
A parent has font-size: 10px; letter-spacing: 0.2em, and its child has font-size: 40px. What is the child's letter spacing?
Answer
2px. The computed value is an absolute length, 0.2 × 10px, and that is what the child inherits. Set letter-spacing: 0.2em on the child to get 8px.
What does this show, and what's read by a screen reader?
<h2 style="text-transform: uppercase">Opening hours</h2>
Answer
It displays "OPENING HOURS", while the source stays "Opening hours", so screen readers usually read it as normal words rather than spelling it out, and the HTML is easy to restyle later.
Why doesn't text-align: right work well for a site that's also available in Arabic?
Answer
right is physical: in a right-to-left page it aligns to the start of the line instead of the end. Use text-align: end, which follows the direction.
Previous: The font Shorthand and How Browsers Match Fonts
Next: Text Decoration, Underline Offsets, Emphasis Marks and Text Shadows

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.