Adding Base Styles
Base (or global) styles are the styles at the beginning of a stylesheet that set useful defaults for basic HTML elements like tags, headings, etc. or apply opinionated resets like the popular box-sizing reset.
Tailwind includes a useful set of base styles out of the box that we call , which is really just normalize.css plus a thin layer of additional more opinionated styles.
Preflight is a great starting point for most projects, but if you’d ever like to add your own additional base styles, here are some recommendations for doing it idiomatically.
If you just want to apply some global styling to the html
or body
elements, consider just adding existing classes to those elements in your HTML instead of writing new CSS:
By using the directive, Tailwind will automatically move those styles to the same place as @tailwind base
to avoid unintended specificity issues.
Using the @layer
directive will also instruct Tailwind to consider those styles for purging when purging the layer. Read our documentation for more details.
It’s a good idea to use @apply or to define these styles to avoid introducing new magic values or accidentally deviating from your design system.
You can use the same approach to add your @font-face
rules for any custom fonts you are using:
Any styles you added using will automatically be included in your @tailwind base
styles.
When to use a plugin
In general, it’s simpler to add base styles to your project in CSS than it is to write a plugin.
You should prefer a plugin if:
- You want to re-use your base styles across multiple projects in your company and prefer sharing JS dependencies instead of CSS dependencies.