Tailwind CSS Typography
Tailwind CSS's Typography(typography) feature is a set of utilities that help developers efficiently design text styles. It includes basic typographic properties such as font family, font weight, line height, letter spacing, and text alignment, while also supporting complex typographic needs such as responsive font sizes, text shadows, text decorations, etc.
1. Font Family
Tailwind provides some utility classes to set font families (font-family), which can be easily applied through class names.
Common Utility Classes:
font-sans: Set a sans-serif font.font-serif: Set a serif font.font-mono: Set a monospace font.
Example
Test text content ...
Test text content ...
Test text content ...
Try it »
2. Font Size
Font size can be controlled through Tailwind's text-* utility classes, supporting a range from text-xs to text-9xl to various sizes, and you can even customize font sizes.
Common Utility Classes:
text-xs,text-sm,text-base,text-lg,text-xl,text-2xl, ...,text-9xl
Example
Test text content ...
Test text content ...
Test text content ...
Test text content ...
Test text content ...
Try it »
3. Font Weight
Font weight can be controlled through font-* utility classes, Tailwind provides a range from font-thin to font-black to various weight options.
Common Utility Classes:
font-thin: Extra thin fontfont-light: Light fontfont-normal: Normal fontfont-medium: Medium weight fontfont-semibold: Semi-bold fontfont-bold: Boldfont-extrabold: Extra bold fontfont-black: Black (extremely bold) font
Example
Test text content ...
Test text content ...
Test text content ...
Test text content ...
Test text content ...
Try it »
4. Line Height
Line height (i.e., line spacing) can be controlled through leading-* utility classes. Tailwind provides various line height options, from leading-none to leading-loose, which can be adjusted as needed.
Common Utility Classes:
leading-none: Line height of 1leading-tight: Tight line heightleading-snug: Slightly tight line heightleading-normal: Default line heightleading-relaxed: Relaxed line heightleading-loose: Loose line height
Example
So I started to walk into the water...
So I started to walk into the water...
So I started to walk into the water...
Try it »
5. Letter Spacing
Letter spacing can be controlled through tracking-* utility classes. Common letter spacing options include tracking-tight、tracking-normal and tracking-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
Example
Test text content ...
Test text content ...
Test text content ...
Try it »
6. Text Color
Tailwind provides a variety of text color classes, allowing you to set different colors for text. You can use text-* utility classes to set colors.
Common Utility Classes:
text-gray-500: Medium graytext-red-500: Redtext-blue-500: Bluetext-green-500: Green
Example
Test text content...
Test text content...
Test text content...
Test text content...
Test text content...
Try it »
7. Text Alignment
Tailwind provides simple utility classes to control text alignment. You can use text-left、text-center or text-right to set the alignment of text.
Common Utility Classes:
text-left: Left alignedtext-center: Center alignedtext-right: Right aligned
Example
This is left-aligned text
This is center-aligned text
This is right-aligned text
Try it »
8. Text Decoration
You can use the underline, line-through and no-underline to control underlines and strikethrough on text.
Common Utility Classes:
underline: Add an underlineline-through: Add a strikethroughno-underline: Remove the underline
Example
Test text content ...
Test text content ...
Test text content ...
Test text content ...
Try it »
9. Text Transform
Tailwind provides uppercase、lowercase and capitalize classes to control text capitalization.
Common Utility Classes:
uppercase: All uppercaselowercase: All lowercasecapitalize: Capitalize the first letter of each word
Example
Test text content ...
Test text content ...
Test text content ...
Test text content ...
Try it »
10. Text Shadow
Tailwind allows you to add shadow effects to text, using text-shadow utility classes.
Common Utility Classes:
text-shadow: Set a simple text shadow (this feature requires a custom plugin or extension).
Example
This text has a shadow effect
Try it »
11. Responsive Font Size
Tailwind supports responsive design; you can set different font sizes at different screen sizes. By adding prefixes for different screen sizes such as sm:, md:, lg:, xl: , you can control the font size.
Example
This is responsive text size
Try it »