Preflight

An opinionated set of base styles for Tailwind projects.

Overview

Built on top of modern-normalize, Preflight is a set of base styles for Tailwind projects that are designed to smooth over cross-browser inconsistencies and make it easier for you to work within the constraints of your design system.

Tailwind automatically injects these styles when you include @tailwind base in your CSS:

  1. @tailwind base; /* Preflight will be injected here */
  2. @tailwind components;
  3. @tailwind utilities;

While most of the styles in Preflight are meant to go unnoticed — they simply make things behave more like you’d expect them to — some are more opinionated and can be surprising when you first encounter them.

For a complete reference of all the styles applied by Preflight, see the stylesheet.


Default margins are removed

Preflight removes all of the default margins from elements like headings, blockquotes, paragraphs, etc.

  1. blockquote,
  2. dl,
  3. dd,
  4. h1,
  5. h2,
  6. h3,
  7. h4,
  8. h5,
  9. h6,
  10. hr,
  11. figure,
  12. p,
  13. pre {
  14. margin: 0;
  15. }

This makes it harder to accidentally rely on margin values applied by the user-agent stylesheet that are not part of your spacing scale.


Headings are unstyled

All heading elements are completely unstyled by default, and have the same font-size and font-weight as normal text.

  1. h1,
  2. h2,
  3. h3,
  4. h4,
  5. h5,
  6. h6 {
  7. font-size: inherit;
  8. font-weight: inherit;
  9. }

The reason for this is two-fold:

  • It helps you avoid accidentally deviating from your type scale. By default, the browsers assigns sizes to headings that don’t exist in Tailwind’s default type scale, and aren’t guaranteed to exist in your own type scale.
  • In UI development, headings should often be visually de-emphasized. Making headings unstyled by default means any styling you apply to headings happens consciously and deliberately.

You can always add default header styles to your project by adding your own base styles.

If you’d like to selectively introduce sensible default heading styles into article-style parts of a page, we recommend the @tailwindcss/typography plugin.


Lists are unstyled

Ordered and unordered lists are unstyled by default, with no bullets/numbers and no margin or padding.

  1. ol,
  2. ul {
  3. list-style: none;
  4. margin: 0;
  5. padding: 0;
  6. }

If you’d like to style a list, you can do so using the list-style-type and list-style-position utilities:

  1. <ul class="list-disc list-inside">
  2. <li>One</li>
  3. <li>Two</li>
  4. <li>Three</li>
  5. </ul>

You can always add default list styles to your project by adding your own base styles.

If you’d like to selectively introduce default list styles into article-style parts of a page, we recommend the @tailwindcss/typography plugin.

Accessibility considerations

Unstyled lists are not announced as lists by VoiceOver. If your content is truly a list but you would like to keep it unstyled, add a “list” role to the element:

  1. <ul role="list">
  2. <li>One</li>
  3. <li>Two</li>
  4. <li>Three</li>
  5. </ul>

Images are block-level

Images and other replaced elements (like svg, video, canvas, and others) are display: block by default.

  1. img,
  2. svg,
  3. video,
  4. canvas,
  5. audio,
  6. iframe,
  7. embed,
  8. object {
  9. display: block;
  10. vertical-align: middle;
  11. }

This helps to avoid unexpected alignment issues that you often run into using the browser default of display: inline.

If you ever need to make one of these elements inline instead of block, simply use the inline utility:

  1. <img class="inline" src="..." alt="...">

Border styles are reset globally

In order to make it easy to add a border by simply adding the border class, Tailwind overrides the default border styles for all elements with the following rules:

  1. *,
  2. ::before,
  3. ::after {
  4. border-width: 0;
  5. border-style: solid;
  6. border-color: theme('borderColor.default', currentColor);
  7. }

Since the border class only sets the border-width property, this reset ensures that adding that class always adds a solid 1px border using your configured default border color.

This can cause some unexpected results when integrating certain third-party libraries, like Google maps for example.

When you run into situations like this, you can work around them by overriding the Preflight styles with your own custom CSS:

  1. .google-map * {
  2. border-style: none;
  3. }

Buttons have a default outline

To ensure that we provide accessible styles out of the box, we made sure that buttons have a default outline. You can of course override this by applying focus:ring or similar utilities to your buttons.

  1. button:focus {
  2. outline: 1px dotted;
  3. outline: 5px auto -webkit-focus-ring-color;
  4. }

Extending Preflight

If you’d like to add your own base styles on top of Preflight, simply add them to your CSS within a @layer base directive:

  1. @tailwind base;
  2. @layer base {
  3. h1 {
  4. @apply text-2xl;
  5. }
  6. h2 {
  7. @apply text-xl;
  8. }
  9. h3 {
  10. @apply text-lg;
  11. }
  12. a {
  13. @apply text-blue-600 underline;
  14. }
  15. }
  16. @tailwind components;
  17. @tailwind utilities;

Learn more in the adding base styles documentation.


Disabling Preflight

If you’d like to completely disable Preflight — perhaps because you’re integrating Tailwind into an existing project or because you’d like to provide your own base styles — all you need to do is set preflight to false in the corePlugins section of your tailwind.config.js file:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. + preflight: false,
  5. }
  6. }

←Presets   Container→