Configuration

A guide to configuring and customizing your Tailwind installation.


Because Tailwind is a framework for building bespoke user interfaces, it has been designed from the ground up with customization in mind.

By default, Tailwind will look for an optional tailwind.config.js file at the root of your project where you can define any customizations.

  1. // Example `tailwind.config.js` file
  2. module.exports = {
  3. important: true,
  4. theme: {
  5. fontFamily: {
  6. display: ['Gilroy', 'sans-serif'],
  7. body: ['Graphik', 'sans-serif'],
  8. },
  9. extend: {
  10. colors: {
  11. cyan: '#9cdbff',
  12. },
  13. margin: {
  14. '96': '24rem',
  15. '128': '32rem',
  16. },
  17. }
  18. },
  19. variants: {
  20. opacity: ['responsive', 'hover']
  21. }
  22. }

Every section of the config file is optional, so you only have to specify what you’d like to change. Any missing sections will fall back to Tailwind’s default configuration.

Creating your configuration file

Generate a Tailwind config file for your project using the Tailwind CLI utility included when you install the tailwindcss npm package:

  1. npx tailwind init

This will create a minimal tailwind.config.js file at the root of your project:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {},
  4. variants: {},
  5. plugins: [],
  6. }

Using a different file name

To use a name other than tailwind.config.js, pass it as an argument on the command-line:

  1. npx tailwind init tailwindcss-config.js

If you use a custom file name, you will need to specify it when including Tailwind as a plugin in your PostCSS configuration as well:

  1. // postcss.config.js
  2. module.exports = {
  3. plugins: [
  4. require('tailwindcss')('./tailwindcss-config.js'),
  5. ],
  6. }

Scaffolding the entire default configuration

For most users we encourage you to keep your config file as minimal as possible, and only specify the things you want to customize.

If you’d rather scaffold a complete configuration file that includes all of Tailwind’s default configuration, use the —full option:

  1. npx tailwind init --full

You’ll get a file that matches the default configuration file Tailwind uses internally.

Theme

The theme section is where you define your color palette, font stacks, type scale, border sizes, breakpoints — anything related to the visual design of your site.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. screens: {
  5. sm: '640px',
  6. md: '768px',
  7. lg: '1024px',
  8. xl: '1280px',
  9. },
  10. fontFamily: {
  11. display: ['Gilroy', 'sans-serif'],
  12. body: ['Graphik', 'sans-serif'],
  13. },
  14. borderWidth: {
  15. default: '1px',
  16. '0': '0',
  17. '2': '2px',
  18. '4': '4px',
  19. },
  20. extend: {
  21. colors: {
  22. cyan: '#9cdbff',
  23. },
  24. spacing: {
  25. '96': '24rem',
  26. '128': '32rem',
  27. }
  28. }
  29. }
  30. }

Learn more about the default theme and how to customize it in the theme configuration guide.

Variants

The variants section lets you control which variants are generated for each core utility plugin.

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. appearance: ['responsive'],
  5. backgroundColors: ['responsive', 'hover', 'focus'],
  6. fill: [],
  7. },
  8. }

Learn more in the variants configuration guide.

Plugins

The plugins section allows you to register third-party plugins with Tailwind that can be used to generate extra utilities, components, base styles, or custom variants.

  1. // tailwind.config.js
  2. module.exports = {
  3. plugins: [
  4. require('tailwindcss-transforms'),
  5. require('tailwindcss-transitions'),
  6. require('tailwindcss-border-gradients'),
  7. ],
  8. }

Learn more about writing your own plugins in the plugin authoring guide.

Prefix

The prefix option allows you to add a custom prefix to all of Tailwind’s generated utility classes. This can be really useful when layering Tailwind on top of existing CSS where there might be naming conflicts.

For example, you could add a tw- prefix by setting the prefix option like so:

  1. // tailwind.config.js
  2. module.exports = {
  3. prefix: 'tw-',
  4. }

Now every utility will be generated with the configured prefix:

  1. .tw-text-left {
  2. text-align: left;
  3. }
  4. .tw-text-center {
  5. text-align: center;
  6. }
  7. .tw-text-right {
  8. text-align: right;
  9. }
  10. /* etc. */

It’s important to understand that this prefix is added to the beginning of each utility name, not to the entire class name.

That means that classes with responsive or state prefixes like sm: or hover: will still have the responsive or state prefix first, with your custom prefix appearing after the colon:

  1. <div class="tw-text-lg md:tw-text-xl tw-bg-red-500 hover:tw-bg-blue-500">
  2. <!-- -->
  3. </div>

Prefixes are only added to classes generated by Tailwind; no prefix will be added to your own custom classes.

That means if you add your own responsive utility like this:

  1. @responsive {
  2. .bg-brand-gradient { /* ... */ }
  3. }

…the generated responsive classes will not have your configured prefix:

  1. .bg-brand-gradient { /* ... */ }
  2. @media (min-width: 640px) {
  3. .sm\:bg-brand-gradient { /* ... */ }
  4. }
  5. @media (min-width: 768px) {
  6. .md\:bg-brand-gradient { /* ... */ }
  7. }
  8. @media (min-width: 992) {
  9. .lg\:bg-brand-gradient { /* ... */ }
  10. }
  11. @media (min-width: 1280px) {
  12. .xl\:bg-brand-gradient { /* ... */ }
  13. }

If you’d like to prefix your own utilities as well, just add the prefix to the class definition:

  1. @responsive {
  2. .tw-bg-brand-gradient { /* ... */ }
  3. }

