Theme Configuration

Customizing the default theme for your project.

The theme section of your tailwind.config.js file is where you define your project’s color palette, type scale, fonts, breakpoints, border radius values, and more.

  1. // tailwind.config.js
  2. const colors = require('tailwindcss/colors')
  3. module.exports = {
  4. theme: {
  5. screens: {
  6. sm: '480px',
  7. md: '768px',
  8. lg: '976px',
  9. xl: '1440px',
  10. },
  11. colors: {
  12. gray: colors.coolGray,
  13. blue: colors.lightBlue,
  14. red: colors.rose,
  15. pink: colors.fuchsia,
  16. },
  17. fontFamily: {
  18. sans: ['Graphik', 'sans-serif'],
  19. serif: ['Merriweather', 'serif'],
  20. },
  21. extend: {
  22. spacing: {
  23. '128': '32rem',
  24. '144': '36rem',
  25. },
  26. borderRadius: {
  27. '4xl': '2rem',
  28. }
  29. }
  30. }
  31. }

We provide a sensible default theme with a very generous set of values to get you started, but don’t be afraid to change it or extend; you’re encouraged to customize it as much as you need to fit the goals of your design.


Theme structure

The theme object contains keys for screens, colors, and spacing, as well as a key for each customizable core plugin.

See the theme configuration reference or the default theme for a complete list of theme options.

Screens

The screens key allows you to customize the responsive breakpoints in your project.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. screens: {
  5. 'sm': '640px',
  6. 'md': '768px',
  7. 'lg': '1024px',
  8. 'xl': '1280px',
  9. '2xl': '1536px',
  10. }
  11. }
  12. }

To learn more, see the breakpoint customization documentation.

Colors

The colors key allows you to customize the global color palette for your project.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. colors: {
  5. transparent: 'transparent',
  6. black: '#000',
  7. white: '#fff',
  8. gray: {
  9. 100: '#f7fafc',
  10. // ...
  11. 900: '#1a202c',
  12. },
  13. // ...
  14. }
  15. }
  16. }

By default, these colors are inherited by all color-related core plugins, like backgroundColor, borderColor, textColor, and others.

To learn more, see the color customization documentation.

Spacing

The spacing key allows you to customize the global spacing and sizing scale for your project.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. spacing: {
  5. px: '1px',
  6. 0: '0',
  7. 0.5: '0.125rem',
  8. 1: '0.25rem',
  9. 1.5: '0.375rem',
  10. 2: '0.5rem',
  11. 2.5: '0.625rem',
  12. 3: '0.75rem',
  13. 3.5: '0.875rem',
  14. 4: '1rem',
  15. 5: '1.25rem',
  16. 6: '1.5rem',
  17. 7: '1.75rem',
  18. 8: '2rem',
  19. 9: '2.25rem',
  20. 10: '2.5rem',
  21. 11: '2.75rem',
  22. 12: '3rem',
  23. 14: '3.5rem',
  24. 16: '4rem',
  25. 20: '5rem',
  26. 24: '6rem',
  27. 28: '7rem',
  28. 32: '8rem',
  29. 36: '9rem',
  30. 40: '10rem',
  31. 44: '11rem',
  32. 48: '12rem',
  33. 52: '13rem',
  34. 56: '14rem',
  35. 60: '15rem',
  36. 64: '16rem',
  37. 72: '18rem',
  38. 80: '20rem',
  39. 96: '24rem',
  40. },
  41. }
  42. }

By default, these values are inherited by the padding, margin, width, height, maxHeight, gap, inset, space, and translate core plugins.

To learn more, see the spacing customization documentation.

Core plugins

The rest of the theme section is used to configure which values are available for each individual core plugin.

For example, the borderRadius key lets you customize which border radius utilities will be generated:

  1. module.exports = {
  2. theme: {
  3. borderRadius: {
  4. 'none': '0',
  5. 'sm': '.125rem',
  6. DEFAULT: '.25rem',
  7. 'lg': '.5rem',
  8. 'full': '9999px',
  9. },
  10. }
  11. }

The keys determine the suffix for the generated classes, and the values determine the value of the actual CSS declaration.

The example borderRadius configuration above would generate the following CSS classes:

  1. .rounded-none { border-radius: 0 }
  2. .rounded-sm { border-radius: .125rem }
  3. .rounded { border-radius: .25rem }
  4. .rounded-lg { border-radius: .5rem }
  5. .rounded-full { border-radius: 9999px }

You’ll notice that using a key of DEFAULT in the theme configuration created the class rounded with no suffix. This is a common convention in Tailwind and is supported by all core plugins.

To learn more about customizing a specific core plugin, visit the documentation for that plugin.

