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. To see what it looks like in action, check out our live demo on Tailwind Play. Installation Install the plugin from npm: Then add the plugin to your main style.css file: If you are still using…
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
Read the Tailwind CSS documentation on 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:
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.
Even when using a prefix for your utilities not-prose should not have a prefix.
Adding custom color themes
To customize the color theme beyond simple CSS overrides, add a @utility directive to your CSS file:
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, you can use the JavaScript based theme API. To do that, use the @config directive:
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 v3 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:
评论