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. const colors = require('tailwindcss/colors')
  3. module.exports = {
  4. theme: {
  5. colors: {
  6. gray: colors.coolGray,
  7. blue: colors.lightBlue,
  8. red: colors.rose,
  9. pink: colors.fuchsia,
  10. },
  11. fontFamily: {
  12. sans: ['Graphik', 'sans-serif'],
  13. serif: ['Merriweather', 'serif'],
  14. },
  15. extend: {
  16. spacing: {
  17. '128': '32rem',
  18. '144': '36rem',
  19. },
  20. borderRadius: {
  21. '4xl': '2rem',
  22. }
  23. }
  24. },
  25. variants: {
  26. extend: {
  27. borderColor: ['focus-visible'],
  28. opacity: ['disabled'],
  29. }
  30. }
  31. }

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 tailwindcss init

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

  1. // tailwind.config.js
  2. module.exports = {
  3. purge: [],
  4. darkMode: false, // or 'media' or 'class'
  5. theme: {
  6. extend: {},
  7. },
  8. variants: {
  9. extend: {},
  10. },
  11. plugins: [],
  12. }

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 tailwindcss 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. tailwindcss: { config: './tailwindcss-config.js' },
  5. },
  6. }

Generating a PostCSS configuration file

Use the -p flag if you’d like to also generate a basic postcss.config.js file alongside your tailwind.config.js file:

  1. npx tailwindcss init -p

This will generate a postcss.config.js file in your project that looks like this:

  1. module.exports = {
  2. plugins: {
  3. tailwindcss: {},
  4. autoprefixer: {},
  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 tailwindcss 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, fonts, type scale, border sizes, breakpoints — anything related to the visual design of your site.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. colors: {
  5. gray: colors.coolGray,
  6. blue: colors.lightBlue,
  7. red: colors.rose,
  8. pink: colors.fuchsia,
  9. },
  10. fontFamily: {
  11. sans: ['Graphik', 'sans-serif'],
  12. serif: ['Merriweather', 'serif'],
  13. },
  14. extend: {
  15. spacing: {
  16. '128': '32rem',
  17. '144': '36rem',
  18. },
  19. borderRadius: {
  20. '4xl': '2rem',
  21. }
  22. }
  23. }
  24. }

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. fill: [],
  5. extend: {
  6. borderColor: ['focus-visible'],
  7. opacity: ['disabled'],
  8. }
  9. },
  10. }

Learn more in the variants configuration guide.

Plugins

The plugins section allows you to register 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/forms'),
  5. require('@tailwindcss/aspect-ratio'),
  6. require('@tailwindcss/typography'),
  7. require('tailwindcss-children'),
  8. ],
  9. }

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

Presets

The presets section allows you to specify your own custom base configuration instead of using Tailwind’s default base configuration.

  1. // tailwind.config.js
  2. module.exports = {
  3. presets: [
  4. require('@acmecorp/base-tailwind-config')
  5. ],
  6. // Project-specific customizations
  7. theme: {
  8. //...
  9. },
  10. // ...
  11. }

Learn more about presets in the presets documentation.

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 class 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 after any variant prefixes. 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. @variants hover {
  2. .bg-brand-gradient { /* ... */ }
  3. }

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

  1. .bg-brand-gradient { /* ... */ }
  2. .hover\:bg-brand-gradient:hover { /* ... */ }

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

  1. @variants hover {
  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. }

Selector strategy

Setting important to true can introduce some issues when incorporating third-party JS libraries that add inline styles to your elements. In those cases, Tailwind’s !important utilities defeat the inline styles, which can break your intended design.

To get around this, you can set important to an ID selector like #app instead:

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

This configuration will prefix all of your utilities with the given selector, effectively increasing their specificity without actually making them !important.

After you specify the important selector, you’ll need to ensure that the root element of your site matches it. Using the example above, we would need to set our root element’s id attribute to app in order for styles to work properly.

After your configuration is all set up and your root element matches the selector in your Tailwind config, all of Tailwind’s utilities will have a high enough specificity to defeat other classes used in your project, without interfering with inline styles:

  1. <html>
  2. <!-- ... -->
  3. <style>
  4. .high-specificity .nested .selector {
  5. color: blue;
  6. }
  7. </style>
  8. <body id="app">
  9. <div class="high-specificity">
  10. <div class="nested">
  11. <!-- Will be red-500 -->
  12. <div class="selector text-red-500"><!-- ... --></div>
  13. </div>
  14. </div>
  15. <!-- Will be #bada55 -->
  16. <div class="text-red-500" style="color: #bada55;"><!-- ... --></div>
  17. </body>
  18. </html>

