How to style markdown with Tailwind CSS

Tailwind CSS comes with “an opinionated set of base styles” called Preflight. A helpful CSS reset built on top of modern-normalize.

Margins, headings, lists, and many others get stripped from their defaults. Thus, achieving cross-browser consistency a…


This content originally appeared on DEV Community and was authored by Oz Ertas

Tailwind CSS comes with "an opinionated set of base styles" called Preflight. A helpful CSS reset built on top of modern-normalize.

Margins, headings, lists, and many others get stripped from their defaults. Thus, achieving cross-browser consistency and an easier adaptation of your design system.

It all sounds helpful, until you need those defaults to style a markdown post.

In comes @tailwindcss/typography, a plugin with sensible typographic styles. It adds a set of prose classes to style content blocks like the one you are reading.

You can install it via npm or yarn:

# Using npm
npm install @tailwindcss/typography

# Using Yarn
yarn add @tailwindcss/typography

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

// tailwind.config.js
module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require('@tailwindcss/typography'),
    // ...
  ],
}

Finally, you can use the prose class to apply the markdown styling:

<article class="prose lg:prose-xl">
  <h1>Welcome to Mars!</h1>
  <p>
    Although life on Mars is perfect in every single way, you might have some questions.
  </p>
  <p>
    Of course there’s air! Just don’t breathe it. And, with the crazy gravity situation, everyone can dunk!
  </p>
  <!-- ... -->
</article>

More information about the prose class and its modifiers can be found at the repository.


This content originally appeared on DEV Community and was authored by Oz Ertas


Print Share Comment Cite Upload Translate Updates
APA

Oz Ertas | Sciencx (2021-11-16T22:51:58+00:00) How to style markdown with Tailwind CSS. Retrieved from https://www.scien.cx/2021/11/16/how-to-style-markdown-with-tailwind-css/

MLA
" » How to style markdown with Tailwind CSS." Oz Ertas | Sciencx - Tuesday November 16, 2021, https://www.scien.cx/2021/11/16/how-to-style-markdown-with-tailwind-css/
HARVARD
Oz Ertas | Sciencx Tuesday November 16, 2021 » How to style markdown with Tailwind CSS., viewed ,<https://www.scien.cx/2021/11/16/how-to-style-markdown-with-tailwind-css/>
VANCOUVER
Oz Ertas | Sciencx - » How to style markdown with Tailwind CSS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/16/how-to-style-markdown-with-tailwind-css/
CHICAGO
" » How to style markdown with Tailwind CSS." Oz Ertas | Sciencx - Accessed . https://www.scien.cx/2021/11/16/how-to-style-markdown-with-tailwind-css/
IEEE
" » How to style markdown with Tailwind CSS." Oz Ertas | Sciencx [Online]. Available: https://www.scien.cx/2021/11/16/how-to-style-markdown-with-tailwind-css/. [Accessed: ]
rf:citation
» How to style markdown with Tailwind CSS | Oz Ertas | Sciencx | https://www.scien.cx/2021/11/16/how-to-style-markdown-with-tailwind-css/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.