Convert Figma logo to code with AI

tailwindlabs logotailwindcss-typography

Beautiful typographic defaults for HTML you don't control.

4,362
263
4,362
9

Top Related Projects

16,276

The instant on-demand atomic CSS engine.

37,442

⚡️ Simple, Modular & Accessible UI Components for your React Applications

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅

17,396

👩‍🎤 CSS-in-JS library designed for high performance style composition

Zero-runtime Stylesheets-in-TypeScript

Quick Overview

Tailwind CSS Typography is a plugin for Tailwind CSS that provides a set of ready-to-use typography styles. It aims to make it easy to create beautiful, readable content within your Tailwind CSS projects by offering sensible defaults for common typographic elements.

Pros

  • Quickly adds well-designed typography styles to Tailwind projects
  • Customizable to match your design preferences
  • Responsive out of the box
  • Integrates seamlessly with existing Tailwind CSS workflows

Cons

  • May require additional configuration for complex typography needs
  • Can increase bundle size if not used carefully
  • Limited control over individual elements compared to custom CSS
  • Learning curve for developers new to Tailwind CSS ecosystem

Code Examples

  1. Basic usage in HTML:
<article class="prose">
  <h1>Garlic bread with cheese: What the science tells us</h1>
  <p>
    For years parents have espoused the health benefits of eating garlic bread with cheese to their
    children, with the food earning such an iconic status in our culture that kids will often dress
    up as warm, cheesy loaf for Halloween.
  </p>
</article>
  1. Customizing typography colors:
// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      typography: (theme) => ({
        DEFAULT: {
          css: {
            color: theme('colors.gray.800'),
            a: {
              color: theme('colors.blue.600'),
              '&:hover': {
                color: theme('colors.blue.800'),
              },
            },
          },
        },
      }),
    },
  },
  plugins: [require('@tailwindcss/typography')],
}
  1. Applying different sizes:
<article class="prose prose-sm">
  <!-- Small size typography -->
</article>

<article class="prose prose-xl">
  <!-- Extra large size typography -->
</article>

Getting Started

  1. Install the plugin:

    npm install -D @tailwindcss/typography
    
  2. Add the plugin to your tailwind.config.js file:

    module.exports = {
      theme: {
        // ...
      },
      plugins: [
        require('@tailwindcss/typography'),
        // ...
      ],
    }
    
  3. Use the prose class in your HTML:

    <article class="prose">
      <!-- Your content here -->
    </article>
    

Competitor Comparisons

16,276

The instant on-demand atomic CSS engine.

Pros of UnoCSS

  • Faster build times and smaller bundle sizes due to its on-demand atomic CSS engine
  • More flexible and customizable with its preset system and custom rules
  • Supports multiple CSS-in-JS solutions and frameworks out of the box

Cons of UnoCSS

  • Less established community and ecosystem compared to Tailwind CSS
  • Steeper learning curve for developers familiar with traditional CSS frameworks
  • May require more configuration for complex projects

Code Comparison

UnoCSS:

.text-red-500 {
  color: rgb(239 68 68);
}

Tailwind CSS Typography:

.prose {
  color: #374151;
  max-width: 65ch;
}

UnoCSS focuses on atomic utility classes, while Tailwind CSS Typography provides pre-designed components for typography. UnoCSS offers more granular control over individual styles, whereas Tailwind CSS Typography provides a cohesive set of styles for text content.

Both projects aim to simplify CSS development, but UnoCSS takes a more flexible and customizable approach, while Tailwind CSS Typography offers a more opinionated and ready-to-use solution for typography-specific styling.

37,442

⚡️ Simple, Modular & Accessible UI Components for your React Applications

Pros of Chakra UI

  • Comprehensive component library with pre-built, accessible UI components
  • Flexible theming system allowing easy customization
  • Built-in support for responsive design and dark mode

Cons of Chakra UI

  • Steeper learning curve due to its extensive API and features
  • Larger bundle size compared to Tailwind Typography
  • May require more setup and configuration

Code Comparison

Chakra UI:

import { Box, Text } from "@chakra-ui/react"

<Box maxWidth="prose" mx="auto">
  <Text fontSize="xl" fontWeight="bold">
    Styled content using Chakra UI
  </Text>
</Box>

Tailwind Typography:

<article class="prose lg:prose-xl mx-auto">
  <h1>Styled content using Tailwind Typography</h1>
</article>

