Gathering detailed insights and metrics for @tailwindcss/typography
Gathering detailed insights and metrics for @tailwindcss/typography
Gathering detailed insights and metrics for @tailwindcss/typography
Gathering detailed insights and metrics for @tailwindcss/typography
Beautiful typographic defaults for HTML you don't control.
npm install @tailwindcss/typography
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
4,734 Stars
249 Commits
270 Forks
20 Watching
8 Branches
31 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-6.3%
309,954
Compared to previous day
Last week
3.3%
1,806,080
Compared to previous week
Last month
10.5%
7,349,366
Compared to previous month
Last year
79.3%
65,149,536
Compared to previous year
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.
1<article class="prose lg:prose-xl">{{ markdown }}</article>
To see what it looks like in action, check out our live demo on Tailwind Play.
Install the plugin from npm:
1npm install -D @tailwindcss/typography
Then add the plugin to your tailwind.config.js
file:
1/** @type {import('tailwindcss').Config} */ 2module.exports = { 3 theme: { 4 // ... 5 }, 6 plugins: [ 7 require('@tailwindcss/typography'), 8 // ... 9 ], 10}
Now you can use the prose
classes to add sensible typography styles to any vanilla HTML:
1<article class="prose lg:prose-xl"> 2 <h1>Garlic bread with cheese: What the science tells us</h1> 3 <p> 4 For years parents have espoused the health benefits of eating garlic bread with cheese to their 5 children, with the food earning such an iconic status in our culture that kids will often dress 6 up as warm, cheesy loaf for Halloween. 7 </p> 8 <p> 9 But a recent study shows that the celebrated appetizer may be linked to a series of rabies cases 10 springing up around the country. 11 </p> 12 <!-- ... --> 13</article>
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.
1<article class="prose prose-slate">{{ markdown }}</article>
Here are the classes that are generated using a totally default Tailwind CSS v2.0 build:
Class | Gray scale |
---|---|
prose-gray (default) | Gray |
prose-slate | Slate |
prose-zinc | Zinc |
prose-neutral | Neutral |
prose-stone | Stone |
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
1<article class="prose prose-stone">{{ markdown }}</article>
To learn about creating your own color themes, read the adding custom color themes documentation.
Size modifiers allow you to adjust the overall size of your typography for different contexts.
1<article class="prose prose-xl">{{ markdown }}</article>
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:
1<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
1<article class="prose prose-lg">{{ markdown }}</article>
To learn about customizing the included type scales, read the documentation on customizing the CSS.
Each default color theme includes a hand-designed dark mode version that you can trigger by adding the prose-invert
class:
1<article class="prose dark:prose-invert">{{ markdown }}</article>
To learn about creating your own color themes, read the adding custom color themes documentation.
Use element modifiers to customize the style of individual elements in your content directly in your HTML:
1<article class="prose prose-img:rounded-xl prose-headings:underline prose-a:text-blue-600"> 2 {{ markdown }} 3</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:
Modifier | Target |
---|---|
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:
1<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.
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:
1<div class="grid grid-cols-4"> 2 <div class="col-span-1"> 3 <!-- ... --> 4 </div> 5 <div class="col-span-3"> 6 <article class="prose max-w-none">{{ markdown }}</article> 7 </div> 8</div>
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:
1<article class="prose"> 2 <h1>My Heading</h1> 3 <p>...</p> 4 5 <div class="not-prose"> 6 <!-- Some example or demo that needs to be prose-free --> 7 </div> 8 9 <p>...</p> 10 <!-- ... --> 11</article>
Note that you can't nest new prose
instances within a not-prose
block at this time.
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:
1/** @type {import('tailwindcss').Config} */ 2module.exports = { 3 theme: { 4 extend: { 5 typography: ({ theme }) => ({ 6 pink: { 7 css: { 8 '--tw-prose-body': theme('colors.pink[800]'), 9 '--tw-prose-headings': theme('colors.pink[900]'), 10 '--tw-prose-lead': theme('colors.pink[700]'), 11 '--tw-prose-links': theme('colors.pink[900]'), 12 '--tw-prose-bold': theme('colors.pink[900]'), 13 '--tw-prose-counters': theme('colors.pink[600]'), 14 '--tw-prose-bullets': theme('colors.pink[400]'), 15 '--tw-prose-hr': theme('colors.pink[300]'), 16 '--tw-prose-quotes': theme('colors.pink[900]'), 17 '--tw-prose-quote-borders': theme('colors.pink[300]'), 18 '--tw-prose-captions': theme('colors.pink[700]'), 19 '--tw-prose-code': theme('colors.pink[900]'), 20 '--tw-prose-pre-code': theme('colors.pink[100]'), 21 '--tw-prose-pre-bg': theme('colors.pink[900]'), 22 '--tw-prose-th-borders': theme('colors.pink[300]'), 23 '--tw-prose-td-borders': theme('colors.pink[200]'), 24 '--tw-prose-invert-body': theme('colors.pink[200]'), 25 '--tw-prose-invert-headings': theme('colors.white'), 26 '--tw-prose-invert-lead': theme('colors.pink[300]'), 27 '--tw-prose-invert-links': theme('colors.white'), 28 '--tw-prose-invert-bold': theme('colors.white'), 29 '--tw-prose-invert-counters': theme('colors.pink[400]'), 30 '--tw-prose-invert-bullets': theme('colors.pink[600]'), 31 '--tw-prose-invert-hr': theme('colors.pink[700]'), 32 '--tw-prose-invert-quotes': theme('colors.pink[100]'), 33 '--tw-prose-invert-quote-borders': theme('colors.pink[700]'), 34 '--tw-prose-invert-captions': theme('colors.pink[400]'), 35 '--tw-prose-invert-code': theme('colors.white'), 36 '--tw-prose-invert-pre-code': theme('colors.pink[300]'), 37 '--tw-prose-invert-pre-bg': 'rgb(0 0 0 / 50%)', 38 '--tw-prose-invert-th-borders': theme('colors.pink[600]'), 39 '--tw-prose-invert-td-borders': theme('colors.pink[700]'), 40 }, 41 }, 42 }), 43 }, 44 }, 45 plugins: [ 46 require('@tailwindcss/typography'), 47 // ... 48 ], 49}
See our internal style definitions for some more examples.
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:
1/** @type {import('tailwindcss').Config} */ 2module.exports = { 3 theme: { 4 // ... 5 }, 6 plugins: [ 7 require('@tailwindcss/typography')({ 8 className: 'wysiwyg', 9 }), 10 ] 11 ... 12}
Now every instance of prose
in the default class names will be replaced by your custom class name:
1<article class="wysiwyg wysiwyg-slate lg:wysiwyg-xl"> 2 <h1>My Heading</h1> 3 <p>...</p> 4 5 <div class="not-wysiwyg"> 6 <!-- Some example or demo that needs to be prose-free --> 7 </div> 8 9 <p>...</p> 10 <!-- ... --> 11</article>
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:
1/** @type {import('tailwindcss').Config} */ 2module.exports = { 3 theme: { 4 extend: { 5 typography: { 6 DEFAULT: { 7 css: { 8 color: '#333', 9 a: { 10 color: '#3182ce', 11 '&:hover': { 12 color: '#2c5282', 13 }, 14 }, 15 }, 16 }, 17 }, 18 }, 19 }, 20 plugins: [ 21 require('@tailwindcss/typography'), 22 // ... 23 ], 24}
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:
1/** @type {import('tailwindcss').Config} */ 2module.exports = { 3 theme: { 4 extend: { 5 typography: (theme) => ({ 6 DEFAULT: { 7 css: { 8 color: theme('colors.gray.800'), 9 10 // ... 11 }, 12 }, 13 }), 14 }, 15 }, 16 plugins: [ 17 require('@tailwindcss/typography'), 18 // ... 19 ], 20}
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.
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:
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
4 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 4
Reason
Found 10/27 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
10 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More