Friday, 27 November 2026

Max-width vs min-width: Which Media Query Should You Use




If you have ever opened an old stylesheet and found a pile of @media (max-width: ...) rules, you have seen desktop-first CSS. Most modern guides recommend the opposite: write for small screens first and use min-width to add layout as the screen grows. This article explains the difference in plain terms, shows a real before-and-after example, and covers the mistakes that usually appear when people convert old code.

The short answer

max-width means "apply these styles when the screen is this wide or smaller". min-width means "apply these styles when the screen is this wide or larger". That is the entire technical difference. The bigger difference is in how you think about your design.

Desktop-firstMobile-first
Media querymax-widthmin-width
Base styles are forLarge screensSmall screens
Media queriesUndo or shrink thingsAdd or expand things
Phone getsBase CSS plus many overridesOnly the base CSS

What desktop-first looks like

In a desktop-first stylesheet, the base rules describe the wide layout. Every smaller screen then needs overrides to take that layout apart again.

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

@media (max-width: 900px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .card-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

This works, but a phone has to read the three-column rule first and then cancel it. As the project grows, these overrides pile up and it becomes hard to tell which rule is actually winning.

The same layout, mobile-first

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 600px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
  }
}

@media (min-width: 900px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); }
}

Now the base rule is the simplest possible layout, and each breakpoint only adds something. The breakpoints also read in the same order as the screen grows, from small to large, which makes the file much easier to scan.

Why mobile-first is usually the better choice

  • Less to undo. Small screens get the simple styles directly instead of loading complex ones and cancelling them.
  • Easier to read. Breakpoints go in one direction, so you never need to ask "which query overrides which".
  • Matches how people browse. A large share of web traffic comes from phones, so it makes sense for them to be the default case.
  • Forces you to prioritise. With limited space you decide early what content really matters.

That said, desktop-first is not "wrong". If you maintain a large existing site and it works, rewriting everything just for the sake of it may not be worth the time. Convert it gradually, one component at a time.

The overlap problem at exact breakpoints

This one catches many people. If you write max-width: 768px and min-width: 768px, both conditions are true when the viewport is exactly 768px wide, so both rules apply at the same moment. There are two common ways to avoid it:

  • Use a different number on each side, for example max-width: 768px and min-width: 769px.
  • Use a small decimal such as min-width: 768.02px. Some browsers handle fractional widths on high-density screens, and the decimal keeps the two ranges from touching.

If you only use one direction in a project (all min-width), this problem mostly disappears, which is one more point in favour of mobile-first.

How to convert old max-width CSS

Simply replacing the word max-width with min-width will break your layout, because the meaning flips. Follow these steps instead:

  1. List your breakpoints. Search the file for every @media rule and write the widths down.
  2. Pick the small-screen version of each component. This becomes your new base style.
  3. Move the old desktop styles into min-width blocks. These now describe what changes when the screen gets larger.
  4. Order the blocks from smallest to largest. Later rules win when specificity is equal, so the order matters.
  5. Test at the edges. Check the layout just below and just above each breakpoint, not only on your own phone.

The mechanical part of this, swapping the queries and sorting the blocks, can be done automatically with the max-width to min-width converter on this site. The second part, moving your small-screen styles into the base rules, still needs a human, so review the output before you ship it.

Common mistakes

  • Mixing both directions in one stylesheet. It is possible, but it quickly becomes confusing. Choose one.
  • Forgetting the viewport meta tag. Without <meta name="viewport" content="width=device-width, initial-scale=1">, phones may pretend to be wider than they are and your media queries will not behave as expected.
  • Using device names as breakpoints. Do not design for "iPhone" or "iPad". Add a breakpoint where your content starts to look bad.
  • Leaving fixed widths in the base rules. A width: 1100px on a container will cause sideways scrolling on a phone. Prefer max-width as a property with width: 100%.

Frequently asked questions

Does min-width make my site faster?

Not directly. The speed benefit comes from the simpler code that mobile-first tends to produce. A phone does not need to parse and then cancel desktop-only layout rules.

Can I use both max-width and min-width together?

Yes. For example, @media (min-width: 600px) and (max-width: 899px) targets only a range. It is useful for a rule that should apply to tablets only, but use it sparingly.

What breakpoints should I use?

There is no perfect set. Common starting points are around 600px, 768px and 1024px, but the best method is to resize your browser and add a breakpoint wherever the design starts to break.

Do I have to convert my whole site?

No. If the existing code works, convert it step by step, starting with the components you touch most often.

Conclusion

The difference between max-width and min-width is small in syntax but large in effect. Writing small-screen styles first gives you simpler base code, fewer overrides and breakpoints that read in a natural order. If you are starting a new project, go mobile-first from day one. If you have an old stylesheet, convert it in small steps and test at every breakpoint.

No comments:

Post a Comment

Search This Blog

Blog Archive

Powered by Blogger.

How to Choose CSS Breakpoints: A Practical Mobile-First Guide

When you write mobile-first CSS, the base styles are for small screens and each min-width media query adds changes as the screen gets w...