Chakra UI offers a more component-based approach with pre-built UI elements, while Tailwind Typography provides utility classes for styling typography within existing HTML structures. Chakra UI requires importing specific components, whereas Tailwind Typography applies styles through CSS classes. Chakra UI offers more granular control over individual elements, while Tailwind Typography provides a cohesive set of typography styles with less configuration.

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅

Pros of styled-components

  • Component-level styling with CSS-in-JS approach
  • Dynamic styling based on props
  • Automatic critical CSS injection

Cons of styled-components

  • Steeper learning curve for developers new to CSS-in-JS
  • Potential performance overhead for large applications
  • Less suitable for projects requiring a utility-first approach

Code Comparison

styled-components:

const Button = styled.button`
  background-color: ${props => props.primary ? 'blue' : 'white'};
  color: ${props => props.primary ? 'white' : 'blue'};
  padding: 10px 20px;
  border: 2px solid blue;
`;

Tailwind CSS Typography:

<button class="bg-blue-500 text-white px-4 py-2 border-2 border-blue-500">
  Click me
</button>

styled-components offers more flexibility in creating dynamic styles based on props, while Tailwind CSS Typography provides a utility-first approach with pre-defined classes. The choice between the two depends on project requirements, team preferences, and scalability needs. styled-components is better suited for component-based architectures with complex, dynamic styling, while Tailwind CSS Typography excels in rapid prototyping and maintaining consistent design systems across large projects.

17,396

👩‍🎤 CSS-in-JS library designed for high performance style composition

Pros of emotion

  • More flexible and powerful, allowing for dynamic styling based on props and state
  • Better integration with JavaScript, enabling the use of variables and functions in styles
  • Supports server-side rendering out of the box

Cons of emotion

  • Steeper learning curve, especially for developers new to CSS-in-JS
  • Potentially larger bundle size due to runtime style injection
  • Less opinionated, which may lead to inconsistent styling across a project

Code Comparison

emotion:

import { css } from '@emotion/react'

const style = css`
  color: hotpink;
  font-size: 24px;
`

const SomeComponent = () => <div css={style}>Some text</div>

tailwindcss-typography:

<article class="prose lg:prose-xl">
  <h1>Garlic bread with cheese: What the science tells us</h1>
  <p>For years parents have espoused the health benefits of eating garlic bread with cheese to their children...</p>
</article>

While emotion offers more programmatic control over styles, tailwindcss-typography provides a set of pre-defined classes for common typographic elements, making it easier to achieve consistent typography across a project with less custom CSS.

Zero-runtime Stylesheets-in-TypeScript

Pros of vanilla-extract

  • Type-safe CSS-in-JS with zero runtime, offering better performance
  • Seamless integration with modern JavaScript ecosystems and build tools
  • Allows for dynamic theming and design token management

Cons of vanilla-extract

  • Steeper learning curve for developers used to traditional CSS
  • Requires additional build step and tooling setup
  • Less suitable for quick prototyping or small projects

Code Comparison

vanilla-extract:

import { style } from '@vanilla-extract/css';

export const heading = style({
  fontSize: '24px',
  fontWeight: 'bold',
  color: 'navy'
});

Tailwind CSS Typography:

<h1 class="prose-2xl font-bold text-navy">
  Heading
</h1>

Summary

vanilla-extract offers a more programmatic approach to styling with type safety and zero runtime overhead, making it suitable for large-scale applications. Tailwind CSS Typography, on the other hand, provides a utility-first approach that's easier to pick up and ideal for rapid development. The choice between the two depends on project requirements, team expertise, and development workflow preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Tailwind CSS Typography

The official Tailwind CSS Typography plugin provides a set of prose classes you can use to add beautiful typographic defaults to any vanilla HTML you don’t control, like HTML rendered from Markdown, or pulled from a CMS.

<article class="prose lg:prose-xl">{{ markdown }}</article>

To see what it looks like in action, check out our live demo on Tailwind Play.


Installation

Install the plugin from npm:

npm install -D @tailwindcss/typography

Then add the plugin to your tailwind.config.js file:

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require('@tailwindcss/typography'),
    // ...
  ],
}

Basic usage

Now you can use the prose classes to add sensible typography styles to any vanilla HTML:

<article class="prose lg:prose-xl">
  <h1>Garlic bread with cheese: What the science tells us</h1>
  <p>
    For years parents have espoused the health benefits of eating garlic bread with cheese to their
    children, with the food earning such an iconic status in our culture that kids will often dress
    up as warm, cheesy loaf for Halloween.
  </p>
  <p>
    But a recent study shows that the celebrated appetizer may be linked to a series of rabies cases
    springing up around the country.
  </p>
  <!-- ... -->
