Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 37 ยท Typography, Color and Effects

Fonts, Text and Typography Utilities

Style text with Tailwind v4: font families, the size scale with built-in line heights, weight, tracking, alignment, decoration, wrapping, line-clamp and lists.

Most of the web is text, so typography utilities are among the ones you will use most. Because Preflight removes the browser's default heading and paragraph styles, every size, weight and line height is something you choose on purpose. This lesson walks through the typography utilities in the order you usually apply them: family, size, weight, spacing, alignment, decoration, and finally how long text wraps or truncates.

Font family

Three families ship in the theme, defined as variables: font-sans (the default, a system UI font stack), font-serif and font-mono. Add your own web font in the theme (chapter 6) and a font-display utility appears.

HTML
<p class="font-sans">System UI text</p>
<p class="font-serif">Serif text for long reading</p>
<code class="font-mono">monospace for code</code>

Font size and the built-in line height

text-{size} sets both font-size and a matching line-height:

Class Size Line height
text-xs 0.75rem (12px) 1.333
text-sm 0.875rem (14px) 1.428
text-base 1rem (16px) 1.5
text-lg 1.125rem 1.556
text-xl 1.25rem 1.4
text-2xl 1.5rem 1.333
text-3xl 1.875rem 1.2
text-4xl 2.25rem 1.111
text-5xl to text-9xl 3rem up to 8rem tighter

Larger text gets proportionally smaller line height, which is what good type design wants. To override the line height at the same time, use a slash: text-sm/6 is a 0.875rem font with line-height: 1.5rem (6 on the spacing scale), and text-lg/tight uses a named leading.

Weight, style and spacing

  • Weight: font-thin (100), font-extralight, font-light (300), font-normal (400), font-medium (500), font-semibold (600), font-bold (700), font-extrabold, font-black (900). Variable fonts accept any value with font-[550].
  • Style: italic, not-italic.
  • Line height: leading-none, leading-tight (1.25), leading-snug, leading-normal (1.5), leading-relaxed (1.625), leading-loose (2), or the scale: leading-6.
  • Letter spacing: tracking-tighter, tracking-tight, tracking-normal, tracking-wide, tracking-wider, tracking-widest. Large headings look better slightly tight (tracking-tight), small uppercase labels slightly wide (tracking-wide).
  • Numbers: tabular-nums makes digits equal width so columns of numbers line up; slashed-zero and ordinal are also available.
A type scale

Alignment, case and decoration

  • Align: text-left, text-center, text-right, text-justify, plus text-start and text-end which follow the language direction.
  • Transform: uppercase, lowercase, capitalize, normal-case.
  • Decoration: underline, overline, line-through, no-underline. Style it with decoration-{color}, decoration-2 (thickness), decoration-wavy or decoration-dotted, and underline-offset-4 for spacing.
  • Wrapping the whole text block: text-wrap (default), text-balance evens out the lines of a heading, text-pretty avoids a single orphan word at the end of a paragraph, text-nowrap prevents wrapping.
  • Indent: indent-8 indents the first line.

Inline a elements have no underline after Preflight (links inherit the text color). Add what you need: text-indigo-600 underline decoration-indigo-300 underline-offset-4 hover:decoration-indigo-600.

Long text: truncate, clamp and break

  • truncate cuts a single line with an ellipsis (it is overflow-hidden text-ellipsis whitespace-nowrap).
  • line-clamp-3 limits a paragraph to three lines and adds an ellipsis; line-clamp-none removes it. This is how card previews stay a uniform height.
  • break-words (overflow-wrap: break-word) breaks long words such as URLs at the edge; break-all breaks anywhere; wrap-anywhere is available in v4 and plays better with flex items.
  • whitespace-pre-wrap preserves line breaks and spaces, for a text area's content; whitespace-nowrap keeps a label on one line.
Wrapping, clamping and decoration

Lists and text color

Preflight also removes list bullets. Bring them back with list-disc, list-decimal or list-none, and the position with list-inside or list-outside:

HTML
<ul class="list-disc space-y-1 pl-5 marker:text-indigo-500">
  <li>First</li>
  <li>Second</li>
</ul>

marker: is a variant that styles the bullet itself. Text color works with text-{color}-{shade} and opacity (text-slate-900/70); see Colors and Opacity.

Using custom fonts

To use a web font such as Inter or a self-hosted file, load it with @font-face (or a <link> from a font provider), then declare it in the theme so a utility exists:

CSS
@theme {
  --font-display: "Fraunces", serif;
}

Now font-display works like font-sans. Chapter 6 covers @theme fully.

A sensible typographic system

  1. Pick 4 to 6 sizes (text-sm, text-base, text-lg, text-2xl, text-4xl) and reuse them.
  2. Use weight and color, not just size, to separate levels: font-semibold text-slate-900 for titles, text-slate-600 for body, text-slate-500 for captions.
  3. Keep line length near 65 characters with max-w-prose (see Sizing).
  4. Body text should have at least 4.5:1 contrast with its background.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does text-sm/6 set?

    The slash adds a line-height modifier: sm size, and leading equal to spacing step 6 (1.5rem).
  2. 2. Which class limits a paragraph to three lines with an ellipsis?

    line-clamp-{n} clamps the number of lines. truncate is for a single line.
  3. 3. Which class is best for aligning digits in a table column?

    tabular-nums makes all digits the same width so numbers line up.
  4. 4. Why does a link look like plain text in a Tailwind page?

    Preflight makes links inherit color and removes the underline; add them back with utilities.
  5. 5. Which class balances the line lengths of a heading?

    text-balance evens out line lengths, avoiding a heading that ends in one short word.

Summary

  • font-sans/serif/mono, text-{size} (with built-in line height), font-{weight}, leading-* and tracking-* cover the basics.
  • text-sm/6 combines size and line height; tabular-nums aligns numbers.
  • Align, transform and decorate with text-center, uppercase, underline decoration-*; wrap with text-balance and text-pretty.
  • truncate, line-clamp-* and break-words control long text; list-disc restores bullets.

Next: Colors and Opacity