Tailwind's container class sticks to the left and has no padding on small screens
container is flush left on the pageShort answer
Tailwind's container sets width 100% and a max-width equal to the current breakpoint, from sm upward. It does not center itself and adds no horizontal padding. Add mx-auto and a px utility yourself, and expect full width below the sm breakpoint.
Fix it fast
1Find out which cause you have
Inspect the element in browser dev tools and read the computed width, max-width and margin. They tell you which rule applies at the current screen width.
grep -rn "className=\"container" src2Match what you see, then jump to its fix
- 1
The content hugs the left edge once the screen is wider than the sm breakpointcontainer does not center itselfFix - 2
Text touches the screen edge on phonescontainer has no built-in horizontal paddingFix - 3
Width changes in steps as the window grows; sm: classes only apply from the breakpoint upThe max-width follows breakpoints, so it jumps at each oneFix
- 1
What does the error look like?
container is flush left on the pagecontainer touches the screen edge on a phone
Cause 1 of 3
container does not center itself
1Check
The docs state that Tailwind's container does not center itself automatically, unlike containers in other frameworks.
grep -rn "container" src --include=*.jsx --include=*.tsx2Fix
Add mx-auto to center it.
<div className="container mx-auto">
...
</div>3Verify
Widen the window past 40rem; the block should sit in the middle.
# resize the browser and re-inspect marginConfirmed by tailwindcss.com
Cause 2 of 3
container has no built-in horizontal padding
1Check
The docs say container has no built-in horizontal padding. Below the first breakpoint it is simply width: 100%.
# dev tools: computed padding-left is 0px2Fix
Add padding utilities next to mx-auto.
<div className="container mx-auto px-4">
...
</div>3Verify
Check a narrow viewport: there should be a gap on both sides.
# dev tools device mode, width 375pxConfirmed by tailwindcss.com
Cause 3 of 3
The max-width follows breakpoints, so it jumps at each one
1Check
container sets a max-width equal to the min-width of the current breakpoint. A breakpoint prefix such as md: applies at that size and above.
# dev tools: note max-width at 640px, 768px, 1024px2Fix
Write the mobile style with plain utilities and use a prefix only for the breakpoint and above; sm: does not mean small screens only. For a different fixed width, use a max-w utility instead of container.
<div className="mx-auto w-full max-w-sm px-4 md:max-w-lg">
...
</div>3Verify
Resize between phone and desktop widths and watch the width.
# resize the browserConfirmed by tailwindcss.com
How do I stop it coming back?
- Pair container with mx-auto and px-* every time, or wrap it in one reusable component.
- Write the mobile layout first with unprefixed classes, then add breakpoint prefixes.
- Check phone width in dev tools device mode before shipping.
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Tailwind is installed but the utility classes do nothing
Tailwind classes work in some components but not in others
When classes have no effect, the stylesheet either lacks the v4 import line, is never loaded by the page, or the class name never appears as plain text in a scanned file.
5 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
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
TypeScript marks className as an error on React Native components
Property 'className' does not exist on type
React Native components have no className prop in their own types.
3 causes, each with a fixWeb apps
A shadcn/ui Dialog stays open after the form is submitted
Form submits and the data saves, but the modal remains on screen
A shadcn Dialog is a Radix dialog.
3 causes, each with a fixWeb apps
shadcn/ui setup fails in a Vite React project using Tailwind v4
Imports from @/components/ui do not resolve in the editor or the build
shadcn init needs three things in a Vite project: Tailwind v4 installed with the @tailwindcss/vite plugin and a single @import "tailwindcss" line in your CSS, the @/* path alias in both tsconfig.json and tsconfig.app.json, and the same alias in vite.config.ts, with @types/node installed so path resolves.
4 causes, each with a fix