Important

The important option lets you control whether or not Tailwind’s utilities should be marked with !important. This can be really useful when using Tailwind with existing CSS that has high specificity selectors.

To generate utilities as !important, set the important key in your configuration options to true:

  1. // tailwind.config.js
  2. module.exports = {
  3. important: true,
  4. }

Now all of Tailwind’s utility classes will be generated as !important:

  1. .leading-none {
  2. line-height: 1 !important;
  3. }
  4. .leading-tight {
  5. line-height: 1.25 !important;
  6. }
  7. .leading-snug {
  8. line-height: 1.375 !important;
  9. }
  10. /* etc. */

Note that any of your own custom utilities will not automatically be marked as !important by enabling this option.

If you’d like to make your own utilities !important, just add !important to the end of each declaration yourself:

  1. @responsive {
  2. .bg-brand-gradient {
  3. background-image: linear-gradient(#3490dc, #6574cd) !important;
  4. }
  5. }

Separator

The separator option lets you customize what character or string should be used to separate variant prefixes (screen sizes, hover, focus, etc.) from utility names (text-center, items-end, etc.).

We use a colon by default (:), but it can be useful to change this if you’re using a templating language like Pug that doesn’t support special characters in class names.

  1. // tailwind.config.js
  2. module.exports = {
  3. separator: '_',
  4. }

Core Plugins

The corePlugins section lets you completely disable classes that Tailwind would normally generate by default if you don’t need them for your project.

If you don’t provide any corePlugins configuration, all core plugins will be enabled by default:

  1. // tailwind.config.js
  2. module.exports = {}

If you’d like to disable specific core plugins, provide an object for corePlugins that sets those plugins to false:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. float: false,
  5. objectFit: false,
  6. objectPosition: false,
  7. }
  8. }

If you’d like to whitelist which core plugins should be enabled, provide an array that includes a list of the core plugins you’d like to use:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: [
  4. 'margin',
  5. 'padding',
  6. 'backgroundColor',
  7. // ...
  8. ]
  9. }

If you’d like to disable all of Tailwind’s core plugins and simply use Tailwind as a tool for processing your own custom plugins, provide an empty array:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: []
  4. }

Here’s a list of every core plugin for reference:

Core PluginDescription
preflightTailwind’s base/reset styles
containerThe .container component
alignContentThe align-content utilities like content-between
alignItemsThe align-items utilities like items-start
alignSelfThe align-self utilities like self-end
appearanceThe appearance utilities like appearance-none
backgroundAttachmentThe background-attachment utilities like bg-fixed
backgroundColorThe background-color utilities like bg-gray-200
backgroundPositionThe background-position utilities like bg-center
backgroundRepeatThe background-repeat utilities like bg-no-repeat
backgroundSizeThe background-size utilities like bg-cover
borderCollapseThe border-collapse utilities like border-separate
borderColorThe border-color utilities like border-gray-300
borderRadiusThe border-radius utilities like rounded-lg
borderStyleThe border-style utilities like border-dashed
borderWidthThe border-width utilities like border-2
boxShadowThe box-shadow utilities like shadow-xl
cursorThe cursor utilities like cursor-pointer
displayThe display utilities like block
fillThe fill utilities like fill-current
flexThe flex utilities like flex-1
flexDirectionThe flex-direction utilities like flex-col
flexGrowThe flex-grow utilities like flex-grow-0
flexShrinkThe flex-shrink utilities like flex-shrink-0
flexWrapThe flex-wrap utilities like flex-no-wrap
floatThe float utilities like float-left
fontFamilyThe font-family utilities like font-sans
fontSizeThe font-size utilities like text-xl
fontSmoothingThe font-smoothing utilities like antialiased
fontStyleThe font-style utilities like italic
fontWeightThe font-weight utilities like font-bold
heightThe height utilities like h-8
insetThe inset utilities like top-0
justifyContentThe justify-content utilities like justify-between
letterSpacingThe letter-spacing utilities like tracking-tight
lineHeightThe line-height utilities like leading-normal
listStylePositionThe list-style-position utilities like list-inside
listStyleTypeThe list-style-type utilities like list-disc
marginThe margin utilities like mt-4
maxHeightThe max-height utilities like max-h-screen
maxWidthThe max-width utilities like max-w-full
minHeightThe min-height utilities like min-h-screen
minWidthThe min-width utilities like min-w-0
negativeMarginThe negative-margin utilities like -mx-6
objectFitThe object-fit utilities like object-cover
objectPositionThe object-position utilities like object-center
opacityThe opacity utilities like opacity-50
outlineThe outline utilities like outline-none
overflowThe overflow utilities like overflow-hidden
paddingThe padding utilities like py-12
pointerEventsThe pointer-events utilities like pointer-events-none
positionThe position utilities like absolute
resizeThe resize utilities like resize-y
strokeThe stroke utilities like stroke-current
tableLayoutThe table-layout utilities like table-fixed
textAlignThe text-align utilities like text-center
textColorThe text-color utilities like text-red-600
textDecorationThe text-decoration utilities like underline
textTransformThe text-transform utilities like uppercase
userSelectThe user-select utilities like user-select-none
verticalAlignThe vertical-align utilities like align-middle
visibilityThe visibility utilities like invisible
whitespaceThe whitespace utilities like whitespace-no-wrap
widthThe width utilities like w-1/2
wordBreakThe word-break utilities like break-all
zIndexThe z-index utilities like z-50