Tailwind CSS Typography
Tailwind CSS'sTypography(Typography) feature is a set of utility tools that help developers efficiently design text styles. It includes setting basic typography properties such as font family, font weight, line height, letter spacing, text alignment, and also supports complex typography requirements such as responsive font sizes, text shadows, text decoration, and more.
1. Font Family
Tailwind provides utility classes to set the font family, which can be easily applied via class names.
Common utility classes:
font-sans: Sets sans-serif font.font-serif: Sets serif font.font-mono: Sets monospace font.
Examples
<p class="font-serif ...">Test text content ...</p>
<p class="font-mono ...">Test text content ...</p>
Try it Yourself »
2. Font Size
Font size can be controlled through Tailwind'stext-*utility classes, supporting multiple sizes fromtext-xstotext-9xl, and you can even customize the font size.
Common utility classes:
text-xs,text-sm,text-base,text-lg,text-xl,text-2xl, ...,text-9xl
Examples
<p class="text-base ...">Test text content ...</p>
<p class="text-lg ...">Test text content ...</p>
<p class="text-xl ...">Test text content ...</p>
<p class="text-2xl ...">Test text content ...</p>
Try it Yourself »
3. Font Weight
Font weight can be controlled throughfont-*utility classes. Tailwind provides multiple weight options fromfont-thintofont-blackto various weights.
Common utility classes:
font-thin: Extra-light fontfont-light: Light fontfont-normal: Normal fontfont-medium: Medium weight fontfont-semibold: Semi-bold fontfont-bold: Boldfont-extrabold: Extra-bold fontfont-black: Black font
Examples
<p class="font-normal ...">Test text content ...</p>
<p class="font-medium ...">Test text content ...</p>
<p class="font-semibold ...">Test text content ...</p>
<p class="font-bold ...">Test text content ...</p>
Try it Yourself »
4. Line Height
Line height (line spacing) can be controlled throughleading-*utility classes. Tailwind provides various line height options fromleading-nonetoleading-loose, which can be adjusted as needed.
Common utility classes:
leading-none: Line height of 1leading-tight: Compact line heightleading-snug: Slightly compact line heightleading-normal: Default line heightleading-relaxed: Relaxed line heightleading-loose: Loose line height
Examples
<p class="leading-relaxed ...">So I started to walk into the water...</p>
<p class="leading-loose ...">So I started to walk into the water...</p>
Try it Yourself »
5. Letter Spacing
Letter spacing can be controlled throughtracking-*utility classes. Common letter spacing options includetracking-tight、tracking-normalandtracking-wide, used to adjust the space between letters.
Common utility classes:
tracking-tight: Tight letter spacingtracking-normal: Default letter spacingtracking-wide: Wide letter spacingtracking-wider: Wider letter spacingtracking-wide: Widest letter spacing
Examples
<p class="tracking-normal ...">Test text content ...</p>
<p class="tracking-wide ...">Test text content ...</p>
Try it Yourself »
6. Text Color
Tailwind provides various text color classes that allow you to set different colors for text. You can usetext-*utility classes to set colors.
Common utility classes:
text-gray-500: Medium graytext-red-500: Redtext-blue-500: Bluetext-green-500: Green
Examples
<p class="text-sky-400/75">Test text content...</p>
<p class="text-sky-400/50">Test text content...</p>
<p class="text-sky-400/25">Test text content...</p>
<p class="text-sky-400/0">Test text content...</p>
Try it Yourself »
7. Text Alignment
Tailwind provides simple utility classes to control text alignment. You can usetext-left、text-centerortext-rightto set the text alignment.
Common utility classes:
text-left: Left-alignedtext-center: Center-alignedtext-right: Right-aligned
Examples
<p class="text-center">This is center-aligned text</p>
<p class="text-right">This is right-aligned text</p>
Try it Yourself »
8. Text Decoration
You can useunderline, line-throughandno-underlineto control underline and strikethrough on text.
Common utility classes:
underline: Add underlineline-through: Add strikethroughno-underline: Remove underline
Examples
<p class="overline ...">Test text content ...</p>
<p class="line-through ...">Test text content ...</p>
<p class="no-underline ...">Test text content ...</p>
Try it Yourself »
9. Text Transform
Tailwind providesuppercase、lowercaseandcapitalizeclasses to control the case transformation of text.
Common utility classes:
uppercase: Uppercaselowercase: Lowercasecapitalize: Capitalize the first letter of each word
Examples
<p class="uppercase ...">Test text content ...</p>
<p class="lowercase ...">Test text content ...</p>
<p class="capitalize ...">Test text content ...</p>
Try it Yourself »
10. Text Shadow
Tailwind allows you to add shadow effects to text usingtext-shadowutility classes.
Common utility classes:
text-shadow: Sets a simple text shadow (this feature requires a custom plugin or extension).
11. Responsive Font Size
Tailwind supports responsive design, allowing you to set different font sizes for different screen sizes. By adding prefixes such assm:, md:, lg:, xl:to different screen sizes, you can control the font size.
Examples
Try it Yourself »