When using the selector strategy, be sure that the template file that includes your root selector is included in your purge configuration, otherwise all of your CSS will be removed when building for production.

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. }

Variant Order

If you are using the extend feature to enable extra variants, those variants are automatically sorted to respect a sensible default variant order.

You can customize this if necessary under the variantOrder key:

  1. // tailwind.config.js
  2. module.exports = {
  3. // ...
  4. variantOrder: [
  5. 'first',
  6. 'last',
  7. 'odd',
  8. 'even',
  9. 'visited',
  10. 'checked',
  11. 'group-hover',
  12. 'group-focus',
  13. 'focus-within',
  14. 'hover',
  15. 'focus',
  16. 'focus-visible',
  17. 'active',
  18. 'disabled',
  19. ]
  20. }

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 = {
  3. // ...
  4. }

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 safelist 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
accessibilityThe sr-only and not-sr-only utilities
alignContentThe align-content utilities like content-end
alignItemsThe align-items utilities like items-center
alignSelfThe align-self utilities like self-end
animationThe animation utilities like
appearanceThe appearance utilities like appearance-none
backdropBlurThe backdrop-blur utilities like
backdropBrightnessThe backdrop-brightness utilities like
backdropContrastThe backdrop-contrast utilities like
backdropFilterThe backdrop-filter utilities like backdrop-filter
backdropGrayscaleThe backdrop-grayscale utilities like
backdropHueRotateThe backdrop-hue-rotate utilities like
backdropInvertThe backdrop-invert utilities like
backdropOpacityThe backdrop-opacity utilities like
backdropSaturateThe backdrop-saturate utilities like
backdropSepiaThe backdrop-sepia utilities like
backgroundAttachmentThe background-attachment utilities like bg-local
backgroundBlendModeThe background-blend-mode utilities like bg-blend-color-burn
backgroundClipThe background-clip utilities like bg-clip-padding
backgroundColorThe background-color utilities like
backgroundImageThe background-image utilities like
backgroundOpacityThe background-color opacity utilities like bg-opacity-25
backgroundOriginThe background-origin utilities like bg-origin-padding
backgroundPositionThe background-position utilities like
backgroundRepeatThe background-repeat utilities like bg-repeat-x
backgroundSizeThe background-size utilities like
blurThe blur utilities like
borderCollapseThe border-collapse utilities like border-collapse
borderColorThe border-color utilities like
borderOpacityThe border-color opacity utilities like border-opacity-25
borderRadiusThe border-radius utilities like
borderStyleThe border-style utilities like border-dotted
borderWidthThe border-width utilities like
boxDecorationBreakThe box-decoration-break utilities like decoration-slice
boxShadowThe box-shadow utilities like ,
boxSizingThe box-sizing utilities like box-border
brightnessThe brightness utilities like
caretColorThe caret-color utilities like
clearThe clear utilities like clear-right
contentThe content utilities like
contrastThe contrast utilities like
cursorThe cursor utilities like
displayThe display utilities like table-column-group
divideColorThe between elements border-color utilities like divide-gray-500
divideOpacityThe divide-opacity utilities like
divideStyleThe divide-style utilities like divide-dotted
divideWidthThe between elements border-width utilities like divide-x-2
dropShadowThe drop-shadow utilities like drop-shadow-lg
fillThe fill utilities like
filterThe filter utilities like filter
flexThe flex utilities like
flexDirectionThe flex-direction utilities like flex-row-reverse
flexGrowThe flex-grow utilities like
flexShrinkThe flex-shrink utilities like
flexWrapThe flex-wrap utilities like flex-wrap-reverse
floatThe float utilities like float-left
fontFamilyThe font-family utilities like
fontSizeThe font-size utilities like
fontSmoothingThe font-smoothing utilities like antialiased
fontStyleThe font-style utilities like italic
fontVariantNumericThe font-variant-numeric utilities like lining-nums
fontWeightThe font-weight utilities like
gapThe gap utilities like
gradientColorStopsThe gradient-color-stops utilities like
grayscaleThe grayscale utilities like
gridAutoColumnsThe grid-auto-columns utilities like
gridAutoFlowThe grid-auto-flow utilities like grid-flow-col
gridAutoRowsThe grid-auto-rows utilities like
gridColumnThe grid-column utilities like
gridColumnEndThe grid-column-end utilities like
gridColumnStartThe grid-column-start utilities like
gridRowThe grid-row utilities like
gridRowEndThe grid-row-end utilities like
gridRowStartThe grid-row-start utilities like
gridTemplateColumnsThe grid-template-columns utilities like
gridTemplateRowsThe grid-template-rows utilities like
heightThe height utilities like
hueRotateThe hue-rotate utilities like
insetThe inset utilities like
invertThe invert utilities like
isolationThe isolation utilities like isolate
justifyContentThe justify-content utilities like justify-center
justifyItemsThe justify-items utilities like justify-items-end
justifySelfThe justify-self utilities like justify-self-end
letterSpacingThe letter-spacing utilities like
lineHeightThe line-height utilities like
listStylePositionThe list-style-position utilities like list-inside
listStyleTypeThe list-style-type utilities like
marginThe margin utilities like
maxHeightThe max-height utilities like
maxWidthThe max-width utilities like
minHeightThe min-height utilities like
minWidthThe min-width utilities like
mixBlendModeThe mix-blend-mode utilities like mix-blend-color-burn
objectFitThe object-fit utilities like object-fill
objectPositionThe object-position utilities like
opacityThe opacity utilities like
orderThe order utilities like
outlineThe outline utilities like
overflowThe overflow utilities like overflow-y-auto
overscrollBehaviorThe overscroll-behavior utilities like overscroll-y-contain
paddingThe padding utilities like
placeContentThe place-content utilities like place-content-between
placeholderColorThe placeholder color utilities like placeholder-red-600
placeholderOpacityThe placeholder color opacity utilities like placeholder-opacity-25
placeItemsThe place-items utilities like place-items-end
placeSelfThe place-self utilities like place-self-end
pointerEventsThe pointer-events utilities like pointer-events-none
positionThe position utilities like absolute
resizeThe resize utilities like resize-y
ringColorThe ring-color utilities like
ringOffsetColorThe ring-offset-color utilities like
ringOffsetWidthThe ring-offset-width utilities like
ringOpacityThe ring-opacity utilities like
ringWidthThe ring-width utilities like ,
rotateThe rotate utilities like
saturateThe saturate utilities like
scaleThe scale utilities like
sepiaThe sepia utilities like
skewThe skew utilities like
spaceThe “space-between” utilities like space-x-4
strokeThe stroke utilities like
strokeWidthThe stroke-width utilities like
tableLayoutThe table-layout utilities like table-auto
textAlignThe text-align utilities like text-center
textColorThe text-color utilities like
textDecorationThe text-decoration utilities like line-through
textOpacityThe text-opacity utilities like
textOverflowThe text-overflow utilities like overflow-ellipsis
textTransformThe text-transform utilities like lowercase
transformThe transform utility (for enabling transform features)
transformOriginThe transform-origin utilities like
transitionDelayThe transition-delay utilities like
transitionDurationThe transition-duration utilities like
transitionPropertyThe transition-property utilities like
transitionTimingFunctionThe transition-timing-function utilities like
translateThe translate utilities like
userSelectThe user-select utilities like select-text
verticalAlignThe vertical-align utilities like align-middle
visibilityThe visibility utilities like visible
whitespaceThe whitespace utilities like whitespace-pre
widthThe width utilities like
wordBreakThe word-break utilities like break-words
zIndexThe z-index utilities like

Referencing in JavaScript

It can often be useful to reference your configuration values in your own client-side JavaScript — for example to access some of your theme values when dynamically applying inline styles in a React or Vue component.

To make this easy, Tailwind provides a resolveConfig helper you can use to generate a fully merged version of your configuration object:

  1. import resolveConfig from 'tailwindcss/resolveConfig'
  2. import tailwindConfig from './tailwind.config.js'
  3. const fullConfig = resolveConfig(tailwindConfig)
  4. fullConfig.theme.width[4]
  5. // => '1rem'
  6. fullConfig.theme.screens.md
  7. // => '768px'
  8. fullConfig.theme.boxShadow['2xl']
  9. // => '0 25px 50px -12px rgba(0, 0, 0, 0.25)'

Note that this will transitively pull in a lot of our build-time dependencies, resulting in bigger bundle client-side size. To avoid this, we recommend using a tool like babel-plugin-preval to generate a static version of your configuration at build-time.

←Functions & DirectivesJust-in-Time Mode→

Edit this page on GitHub