Sub topic 10
One-off breakpoints with arbitrary values
This chapter assumes you know the default breakpoints (sm, md, lg, xl, 2xl), how mobile-first prefixes work, and how max-* variants limit a style to a width range. It also assumes you can read a basic CSS media query.
When a named breakpoint is the wrong tool
The default breakpoints suit most layouts. Sometimes one element needs to change at a width that no breakpoint matches. A banner might break at 900px, or a sidebar might need to collapse at 600px.
You could add a theme breakpoint for each case, but that makes a shared vocabulary of names (md, lg, 3xl) fill up with values used once. Arbitrary values let you write the width directly in the class and leave the theme alone.
The syntax
Put a width in square brackets after min- or max-:
<div class="min-[900px]:flex max-[600px]:hidden">One-off breakpoints</div>min-[900px]:flexappliesdisplay: flexwhen the viewport is at least 900px wide. It behaves like a customsm:prefix with a value you chose.max-[600px]:hiddenappliesdisplay: nonewhen the viewport is narrower than 600px.
The generated media queries differ by version:
| Class | Tailwind v3 (3.2 and later) | Tailwind v4 |
|---|---|---|
| `min-[900px]:flex` | `@media (min-width: 900px)` | `@media (width >= 900px)` |
| `max-[600px]:hidden` | `@media (max-width: 600px)` | `@media (width < 600px)` |
Any CSS length works, so you can use rem to scale with the user's font size:
<aside class="hidden min-[56rem]:block">Sidebar</aside>Using rem is a good habit here. The default breakpoints are also defined in rem, so a one-off value in rem stays consistent with them when users change their browser font size.
Combining arbitrary values with other variants
Arbitrary breakpoints stack like named ones. Each variant is separated by a colon:
<button class="bg-blue-600 min-[900px]:hover:bg-blue-700 max-[600px]:w-full">
Save
</button>Here the button is full width below 600px. The hover color applies only at 900px and wider. You can also combine an arbitrary value with a named one to build a range:
<div class="md:max-[1100px]:grid-cols-2">Two columns from md up to 1100px</div>Choosing between arbitrary, custom, and container breakpoints
As a rule of thumb, once you write the same arbitrary value a third time, move it into the theme.
Common errors
Building class names dynamically
Tailwind finds classes by scanning your source files for complete strings. This code never produces the CSS:
<script>
const width = 900;
const cls = `min-[${width}px]:flex`;
</script>The scanner sees min-[${width}px]:flex, which is not a valid class. Write the full class name, or choose between complete class strings:
<script>
const cls = isWide ? "min-[900px]:flex" : "min-[600px]:flex";
</script>Forgetting the unit
min-[900]:flex has no unit, so the generated media query is invalid and the browser ignores it. Always include px, rem, or another length unit.
Overlapping boundaries in v3
In v3, max-[900px] uses max-width: 900px, which includes 900px. Paired with min-[900px], both match at exactly 900px. In v4 the max-* query excludes the boundary, so the two do not overlap. If you support both versions, offset the values by one pixel, for example max-[899px].
Using arbitrary values for the whole layout
A page full of min-[713px] and min-[947px] is hard to maintain, because nobody can tell which values are intentional. Arbitrary values are for exceptions.
Summary of the working model
min-[value]:means "at this width or wider", andmax-[value]:means "narrower than this width".- They stack with state variants and named breakpoints.
- They need complete class strings and a unit.
- They are for one-offs. Shared widths belong in the theme.
Exercise
A product card needs flex-col by default, but it should switch to flex-row once the viewport is at least 720px wide. No theme breakpoint matches 720px. Write the class list, and say why min-[${w}px]:flex-row built from a JavaScript variable would fail.
Show answer
Use class="flex flex-col min-[720px]:flex-row". The unprefixed flex-col applies on all widths, and min-[720px]:flex-row overrides it from 720px up. The interpolated version fails because Tailwind scans source files for complete class strings, and min-[${w}px]:flex-row is not a complete class, so no CSS is generated for it. You must write the full class, such as min-[720px]:flex-row.