For a complete reference of available theme properties and their default values, see the default theme configuration.

Customizing the default theme

Out of the box, your project will automatically inherit the values from the default theme configuration. If you would like to customize the default theme, you have a few different options depending on your goals.

Extending the default theme

If you’d like to preserve the default values for a theme option but also add new values, add your extensions under the extend key in the theme section of your configuration file.

For example, if you wanted to add an extra breakpoint but preserve the existing ones, you could extend the screens property:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. extend: {
  5. // Adds a new breakpoint in addition to the default breakpoints
  6. screens: {
  7. '3xl': '1600px',
  8. }
  9. }
  10. }
  11. }

Overriding the default theme

To override an option in the default theme, add your overrides directly under the theme section of your tailwind.config.js:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. // Replaces all of the default `opacity` values
  5. opacity: {
  6. '0': '0',
  7. '20': '0.2',
  8. '40': '0.4',
  9. '60': '0.6',
  10. '80': '0.8',
  11. '100': '1',
  12. }
  13. }
  14. }

This will completely replace Tailwind’s default configuration for that key, so in the example above none of the default opacity utilities would be generated.

Any keys you do not provide will be inherited from the default theme, so in the above example, the default theme configuration for things like colors, spacing, border-radius, background-position, etc. would be preserved.

You can of course both override some parts of the default theme and extend other parts of the default theme within the same configuration:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. opacity: {
  5. '0': '0',
  6. '20': '0.2',
  7. '40': '0.4',
  8. '60': '0.6',
  9. '80': '0.8',
  10. '100': '1',
  11. },
  12. extend: {
  13. screens: {
  14. '3xl': '1600px',
  15. }
  16. }
  17. }
  18. }

Referencing other values

If you need to reference another value in your theme, you can do so by providing a closure instead of a static value. The closure will receive a theme() function that you can use to look up other values in your theme using dot notation.

For example, you could generate fill utilities for every color in your color palette by referencing theme('colors') in your fill configuration:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. colors: {
  5. // ...
  6. },
  7. fill: theme => theme('colors')
  8. }
  9. }

The theme() function attempts to find the value you are looking for from the fully merged theme object, so it can reference your own customizations as well as the default theme values. It also works recursively, so as long as there is a static value at the end of the chain it will be able to resolve the value you are looking for.

Note that you can only use this kind of closure with top-level theme keys, not the keys inside of each section.

Theme - 图1You can’t use functions for individual values

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. fill: {
  5. gray: theme => theme('colors.gray')
  6. }
  7. }
  8. }

Theme - 图2Use functions for top-level theme keys

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. fill: theme => ({
  5. gray: theme('colors.gray')
  6. })
  7. }
  8. }

Referencing the default theme

If you’d like to reference a value in the default theme for any reason, you can import it from tailwindcss/defaultTheme.

One example of where this is useful is if you’d like to add a font family to one of Tailwind’s default font stacks:

  1. // tailwind.config.js
  2. const defaultTheme = require('tailwindcss/defaultTheme')
  3. module.exports = {
  4. theme: {
  5. extend: {
  6. fontFamily: {
  7. sans: [
  8. 'Lato',
  9. ...defaultTheme.fontFamily.sans,
  10. ]
  11. }
  12. }
  13. }
  14. }

Disabling an entire core plugin

If you don’t want to generate any classes for a certain core plugin, it’s better to set that plugin to false in your corePlugins configuration than to provide an empty object for that key in your theme configuration.

Theme - 图3Don’t assign an empty object in your theme configuration

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. opacity: {},
  5. }
  6. }

Theme - 图4Do disable the plugin in your corePlugins configuration

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

The end result is the same, but since many core plugins expose no configuration they can only be disabled using corePlugins anyways, so it’s better to be consistent.

Adding your own keys

There are a number of situations where it can be useful to add your own keys to the theme object.

One example of this is adding new keys to create a single source of truth for values that are common between multiple core plugins. For example, you could extract a shared positions object that could be referenced by both the backgroundPosition and objectPosition plugins:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. positions: {
  5. bottom: 'bottom',
  6. center: 'center',
  7. left: 'left',
  8. 'left-bottom': 'left bottom',
  9. 'left-top': 'left top',
  10. right: 'right',
  11. 'right-bottom': 'right bottom',
  12. 'right-top': 'right top',
  13. top: 'top',
  14. },
  15. backgroundPosition: theme => theme('positions'),
  16. objectPosition: theme => theme('positions'),
  17. }
  18. }

