Sub topic 9
Customizing breakpoints
This chapter assumes you know the default breakpoints (sm, md, lg, xl, 2xl), the mobile-first model, and how breakpoint prefixes apply to utilities. It also assumes you can read a basic CSS file and a JavaScript config file. You will learn how to add, rename, override and remove breakpoints in Tailwind v4 and v3, and when a custom breakpoint is the wrong tool.
Why customize at all
The defaults suit many sites, but a project sometimes needs something different:
- A design system specifies its own widths, such as a "tablet" at 800px.
- Your audience includes large monitors, and you want a step above
2xl. - Your team prefers names that describe devices or layouts instead of t-shirt sizes.
- A default breakpoint falls in the wrong place for your content. For example, a sidebar needs more room than
lggives it.
A custom breakpoint is a project-wide decision. Every developer on the team gets the same variant name with the same meaning. If you need a breakpoint for only one element, use an arbitrary value such as min-[900px]:flex instead. Those are covered in the previous chapter.
The defaults you are changing
Tailwind v4 defines the defaults in rem, and v3 defines them in px. They describe the same widths.
| Prefix | Minimum width | Rem (v4 default) |
|---|---|---|
| `sm` | 640px | 40rem |
| `md` | 768px | 48rem |
| `lg` | 1024px | 64rem |
| `xl` | 1280px | 80rem |
| `2xl` | 1536px | 96rem |
Each prefix compiles to a min-width media query. md:flex becomes @media (width >= 48rem) { ... } in v4.
Customizing in Tailwind v4
In v4 you configure breakpoints in CSS, inside an @theme block. Any theme variable in the --breakpoint-* namespace becomes a variant. The part after --breakpoint- is the variant name.
Adding a breakpoint
This adds a 3xl: variant and keeps the five defaults:
@import "tailwindcss";
@theme {
--breakpoint-3xl: 120rem;
}You can now write 3xl:grid-cols-6. The max-3xl: variant also exists, because Tailwind generates both forms from every breakpoint.
Using descriptive names
Names do not have to look like sizes. This adds tablet: and desktop::
@import "tailwindcss";
@theme {
--breakpoint-tablet: 50rem;
--breakpoint-desktop: 75rem;
}<section class="p-4 tablet:p-8 desktop:p-12">
Padding grows at 800px and 1200px.
</section>The default names still work next to these. If you mix naming schemes, people have to remember which names mean which widths. Pick one scheme and document it.
Overriding a default
To change a default, redefine its variable. Here sm starts at 30rem instead of 40rem:
@import "tailwindcss";
@theme {
--breakpoint-sm: 30rem;
}Every existing sm: class in your project now switches earlier. Check any component that relied on the old width.
Removing breakpoints
Set a variable to initial to remove it. This removes 2xl:
@import "tailwindcss";
@theme {
--breakpoint-2xl: initial;
}To drop all defaults and define your own scale from scratch, reset the whole namespace first:
@import "tailwindcss";
@theme {
--breakpoint-*: initial;
--breakpoint-tablet: 50rem;
--breakpoint-laptop: 64rem;
--breakpoint-desktop: 80rem;
}After this, md: and lg: no longer exist. Any leftover md: class in your markup is ignored and generates no CSS. It does not raise an error, so search your templates for old prefixes after a reset.
Customizing in Tailwind v3
In v3 you configure breakpoints in tailwind.config.js under theme.screens. Where you put the entry decides whether you keep the defaults.
Adding with `extend`
An entry under theme.extend.screens keeps the defaults and adds yours:
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
screens: {
'3xl': '1920px',
},
},
},
};Replacing with `theme.screens`
An entry directly under theme.screens replaces the whole default scale:
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
screens: {
tablet: '640px',
laptop: '1024px',
desktop: '1280px',
},
},
};Order matters in v3
Tailwind v3 emits breakpoint rules in the order the screens appear in the config. With extend, your new entries come after the defaults. That is fine for a larger value like 3xl. It breaks if you add a value smaller than an existing one, such as 'xs': '480px', because the xs: rules are emitted after sm: and later rules win at equal specificity. In that case, define the full list yourself in theme.screens, in ascending order. You can also import the defaults and spread them:
const defaultTheme = require('tailwindcss/defaultTheme');
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
screens: {
xs: '480px',
...defaultTheme.screens,
},
},
};Ranges and raw queries in v3
A v3 screen can be an object with min and max, which makes a variant that applies only inside a range. It can also be a raw media query string:
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
screens: {
'only-tablet': { min: '640px', max: '1023px' },
'tall': { raw: '(min-height: 800px)' },
},
},
},
};only-tablet:hidden hides an element between 640px and 1023px. tall:p-8 applies when the viewport is at least 800px high. Raw queries are useful for conditions that are not about width. In v4, you can get the same effect with @custom-variant or arbitrary variants, and you do not need to put them under --breakpoint-*.
Version comparison
| Task | Tailwind v4 (CSS) | Tailwind v3 (JS config) |
|---|---|---|
| Add a breakpoint | `--breakpoint-3xl: 120rem;` in `@theme` | `theme.extend.screens` |
| Override a default | Redefine the variable | Redefine under `extend.screens` or `screens` |
| Remove one | `--breakpoint-2xl: initial;` | Omit it from `theme.screens` |
| Remove all | `--breakpoint-*: initial;` | Define `theme.screens` yourself |
| Ordering | Sorted by value | Config order |
| Range variant | Stack `md:max-lg:` | Stack, or define `{ min, max }` |
If you upgrade a v3 project and keep a JavaScript config, load it from your CSS with @config "./tailwind.config.js";. Migrating the breakpoints into @theme is usually cleaner, since the config file then has less to hold.
Choosing a scale
The diagram shows a decision flow for choosing between the options in this chapter.
A few practical rules help keep a custom scale healthy:
- Base breakpoints on your content, not on devices. Resize the browser and note where the layout starts to look wrong. Put the breakpoint there.
- Keep the scale small. Each extra breakpoint multiplies the combinations you have to test.
- Add before you replace. Adding
3xlis low risk. Overridingsmormdchanges every class that uses them. - Keep names ordered. Names like
tabletanddesktopcommunicate order, and arbitrary names likefooandbardo not.
Edge cases and failure modes
- Utility names that collide. A breakpoint called
flexorhiddenwould be confusing, since a variant is writtenflex:and a utility isflex. Avoid names that match utility names. - Names starting with a digit.
3xlworks in both versions, and the default2xlalready follows the same pattern. Quote the key in a v3 config, as the examples above do. - Container query sizes are separate.
--breakpoint-*affects only viewport variants. Container variants such as@md:use the--container-*namespace, so overriding--breakpoint-mddoes not change@md:. - Stale classes after removal. Removed breakpoints fail silently. Search for the old prefixes in templates, component libraries and any documentation snippets.
- The viewport meta tag still matters. Custom breakpoints depend on the same real device width, so
<meta name="viewport" content="width=device-width, initial-scale=1">must still be in your document head. - Third-party components. UI kits that ship Tailwind classes assume the default scale. If you replace or shift defaults, their layouts can change without warning.
Putting it together
This example defines a small custom scale in v4 and uses it in a layout. The sidebar appears at tablet, and the page switches to three columns at desktop:
@import "tailwindcss";
@theme {
--breakpoint-*: initial;
--breakpoint-tablet: 50rem;
--breakpoint-desktop: 75rem;
--breakpoint-wide: 100rem;
}<div class="mx-auto grid max-w-screen-2xl grid-cols-1 gap-6 p-4 tablet:grid-cols-[14rem_1fr] desktop:grid-cols-[14rem_1fr_16rem]">
<aside class="hidden tablet:block">Sidebar</aside>
<main>Content</main>
<aside class="hidden desktop:block">Related links</aside>
</div>The unprefixed grid-cols-1 serves the smallest screens, as in any mobile-first layout. The max-w-screen-2xl class is not part of this reset scale, so remove it or replace it with a fixed max-w-* value. Always check which utilities depend on the scale you just removed. In this example, the max-w-screen-* utilities are the ones affected, because they are generated from the breakpoint list too.
Exercise
In a Tailwind v4 project you add --breakpoint-xs: 30rem; to @theme. A teammate then writes xs:flex-row max-xs:hidden. What does each class do, and does adding xs change what sm: means?
Show answer
xs:flex-row applies when the viewport is at least 30rem wide (480px), and max-xs:hidden hides the element when the viewport is narrower than 30rem. Adding xs does not change sm:, which stays at 40rem. v4 sorts breakpoints by value, so the smaller xs is emitted before sm. Mobile-first overriding therefore still works.
Exercise
A Tailwind v3 project adds extend: { screens: { xs: '480px' } }. On a 700px-wide screen, an element has sm:text-lg xs:text-sm. Which size applies, and how do you fix it?
Show answer
text-sm wins. v3 emits screens in config order, so with extend the xs rules come after sm. Both match at 700px, and the later rule wins. Fix it by defining the full list in theme.screens in ascending order, for example { xs: '480px', ...defaultTheme.screens }.