Tailwind CSS Typography Playground

Visualize and customize typography with our interactive playground.
Adjust font scales and preview instantly.

排版控制

12px24px

Major Third - Balanced visual hierarchy

font-sans

Preview

宽度: 1280px

The Art of Typography in Modern Web Design

How to create beautiful, readable content with Tailwind CSS

Design Team

Typography is the cornerstone of effective web design. It's not just about making text look pretty—it's about creating a hierarchy, establishing rhythm, and guiding your readers through your content with ease and clarity.

Why Typography Matters

Good typography improves readability, establishes visual hierarchy, and creates a professional appearance. When done right, users won't even notice it—they'll simply enjoy reading your content.

Typography is what language looks like.

Ellen Lupton

Key Principles

  • Choose appropriate font sizes for different screen sizes
  • Maintain consistent spacing and rhythm
  • Use a modular scale for harmonious proportions
  • Ensure sufficient contrast for readability
  • Limit line length to 60-80 characters

With Tailwind CSS, you can implement these principles using utility classes like text-lg, leading-relaxed, and tracking-tight. The @tailwindcss/typography plugin provides beautiful defaults for prose content.

Tailwind 类名

Title (H1)
text-5xl font-bold tracking-tight font-sans
Body (Body)
text-base leading-relaxed font-sans
Prose 容器
prose prose-slate max-w-none font-sans prose-headings:font-bold prose-headings:tracking-tight prose-p:leading-relaxed prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline prose-strong:font-semibold prose-code:text-pink-600 prose-code:bg-slate-100 prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-pre:bg-slate-900 prose-pre:text-slate-100

Tailwind Configuration

module.exports = {
  theme: {
    extend: {
      fontSize: {
        base: '16px',
      },
      fontFamily: {
        sans: ['system-ui', '-apple-system', 'BlinkMacSystemFont', '"Segoe UI"', 'Roboto', 'sans-serif'],
      },
      typography: {
        DEFAULT: {
          css: {
            fontSize: '16px',
            lineHeight: '1.75',
          },
        },
      },
    },
  },
  plugins: [
    require('@tailwindcss/typography'),
  ],
}

Font Size Reference

ElementSizeLine HeightFont weightLetter Spacing
h139px1.1700-0.025em
h231px1.2700-0.025em
h325px1.3600-0.015em
h420px1.4600-0.01em
body16px1.754000em
small13px1.64000em
caption10px1.54000.01em

Usage Instructions

  • Adjust base font size and scale, view effects in real-time
  • Select different font families, preview typography styles
  • Switch responsive breakpoints, test different screen sizes
  • Copy Tailwind class names for direct use, or export configuration to project
  • Recommend installing @tailwindcss/typography plugin for best results

How to Use Tailwind CSS Typography

Typography is the foundation of great web design. Tailwind CSS provides a comprehensive typography system that makes it easy to create beautiful, readable content. Understanding how to use font sizes, line heights, and the typography plugin can dramatically improve your design workflow and create more professional-looking websites.

Understanding Type Scales

A type scale is a progression of font sizes that creates visual hierarchy and rhythm in your design. Tailwind uses a numeric scale from text-xs to text-9xl. These sizes are based on a modular scale, which ensures harmonious proportions between different text elements.

The most common approach is to use a ratio-based scale, such as the Major Third (1.250) or Perfect Fourth (1.333). This means each step up in the scale multiplies the previous size by the ratio. For example, if your base size is 16px with a Major Third ratio, your heading sizes would be 20px, 25px, 31px, and so on. This creates a natural, pleasing progression that guides the reader's eye.

The Typography Plugin

The @tailwindcss/typography plugin provides beautiful typographic defaults for prose content. Simply add the prose class to any container, and all child elements will receive carefully crafted styles for optimal readability.

<!-- Install the plugin -->
npm install -D @tailwindcss/typography

<!-- Add to tailwind.config.js -->
module.exports = {
  plugins: [
    require('@tailwindcss/typography'),
  ],
}

<!-- Use in your HTML -->
<article class="prose prose-slate lg:prose-xl">
  <h1>Your Article Title</h1>
  <p>Your content here...</p>
</article>

When working with typography, consider these key principles: maintain consistent spacing between elements, use appropriate line heights for readability (1.5-1.75 for body text), limit line length to 60-80 characters, and ensure sufficient contrast between text and background. The leading-* utilities control line height, while tracking-* utilities adjust letter spacing.

Font families in Tailwind are organized into three main categories: sans-serif, serif, and monospace. Use font-sans for modern, clean interfaces,font-serif for traditional, elegant content, and font-mono for code snippets and technical content. You can customize these font stacks in your Tailwind configuration to match your brand's typography.

Responsive typography is crucial for modern web design. Use Tailwind's responsive prefixes like sm:, md:, and lg: to adjust font sizes at different breakpoints. For example, text-2xl md:text-4xl lg:text-5xlcreates a heading that scales appropriately from mobile to desktop, ensuring readability across all devices.

Quick Reference Guide

Font Size Utilities

  • text-xs - 12px (0.75rem)
  • text-sm - 14px (0.875rem)
  • text-base - 16px (1rem)
  • text-lg - 18px (1.125rem)
  • text-xl/2xl/3xl... - Larger sizes

Line Height

  • leading-tight - 1.25
  • leading-normal - 1.5
  • leading-relaxed - 1.625
  • leading-loose - 2

Common Type Scales

  • Minor Third - 1.200 (subtle)
  • Major Third - 1.250 (balanced)
  • Perfect Fourth - 1.333 (strong)
  • Golden Ratio - 1.618 (dramatic)

Pro Tips

  • Use prose plugin for article content
  • Limit line length to 60-80 characters
  • Increase line height for body text
  • Use responsive font sizes for mobile