Sub topic 9
Customizing breakpoints
This chapter assumes you know the default breakpoint prefixes (sm, md, lg, xl, 2xl) and how mobile-first stacking works. It also assumes you can read a CSS file and a JavaScript config file. Here you will add breakpoints, replace the default set, and avoid the errors that come with both.
Why customize
The defaults suit many layouts. Sometimes they don't. A dashboard may need a 3xl: step for ultrawide monitors. A design system may define its own widths, such as tablet and desktop. In both cases you change the theme, not the markup. Every breakpoint you define becomes a variant prefix, so 3xl:grid-cols-6 works the same way as lg:grid-cols-3.
How you define a breakpoint depends on your Tailwind version.
Adding a breakpoint in Tailwind v4
Tailwind v4 is configured in CSS. Define a --breakpoint-* variable inside @theme. The part after --breakpoint- becomes the prefix.
@import "tailwindcss";
@theme {
--breakpoint-3xl: 120rem;
}You can now write 3xl:text-6xl. The default breakpoints stay in place, and 3xl applies from 120rem (1920px at the default 16px root font size) upward.
To replace the whole set, clear the defaults first. Setting --breakpoint-* to initial removes every default breakpoint, so you then define your own.
@import "tailwindcss";
@theme {
--breakpoint-*: initial;
--breakpoint-tablet: 40rem;
--breakpoint-laptop: 64rem;
--breakpoint-desktop: 80rem;
}After this, sm: and md: no longer exist. Any leftover md: class in your markup is silently ignored, so search your templates before removing defaults.
Adding a breakpoint in Tailwind v3
Tailwind v3 uses tailwind.config.js. Put your entry under theme.extend.screens to keep the defaults and add to them.
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
screens: {
'3xl': '1920px',
},
},
},
};If you put screens directly under theme instead of extend, it replaces the defaults entirely.
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
screens: {
tablet: '640px',
laptop: '1024px',
desktop: '1280px',
},
},
};Keep the order ascending
Mobile-first breakpoints rely on source order. A wider breakpoint must produce its CSS after a narrower one, so the wider rule wins when both match. Tailwind v4 sorts breakpoints by value for you. In v3, the order of keys in screens is the order of the generated CSS, so list them from smallest to largest. If you place desktop before tablet, tablet: utilities can override desktop: ones on wide screens.
Keep units consistent as well. Mixing rem and px in one theme makes the sort order hard to predict, because the pixel width of a rem value depends on the user's font size.
Choosing names and values
Prefer names that describe the step in a scale (3xl) over names that describe a device (iphone). Devices change, and a name tied to one misleads once a different device lands in that range. Choose widths where your content breaks, not where a popular device happens to sit.
For a single use, adding a theme entry is too much. The arbitrary min-[900px]: and max-[600px]: variants cover that case, and they are the topic of the next chapter.
Common errors
| Symptom | Likely cause |
|---|---|
| `3xl:` classes do nothing | The variable was defined outside `@theme` (v4), or the config has no `extend` and the file is not loaded (v3) |
| `md:` stopped working | Defaults were cleared with `--breakpoint-*: initial` or a top-level `theme.screens` |
| Wide styles override narrow ones unpredictably | v3 `screens` keys are not in ascending order, or units are mixed |
| Changes to config have no effect | The dev server was not restarted after editing `tailwind.config.js` |
Exercise
A Tailwind v3 project defines theme: { screens: { '3xl': '1920px' } } in its config. After the change, md:flex stops working across the site. Why, and what is the fix?
Show answer
Putting screens directly under theme replaces the default breakpoints, so only 3xl exists and md is gone. Move the entry under theme.extend.screens so the defaults stay and 3xl is added.