</article>

Choosing a gray scale

This plugin includes a modifier class for each of the five gray scales Tailwind includes by default so you can easily style your content to match the grays you're using in your project.

<article class="prose prose-slate">{{ markdown }}</article>

Here are the classes that are generated using a totally default Tailwind CSS v2.0 build:

ClassGray scale
prose-gray (default)Gray
prose-slateSlate
prose-zincZinc
prose-neutralNeutral
prose-stoneStone

Modifier classes are designed to be used with the multi-class modifier pattern and must be used in conjunction with the base prose class.

[!NOTE] Always include the prose class when adding a gray scale modifier

<article class="prose prose-stone">{{ markdown }}</article>

To learn about creating your own color themes, read the adding custom color themes documentation.

Applying a type scale

Size modifiers allow you to adjust the overall size of your typography for different contexts.

<article class="prose prose-xl">{{ markdown }}</article>

Five different typography sizes are included out of the box:

ClassBody font size
prose-sm0.875rem (14px)
prose-base (default)1rem (16px)
prose-lg1.125rem (18px)
prose-xl1.25rem (20px)
prose-2xl1.5rem (24px)

These can be used in combination with Tailwind's breakpoint modifiers to change the overall font size of a piece of content at different viewport sizes:

<article class="prose md:prose-lg lg:prose-xl">{{ markdown }}</article>

Everything about the provided size modifiers has been hand-tuned by professional designers to look as beautiful as possible, including the relationships between font sizes, heading spacing, code block padding, and more.

Size modifiers are designed to be used with the multi-class modifier pattern and must be used in conjunction with the base prose class.

[!NOTE] Always include the prose class when adding a size modifier

<article class="prose prose-lg">{{ markdown }}</article>

To learn about customizing the included type scales, read the documentation on customizing the CSS.

Adapting to dark mode

Each default color theme includes a hand-designed dark mode version that you can trigger by adding the prose-invert class:

<article class="prose dark:prose-invert">{{ markdown }}</article>

To learn about creating your own color themes, read the adding custom color themes documentation.

Element modifiers

Use element modifiers to customize the style of individual elements in your content directly in your HTML:

<article class="prose prose-img:rounded-xl prose-headings:underline prose-a:text-blue-600">
  {{ markdown }}
</article>

This makes it easy to do things like style links to match your brand, add a border radius to images, and tons more.

Here's a complete list of available element modifiers:

ModifierTarget
prose-headings:{utility}h1, h2, h3, h4, th
prose-lead:{utility}[class~="lead"]
prose-h1:{utility}h1
prose-h2:{utility}h2
prose-h3:{utility}h3
prose-h4:{utility}h4
prose-p:{utility}p
prose-a:{utility}a
prose-blockquote:{utility}blockquote
prose-figure:{utility}figure
prose-figcaption:{utility}figcaption
prose-strong:{utility}strong
prose-em:{utility}em
prose-kbd:{utility}kbd
prose-code:{utility}code
prose-pre:{utility}pre
prose-ol:{utility}ol
prose-ul:{utility}ul
prose-li:{utility}li
prose-table:{utility}table
prose-thead:{utility}thead
prose-tr:{utility}tr
prose-th:{utility}th
prose-td:{utility}td
prose-img:{utility}img
prose-video:{utility}video
prose-hr:{utility}hr

When stacking these modifiers with other modifiers like hover, you most likely want the other modifier to come first:

<article class="prose prose-a:text-blue-600 hover:prose-a:text-blue-500">{{ markdown }}</article>

Read the Tailwind CSS documentation on ordering stacked modifiers to learn more.

Overriding max-width

Each size modifier comes with a baked in max-width designed to keep the content as readable as possible. This isn't always what you want though, and sometimes you'll want the content to just fill the width of its container.

In those cases, all you need to do is add max-w-none to your content to override the embedded max-width:

<div class="grid grid-cols-4">
  <div class="col-span-1">
    <!-- ... -->
  </div>
  <div class="col-span-3">
    <article class="prose max-w-none">{{ markdown }}</article>
  </div>
</div>

Advanced topics

Undoing typography styles

If you have a block of markup embedded in some content that shouldn't inherit the prose styles, use the not-prose class to sandbox it:

<article class="prose">
  <h1>My Heading</h1>
  <p>...</p>

  <div class="not-prose">
    <!-- Some example or demo that needs to be prose-free -->
  </div>

  <p>...</p>
  <!-- ... -->
</article>

Note that you can't nest new prose instances within a not-prose block at this time.

