Tailwind md:, lg: and sm: classes do not override as expected
sm:text-center has no effect on a phoneShort answer
Tailwind is mobile-first: a plain class applies at every width, and sm:, md: or lg: applies at that width and above. So sm: does not mean phones. Put the mobile style first with no prefix, add the larger style with a prefix, use max-* to cap a range, and write class names out in full.
Fix it fast
1Find out which cause you have
Resize the browser and open the element in dev tools. Check which media query each class sits in, then compare it with the width where you expected the change.
grep -rn "md:" resources/views | head npm run build2Match what you see, then jump to its fix
- 1
The style appears only from 640px upward and never on a phonesm: was used to target small screensFix - 2
md:flex works, but the same layout is wanted only between two widthsA style from a smaller breakpoint is still applied at larger sizesFix - 3
The class is in the HTML, but no CSS rule exists for it in the built stylesheetThe class name is built at runtime, so Tailwind never generates itFix
- 1
What does the error look like?
sm:text-center has no effect on a phonemd:flex still applies on large screensA breakpoint class works only when written by hand, not when built from a variable
Cause 1 of 3
sm: was used to target small screens
1Check
Unprefixed utilities take effect at every size, while prefixed ones apply at that breakpoint and above. The docs call out sm: for mobile as a common mistake.
grep -rn "class=.*sm:" resources/views | head2Fix
Write the mobile style with no prefix and the larger-screen style with the prefix.
<!-- wrong: centers only from 640px up -->
<div class="sm:text-center"></div>
<!-- right: centered on mobile, left aligned from 640px up -->
<div class="text-center sm:text-left"></div>3Verify
Rebuild and check the page at 375px and at 800px.
npm run buildConfirmed by tailwindcss.com
Cause 2 of 3
A style from a smaller breakpoint is still applied at larger sizes
1Check
Styles such as md:flex stay applied at larger breakpoints, so a rule meant for one range leaks into the next.
grep -rn "md:" resources/views | head2Fix
Stack the breakpoint with a max-* variant to limit the range, or set the opposite style at the next breakpoint.
<!-- flex only from 768px up to below 1280px -->
<div class="md:max-xl:flex"></div>
<!-- or undo it at the next breakpoint -->
<div class="md:flex xl:block"></div>3Verify
Check the element at widths just below and above each breakpoint.
npm run buildConfirmed by tailwindcss.com
Cause 3 of 3
The class name is built at runtime, so Tailwind never generates it
1Check
Tailwind reads source files as plain text and cannot see names assembled from pieces such as md:grid-cols-{{ $n }}.
grep -rn "md:grid-cols-\$\|md:grid-cols-{{" resources/views | head2Fix
Write each complete class name somewhere in the source, for example in a map that picks one of them.
@php
$cols = [2 => 'md:grid-cols-2', 3 => 'md:grid-cols-3'];
@endphp
<div class="grid {{ $cols[$n] }}"></div>3Verify
Rebuild and search the output CSS for the class.
npm run buildConfirmed by tailwindcss.com
How do I stop it coming back?
- Design the smallest screen first and add one prefix per larger layout step.
- Never assemble class names from variables; map values to complete class strings.
- Test at widths on both sides of every breakpoint you use, not only at the device presets.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
focus:outline-none does not remove the focus border in Tailwind
A ring still shows around the field when focused
focus:outline-none only controls the CSS outline.
3 causes, each with a fixWeb apps
group-focus classes in a Tailwind page do nothing when the field is focused
The class is in the HTML, but the built CSS has no rule for it
group-focus styles the target only while the element that carries the group class has focus itself.
4 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
Laravel cannot find a Sass or JS entry in the Vite manifest
Unable to locate file in Vite manifest: resources/sass/app.scss
The @vite directive asks the built manifest for a file, and that file is listed only if it is an entry in the laravel() input option and the assets were built after adding it.
3 causes, each with a fixWeb apps
Hydration failed after adding next-themes dark mode
Console reports a server and client mismatch on the html element
next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.
3 causes, each with a fixWeb apps
Next.js fails with Cannot find module 'tailwindcss'
Error: Cannot find module 'tailwindcss'
Next.js loads Tailwind through PostCSS, so the error means the package named in postcss.config is not installed where the build runs.
3 causes, each with a fix