Sub topic 3
Alignment, Wrapping, Truncation, and Line Clamping
Assume you know HTML, the CSS box model, CSS units, and have Tailwind CSS installed. This chapter focuses on text layout and responsive utility composition.
Text layout utilities
Use text-left, text-center, or text-right to align text. Tailwind's whitespace-* utilities control whether text wraps. whitespace-normal allows wrapping, while whitespace-nowrap keeps text on one line. break-words prevents a long word or URL from overflowing its container.
The truncate utility is shorthand for single-line ellipsis behavior. It applies hidden overflow, no wrapping, and an ellipsis. Use line-clamp-3 when text may occupy three lines and then needs truncating. Line clamping requires Tailwind v3.3 or later.
<div class="max-w-prose text-left">
<h2 class="truncate text-xl font-semibold">A title that stays on one line</h2>
<p class="break-words line-clamp-3 text-base/7 text-gray-600">
Long content can wrap naturally, break difficult words, and stop after three lines.
</p>
</div>Readable line length
max-w-prose limits text to a measure suited to reading, usually about 65 characters per line. Use max-w-md, max-w-lg, or another max-w-* utility when a fixed scale value better matches the design. A width limit is useful even when the parent spans the whole screen.
Responsive variants
Tailwind is mobile-first. An unprefixed class applies everywhere. A prefixed class overrides it at that breakpoint and above.
For example, p-4 md:p-8 increases padding from medium screens upward. The same pattern works for text-lg md:text-xl, widths, gaps, and margins.
One-off values
Use square brackets when the design needs a value outside the configured scale: w-[320px], mt-[3px], or text-[18px]. Use this sparingly. Repeated arbitrary values usually indicate a missing theme token.
Extending the theme
For a repeated value, add a named token. In Tailwind v3, place it under theme.extend.spacing. In Tailwind v4, define --spacing-* inside @theme. Named tokens keep class names consistent across components.
Responsive article card
<article class="mx-auto max-w-prose p-4 md:p-8">
<h2 class="text-2xl font-semibold leading-snug md:text-3xl">
Article title
</h2>
<p class="mt-2 line-clamp-3 text-base/7 text-gray-600">
Summary text remains readable while longer content is safely limited.
</p>
<div class="mt-6 flex flex-wrap gap-4">
<a href="#" class="text-sm font-medium">Read more</a>
<a href="#" class="text-sm font-medium">Share</a>
</div>
</article>Exercise
Which utility combination limits a paragraph to three lines and prevents long words from overflowing?
Show answer
Use line-clamp-3 break-words, together with a width constraint such as max-w-prose.