The @tailwindcss/typography plugin provides a set of prose classes that 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. It's designed to make the text in your applications look good out of the box.
What are @tailwindcss/typography's main functionalities?
Prose styling
Automatically styles the text within the <article> tag according to the Tailwind Typography defaults. The 'prose' class applies base styles, and 'lg:prose-xl' applies larger styles at the 'lg' breakpoint and above.
<article class='prose lg:prose-xl'>...</article>
Customizing Typography
Allows customization of the default typography styles. In this example, the base text color is set to '#333', and anchor (<a>) tags are styled with a default color of '#3178c6', which changes to '#0550ae' on hover.
Enables dark mode styles within the <article> tag when the parent or root element has the 'dark' class. The 'prose-dark' class applies dark mode styles to the text.
A powerful toolkit for building websites with beautiful design. Typography.js provides a set of themes and plugins to manage typography in CSS-in-JS applications. It differs from @tailwindcss/typography by offering a more JavaScript-centric approach, allowing for dynamic theme adjustments and integration with React components.
A tool for creating presentation decks using MDX (Markdown + JSX), which allows for the use of JSX components within markdown. While not a direct competitor to @tailwindcss/typography, mdx-deck can be used to style markdown content for presentations and includes its own set of themes and layouts for typography. It's more specialized for presentation purposes compared to the broad HTML content styling offered by @tailwindcss/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.
Now you can use the prose classes to add sensible typography styles to any vanilla HTML:
<articleclass="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.
Five different typography sizes are included out of the box:
Class
Body font size
prose-sm
0.875rem (14px)
prose-base(default)
1rem (16px)
prose-lg
1.125rem (18px)
prose-xl
1.25rem (20px)
prose-2xl
1.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:
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
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:
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:
<articleclass="prose"><h1>My Heading</h1><p>...</p><divclass="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:
Now every instance of prose in the default class names will be replaced by your custom class name:
<articleclass="wysiwyg wysiwyg-slate lg:wysiwyg-xl"><h1>My Heading</h1><p>...</p><divclass="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:
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:
Support installing with alpha versions of Tailwind CSS v4 (#358)
FAQs
A Tailwind CSS plugin for automatically styling plain HTML content with beautiful typographic defaults.
The npm package @tailwindcss/typography receives a total of 1,330,530 weekly downloads. As such, @tailwindcss/typography popularity was classified as popular.
We found that @tailwindcss/typography demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 4 open source maintainers collaborating on the project.
Package last updated on 28 Aug 2024
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Socket researchers found a malicious Maven package impersonating the legitimate ‘XZ for Java’ library, introducing a backdoor for remote code execution.
Node.js v22.12.0 (LTS) debuts with require(esm) enabled by default, alongside security milestones and automated workflows for faster, more stable releases.