Breakpoints

Customizing the default breakpoints for your project.


Basic customization

You define your project’s breakpoints in the theme.screens section of your tailwind.config.js file. The keys are your screen names (used as the prefix for the responsive utility variants Tailwind generates, like md:text-center), and the values are the min-width where that breakpoint should start.

The default breakpoints are inspired by common device resolutions:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. screens: {
  5. 'sm': '640px',
  6. // => @media (min-width: 640px) { ... }
  7. 'md': '768px',
  8. // => @media (min-width: 768px) { ... }
  9. 'lg': '1024px',
  10. // => @media (min-width: 1024px) { ... }
  11. 'xl': '1280px',
  12. // => @media (min-width: 1280px) { ... }
  13. }
  14. }
  15. }

Feel free to have as few or as many screens as you want, naming them in whatever way you’d prefer for your project.

For example, you could use device names instead of sizes:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. screens: {
  5. 'tablet': '640px',
  6. // => @media (min-width: 640px) { ... }
  7. 'laptop': '1024px',
  8. // => @media (min-width: 1024px) { ... }
  9. 'desktop': '1280px',
  10. // => @media (min-width: 1280px) { ... }
  11. },
  12. }
  13. }

These screen names will be reflected in your utilities, so your text-center utilities would now look like this:

  1. .text-center { text-align: center }
  2. @media (min-width: 640px) {
  3. .tablet\:text-center { text-align: center }
  4. }
  5. @media (min-width: 1024px) {
  6. .laptop\:text-center { text-align: center }
  7. }
  8. @media (min-width: 1280px) {
  9. .desktop\:text-center { text-align: center }
  10. }

Max-width breakpoints

If you want to work with max-width breakpoints instead of min-width, you can specify your screens as objects with a max key:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. screens: {
  5. 'xl': {'max': '1279px'},
  6. // => @media (max-width: 1279px) { ... }
  7. 'lg': {'max': '1023px'},
  8. // => @media (max-width: 1023px) { ... }
  9. 'md': {'max': '767px'},
  10. // => @media (max-width: 767px) { ... }
  11. 'sm': {'max': '639px'},
  12. // => @media (max-width: 639px) { ... }
  13. }
  14. }
  15. }

You can even create breakpoints with both min-width and max-width definitions if necessary, for example:

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

Multi-range breakpoints

Sometimes it can be useful to have a single breakpoint definition apply in multiple ranges.

For example, say you have a sidebar and want your breakpoints to be based on the content-area width rather than the entire viewport. You can simulate this having one of your breakpoints fall back to a smaller breakpoint when the sidebar becomes visible and shrinks the content area:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. screens: {
  5. 'sm': '500px',
  6. 'md': [
  7. // Sidebar appears at 768px, so revert to `sm:` styles between 768px
  8. // and 868px, after which the main content area is wide enough again to
  9. // apply the `md:` styles.
  10. {'min': '668px', 'max': '767px'},
  11. {'min': '868px'}
  12. ],
  13. 'lg': '1100px',
  14. 'xl': '1400px',
  15. }
  16. }
  17. }

Custom media queries

If you need to provide a completely custom media query for a breakpoint, you can do so using an object with a raw key:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. extend: {
  5. screens: {
  6. 'portrait': {'raw': '(orientation: portrait)'},
  7. // => @media (orientation: portrait) { ... }
  8. }
  9. }
  10. }
  11. }

Styling for print

The raw option can be particularly useful if you need to apply different styles specifically for print.

All you need to do is add a print screen under theme.extend.screens:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. extend: {
  5. screens: {
  6. 'print': {'raw': 'print'},
  7. // => @media print { ... }
  8. }
  9. }
  10. }
  11. }

Then you can use classes like print:text-black to specify styles that should only be applied when someone tries to print the page you’re working on:

  1. <div class="text-gray-700 print:text-black">
  2. <!-- ... -->
  3. </div>

Dark mode

The raw option can even be used to implement a “dark mode” screen:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. extend: {
  5. screens: {
  6. 'dark': {'raw': '(prefers-color-scheme: dark)'},
  7. // => @media (prefers-color-scheme: dark) { ... }
  8. }
  9. }
  10. }
  11. }

Then you can style elements differently in dark mode using the dark: prefix:

  1. <div class="text-gray-700 dark:text-gray-200">
  2. <!-- ... -->
  3. </div>

Note that because of how these screen variants are implemented in Tailwind you can’t combine breakpoints with dark mode using this approach, for example md:dark:text-gray-300 won’t work. This is something we’re hoping to address with official dark mode support in a future release.


← Theme   Colors →