Adding custom color themes

You can create your own color theme by adding a new key in the typography section of your tailwind.config.js file and providing your colors under the css key:

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    extend: {
      typography: ({ theme }) => ({
        pink: {
          css: {
            '--tw-prose-body': theme('colors.pink[800]'),
            '--tw-prose-headings': theme('colors.pink[900]'),
            '--tw-prose-lead': theme('colors.pink[700]'),
            '--tw-prose-links': theme('colors.pink[900]'),
            '--tw-prose-bold': theme('colors.pink[900]'),
            '--tw-prose-counters': theme('colors.pink[600]'),
            '--tw-prose-bullets': theme('colors.pink[400]'),
            '--tw-prose-hr': theme('colors.pink[300]'),
            '--tw-prose-quotes': theme('colors.pink[900]'),
            '--tw-prose-quote-borders': theme('colors.pink[300]'),
            '--tw-prose-captions': theme('colors.pink[700]'),
            '--tw-prose-code': theme('colors.pink[900]'),
            '--tw-prose-pre-code': theme('colors.pink[100]'),
            '--tw-prose-pre-bg': theme('colors.pink[900]'),
            '--tw-prose-th-borders': theme('colors.pink[300]'),
            '--tw-prose-td-borders': theme('colors.pink[200]'),
            '--tw-prose-invert-body': theme('colors.pink[200]'),
            '--tw-prose-invert-headings': theme('colors.white'),
            '--tw-prose-invert-lead': theme('colors.pink[300]'),
            '--tw-prose-invert-links': theme('colors.white'),
            '--tw-prose-invert-bold': theme('colors.white'),
            '--tw-prose-invert-counters': theme('colors.pink[400]'),
            '--tw-prose-invert-bullets': theme('colors.pink[600]'),
            '--tw-prose-invert-hr': theme('colors.pink[700]'),
            '--tw-prose-invert-quotes': theme('colors.pink[100]'),
            '--tw-prose-invert-quote-borders': theme('colors.pink[700]'),
            '--tw-prose-invert-captions': theme('colors.pink[400]'),
            '--tw-prose-invert-code': theme('colors.white'),
            '--tw-prose-invert-pre-code': theme('colors.pink[300]'),
            '--tw-prose-invert-pre-bg': 'rgb(0 0 0 / 50%)',
            '--tw-prose-invert-th-borders': theme('colors.pink[600]'),
            '--tw-prose-invert-td-borders': theme('colors.pink[700]'),
          },
        },
      }),
    },
  },
  plugins: [
    require('@tailwindcss/typography'),
    // ...
  ],
}

See our internal style definitions for some more examples.

Changing the default class name

If you need to use a class name other than prose for any reason, you can do so using the className option when registering the plugin:

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require('@tailwindcss/typography')({
      className: 'wysiwyg',
    }),
  ]
  ...
}

Now every instance of prose in the default class names will be replaced by your custom class name:

<article class="wysiwyg wysiwyg-slate lg:wysiwyg-xl">
  <h1>My Heading</h1>
  <p>...</p>

  <div class="not-wysiwyg">
    <!-- Some example or demo that needs to be prose-free -->
  </div>

  <p>...</p>
  <!-- ... -->
</article>

Customizing the CSS

If you want to customize the raw CSS generated by this plugin, add your overrides under the typography key in the theme section of your tailwind.config.js file:

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    extend: {
      typography: {
        DEFAULT: {
          css: {
            color: '#333',
            a: {
              color: '#3182ce',
              '&:hover': {
                color: '#2c5282',
              },
            },
          },
        },
      },
    },
  },
  plugins: [
    require('@tailwindcss/typography'),
    // ...
  ],
}

Like with all theme customizations in Tailwind, you can also define the typography key as a function if you need access to the theme helper:

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    extend: {
      typography: (theme) => ({
        DEFAULT: {
          css: {
            color: theme('colors.gray.800'),

            // ...
          },
        },
      }),
    },
  },
  plugins: [
    require('@tailwindcss/typography'),
    // ...
  ],
}

Customizations should be applied to a specific modifier like DEFAULT or xl, and must be added under the css property. Customizations are authored in the same CSS-in-JS syntax used to write Tailwind plugins.

See the default styles for this plugin for more in-depth examples of configuring each modifier.


Community

For help, discussion about best practices, or any other conversation that would benefit from being searchable:

Discuss the Tailwind CSS Typography plugin on GitHub

For casual chit-chat with others using the framework:

Join the Tailwind CSS Discord Server

NPM DownloadsLast 30 Days