Tailwind CSS Tutorial menu

Tailwind CSS Typography

Tailwind has a class for every common text style, from size and weight to spacing and alignment.

Font Size

ClassSizePixels
text-xs0.75rem12px
text-sm0.875rem14px
text-base1rem16px
text-lg1.125rem18px
text-xl1.25rem20px
text-2xl1.5rem24px
text-4xl2.25rem36px
text-6xl3.75rem60px

The scale goes all the way up to text-9xl. Each size class also sets a matching line height.

Font Weight and Style

ClassCSS
font-lightfont-weight: 300
font-normalfont-weight: 400
font-mediumfont-weight: 500
font-semiboldfont-weight: 600
font-boldfont-weight: 700
italicfont-style: italic

Example

html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
</head>
<body class="p-8">

<h1 class="text-4xl font-bold text-gray-900">Karachi Food Street</h1>
<p class="text-xl font-medium text-cyan-700 mt-2">Burns Road, open till 2 am</p>
<p class="text-base text-gray-600 mt-4">Try the nihari, the rabri and the famous seekh kebabs.</p>
<p class="text-sm italic text-gray-400 mt-2">Prices change during Ramadan.</p>

</body>
</html>
Try it Yourself »

Font Family

Tailwind gives three font stacks:

  • font-sans: clean fonts like the system UI font (the default)
  • font-serif: fonts with small strokes, such as Georgia
  • font-mono: same-width letters, good for code

Alignment, Spacing and Line Height

ClassWhat it does
text-left, text-center, text-right, text-justifyText alignment
leading-tight, leading-normal, leading-relaxed, leading-looseLine height
tracking-tight, tracking-wide, tracking-widestLetter spacing

Example

html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
</head>
<body class="p-8 max-w-xl">

<p class="text-sm uppercase tracking-widest text-cyan-600 font-semibold text-center">New Batch</p>
<h2 class="text-3xl font-bold text-center tracking-tight mt-1">Learn Web Development</h2>

<p class="leading-tight mt-6 bg-gray-100 p-3">leading-tight: The lines of this paragraph sit close together, which is fine for short headings but hard to read in long text.</p>
<p class="leading-relaxed mt-4 bg-gray-100 p-3">leading-relaxed: The lines of this paragraph have more room, so long text is easier on the eyes.</p>

</body>
</html>
Try it Yourself »

For long paragraphs, combine leading-relaxed with a maximum width like max-w-prose. Very long lines are tiring to read.

Decoration and Transform

ClassEffect
underlineUnderlines text
line-throughDraws a line through text (old prices)
no-underlineRemoves underlines
uppercase, lowercase, capitalizeChanges letter case

Cutting Off Long Text

truncate keeps text on one line and adds "..." if it is too long. It is useful for product names in small cards.

Example

html
<p class="truncate w-48">Samsung Galaxy phone with 256 GB storage and a case</p>

line-clamp-2 shows two lines and then cuts off the rest with "...".

Exercise

Exercise

Which class makes text bold?

Learn Tailwind CSS with a teacher

Join the Web Development course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp