Sub topic 11
Keeping line length readable with max-w-prose and max-w-* utilities
This chapter assumes you know the CSS box model, the class attribute, and the rem, px, and % units. It also assumes you have used w-* and max-w-* utilities from the sizing chapters. You need a project with Tailwind CSS installed.
Why line length matters
The line length of a block of text is called its measure. When lines are too long, the reader's eye loses its place when it jumps from the end of one line to the start of the next. When lines are too short, the eye jumps too often and the text feels choppy.
A common guideline is 45 to 75 characters per line, with about 66 as the ideal for body text. This is a guideline, not a rule. Narrow columns, captions, and code blocks can fall outside it.
A block-level element such as <p> or <div> fills the width of its parent by default. On a wide monitor, an unconstrained paragraph can run 200 characters or more per line. You fix this by limiting the width of the text container, not by shrinking the whole page.
Two ways to cap the measure
Tailwind gives you two kinds of max-w-* utility. Both set the CSS max-width property. They differ in the unit they use.
| Utility | CSS | Unit it measures in |
|---|---|---|
| `max-w-prose` | `max-width: 65ch` | Characters |
| `max-w-md` | `max-width: 28rem` | Root font size |
| `max-w-2xl` | `max-width: 42rem` | Root font size |
| `max-w-[60ch]` | `max-width: 60ch` | Characters (arbitrary value) |
| `max-w-full` | `max-width: 100%` | Parent width |
The ch unit equals the width of the 0 (zero) glyph in the element's own font. It is a rough stand-in for "one character." Because the width follows the font, 65ch produces about the same number of characters per line whether the text is 16px or 20px. A rem-based cap does not adjust this way. If you raise the font size inside a max-w-2xl container, fewer characters fit on each line.
Here is the same paragraph in both kinds of container:
<div class="max-w-prose">
<p class="text-base/7">
This paragraph is limited to roughly 65 characters per line, and the limit
follows the font size of the container.
</p>
</div>
<div class="max-w-2xl">
<p class="text-base/7">
This paragraph is limited to 42rem. The number of characters per line
depends on the font size and font family in use.
</p>
</div>In the first block, max-w-prose sets the maximum width to 65ch. In the second, max-w-2xl sets it to 42rem, which is 672px when the root font size is 16px.
Centering the capped block
max-width stops a block from growing. It does not move the block. A block capped at 65ch inside a wider parent sits against the left edge, and the space on the right stays empty. Pair the cap with mx-auto to center it:
<article class="mx-auto max-w-prose px-4">
<h1 class="text-3xl font-bold tracking-tight">A readable article</h1>
<p class="mt-4 text-base/7 text-gray-700">
The article is centered, never wider than 65ch, and has side padding so
the text does not touch the screen edge on small devices.
</p>
</article>mx-auto sets both horizontal margins to auto. The browser splits the leftover horizontal space equally between them. This only works when the element has a width that is smaller than its container, which is why the max-w-prose cap matters.
The px-4 class is also deliberate. On a screen narrower than 65 characters, the article fills the whole width. Without horizontal padding, the text would touch the screen edges.
Max-width vs. width
You can limit the measure with w-* or max-w-*. Prefer max-w-* for text.
w-[65ch]fixes the width at 65 characters. On a phone narrower than that, the text overflows and forces horizontal scrolling.max-w-proselets the block shrink with the screen and only stops it from growing past 65 characters.
You can also combine them. w-full max-w-prose is common when the element is a flex or grid child that would otherwise shrink to its content. In a flex container, a child's width comes from its content, so w-full asks it to take the available space and max-w-prose then caps it.
The prose utilities versus the typography plugin
Do not confuse max-w-prose with the prose class from the @tailwindcss/typography plugin. They are separate things.
max-w-proseis a core utility. It only setsmax-width: 65ch.prosecomes from the optional typography plugin. It styles headings, lists, links, and other elements inside a block of rendered Markdown or CMS content.
The plugin's prose class also applies a max-width: 65ch by default. That is why a block with class="prose" already has a limited measure. If you want a wider block of prose content, add max-w-none or a larger cap, such as prose max-w-3xl. Adding max-w-prose on top of prose is redundant.
The named max-width scale
The max-w-* family includes more than prose. The default scale in Tailwind v3 and v4 includes these named sizes.
| Class | Value | Pixels at 16px root |
|---|---|---|
| `max-w-xs` | `20rem` | 320 |
| `max-w-sm` | `24rem` | 384 |
| `max-w-md` | `28rem` | 448 |
| `max-w-lg` | `32rem` | 512 |
| `max-w-xl` | `36rem` | 576 |
| `max-w-2xl` | `42rem` | 672 |
| `max-w-3xl` | `48rem` | 768 |
| `max-w-4xl` | `56rem` | 896 |
| `max-w-5xl` | `64rem` | 1024 |
| `max-w-6xl` | `72rem` | 1152 |
| `max-w-7xl` | `80rem` | 1280 |
Other values are available too: max-w-none (no limit), max-w-full (100%), max-w-screen-md and its siblings in v3 (these match the breakpoints), and max-w-fit, max-w-min, and max-w-max for content-based sizing. In v4, the max-w-screen-* classes are replaced by max-w-(--breakpoint-md) style references, so check your version's documentation before relying on them.
Two heuristics for choosing between them:
- Use a character-based cap (
max-w-proseormax-w-[Nch]) for the text itself. The measure is a property of reading, so a unit tied to characters fits. - Use a
rem-based cap (max-w-3xl,max-w-7xl) for page layout containers, such as the outer wrapper of a page. These caps control layout, and they do not need to track the font.
A typical page uses both: a wide outer container with max-w-7xl, and a narrower inner column with max-w-prose for the article text.
A common mistake: capping the wrong element
The cap must go on an element that contains the text and is a block-level box. These errors come up often:
- Capping a parent that has several children. If a
max-w-prosewrapper holds a heading, a paragraph, and a wide image, all of them are limited to 65ch. This is fine for an article. It is wrong if the image should be wider than the text. - Capping an inline element.
max-widthhas no effect on a non-replaced inline element such as<span>. Use a block element, or add theblockclass. - Forgetting that the cap uses the element's font.
chis based on the font of the element that has themax-w-*class, not of the paragraph inside it. If you putmax-w-proseon a wrapper with the default 16px font and the paragraph inside usestext-xl, the paragraph gets fewer characters per line than expected. To avoid this, put the cap on the same element that sets the font size, or on the text element directly.
The third point is the one that most often surprises people. This example shows it:
<div class="max-w-prose">
<p class="text-2xl">
The wrapper measures 65ch in a 16px font, so this larger paragraph fits
fewer than 65 characters per line.
</p>
</div>
<div class="max-w-prose text-2xl">
<p>
Here the wrapper sets the font size, so 65ch is measured in the larger
font and the paragraph holds about 65 characters per line.
</p>
</div>Using a diagram to decide
The flow below summarizes how to pick a cap for a given element.
Customizing the measure
If 65ch is not right for your design, you have three options.
- Use an arbitrary value for a one-off:
max-w-[55ch]. - In Tailwind v3, add a named value under
theme.extend.maxWidthintailwind.config.js. - In Tailwind v4, define a
--container-*variable in an@themeblock.
// tailwind.config.js (Tailwind v3)
module.exports = {
theme: {
extend: {
maxWidth: {
measure: '60ch',
},
},
},
}/* app.css (Tailwind v4) */
@import "tailwindcss";
@theme {
--container-measure: 60ch;
}After this, max-w-measure is available in your markup. Define a named value when the measure repeats across many pages. A name such as measure also tells the next reader why the width exists.
Edge cases
- Narrow screens. On a screen narrower than the cap, the cap does nothing. This is the desired behavior.
- Headings. Headings are often larger and shorter than body text. They can sit inside the same capped column, or you can let them run wider if the design calls for it.
- Mixed languages. The
chunit is based on the0glyph. Languages with wider or narrower characters, such as Chinese or Japanese text, do not map cleanly to a character count, so adjust the value by testing. - Fonts with unusual widths. In a very condensed or very wide typeface,
65chyields noticeably more or fewer characters than 65. Check with real content.
Exercise
A paragraph uses class="text-xl" and sits inside <div class="max-w-prose">, which has the default 16px font. The line length looks too short, about 52 characters. Why does this happen, and what is a one-class fix?
Show answer
The ch unit in max-w-prose is measured in the font of the element that carries the class, which is the 16px wrapper. The paragraph uses a larger font, so fewer characters fit in the same width. Move text-xl onto the wrapper (<div class="max-w-prose text-xl">) so 65ch is measured in the larger font.
Exercise
Write the classes for an article container that is centered, never wider than about 65 characters, and keeps 1rem of space from the screen edges on small devices.
Show answer
mx-auto max-w-prose px-4. The max-w-prose class caps the width at 65ch, mx-auto centers the capped block, and px-4 adds 1rem of horizontal padding.