Another example is adding a new key to reference inside a custom plugin. For example, if you’ve written a filters plugin for your project, you might add a filters key to your theme object that the plugin references:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. filters: {
  5. none: 'none',
  6. grayscale: 'grayscale(1)',
  7. invert: 'invert(1)',
  8. sepia: 'sepia(1)',
  9. }
  10. },
  11. plugins: [
  12. require('./plugins/filters')
  13. ],
  14. }

Since the entire theme object is available in your CSS using the theme function, you might also add a key just to be able to reference it in your CSS.

Configuration reference

Except for screens, colors, and spacing, all of the keys in the theme object map to one of Tailwind’s core plugins. Since many plugins are responsible for CSS properties that only accept a static set of values (like float for example), note that not every plugin has a corresponding key in the theme object.

All of these keys are also available under the theme.extend key to enable extending the default theme.

KeyDescription
screensYour project’s responsive breakpoints
colorsYour project’s color palette
spacingYour project’s spacing scale
animationValues for the animation property
backdropBlurValues for the backdrop-blur property
backdropBrightnessValues for the backdrop-brightness property
backdropContrastValues for the backdrop-contrast property
backdropGrayscaleValues for the backdrop-grayscale property
backdropHueRotateValues for the backdrop-hue-rotate property
backdropInvertValues for the backdrop-invert property
backdropOpacityValues for the backdrop-opacity property
backdropSaturateValues for the backdrop-saturate property
backdropSepiaValues for the backdrop-sepia property
backgroundColorValues for the background-color property
backgroundImageValues for the background-image property
backgroundOpacityValues for the background-opacity property
backgroundPositionValues for the background-position property
backgroundSizeValues for the background-size property
blurValues for the blur property
brightnessValues for the brightness property
borderColorValues for the border-color property
borderOpacityValues for the border-opacity property
borderRadiusValues for the border-radius property
borderWidthValues for the border-width property
boxShadowValues for the box-shadow property
caretColorValues for the caret-color property
contrastValues for the contrast property
containerConfiguration for the container plugin
contentValues for the content property
cursorValues for the cursor property
divideColorValues for the divide-color property
divideOpacityValues for the divide-opacity property
divideWidthValues for the divide-width property
dropShadowValues for the drop-shadow property
fillValues for the fill property
grayscaleValues for the grayscale property
hueRotateValues for the hue-rotate property
invertValues for the invert property
flexValues for the flex property
flexGrowValues for the flex-grow property
flexShrinkValues for the flex-shrink property
fontFamilyValues for the font-family property
fontSizeValues for the font-size property
fontWeightValues for the font-weight property
gapValues for the gap property
gradientColorStopsValues for the gradient-color-stops property
gridAutoColumnsValues for the grid-auto-columns property
gridAutoRowsValues for the grid-auto-rows property
gridColumnValues for the grid-column property
gridColumnEndValues for the grid-column-end property
gridColumnStartValues for the grid-column-start property
gridRowValues for the grid-row property
gridRowStartValues for the grid-row-start property
gridRowEndValues for the grid-row-end property
gridTemplateColumnsValues for the grid-template-columns property
gridTemplateRowsValues for the grid-template-rows property
heightValues for the height property
insetValues for the top, right, bottom, and left properties
keyframesValues for the keyframes property
letterSpacingValues for the letter-spacing property
lineHeightValues for the line-height property
listStyleTypeValues for the list-style-type property
marginValues for the margin property
maxHeightValues for the max-height property
maxWidthValues for the max-width property
minHeightValues for the min-height property
minWidthValues for the min-width property
objectPositionValues for the object-position property
opacityValues for the opacity property
orderValues for the order property
outlineValues for the outline property
paddingValues for the padding property
placeholderColorValues for the placeholderColor plugin
placeholderOpacityValues for the placeholderOpacity plugin
ringColorValues for the ring-color property
ringOffsetColorValues for the ring-offset-color property
ringOffsetWidthValues for the ring-offset-width property
ringOpacityValues for the ring-opacity property
ringWidthValues for the ring-width property
rotateValues for the rotate plugin
saturateValues for the saturate property
scaleValues for the scale plugin
sepiaValues for the sepia property
skewValues for the skew plugin
spaceValues for the space plugin
strokeValues for the stroke property
strokeWidthValues for the stroke-width property
textColorValues for the text-color property
textOpacityValues for the textOpacity plugin
transformOriginValues for the transform-origin property
transitionDelayValues for the transition-delay property
transitionDurationValues for the transition-duration property
transitionPropertyValues for the transition-property property
transitionTimingFunctionValues for the transition-timing-function property
translateValues for the translate plugin
widthValues for the width property
zIndexValues for the z-index property

←Just-in-Time Mode Breakpoints→

Edit this page on GitHub