mt-4 adds no space above an element in Tailwind
mt-4 on a span or a link has no visible effectShort answer
The class is usually generated correctly, but CSS ignores the margin. Vertical margin has no effect on a non-replaced inline element like a span. A top margin can also collapse into its parent's. Make the element block or inline-block, or stop the collapse with a padding, a border or flow-root.
Fix it fast
1Find out which cause you have
Inspect the element in dev tools. If margin-top appears in the Styles panel but the box does not move, the class works and CSS rules are ignoring the margin.
<span className="mt-4">Label</span>2Match what you see, then jump to its fix
- 1
Dev tools shows margin-top on a span, a, em or code, and nothing moves.The element is inlineFix - 2
The margin on the first child seems to move the whole parent box.The margin collapses with the parent's marginFix - 3
mt-[10%] gives a much smaller or larger space than expected.The class is not what you think it is (a percentage or a wrong value)Fix
- 1
What does the error look like?
mt-4 on a span or a link has no visible effectThe space above a child appears on its parent instead
Cause 1 of 3
The element is inline
1Check
MDN states that margin-top has no effect on non-replaced inline elements such as span or code. Check the element's computed display.
getComputedStyle($0).display2Fix
Change the display type: block, or inline-block when it must stay in a line of text.
<span className="mt-4 inline-block">Label</span>3Verify
The space above the label appears.
npm run devConfirmed by developer.mozilla.org
Cause 2 of 3
The margin collapses with the parent's margin
1Check
A parent's margin-top can collapse with its first child's when no border, padding, inline content or new formatting context separates them.
getComputedStyle($0.parentElement).display2Fix
Create a block formatting context on the parent with flow-root, or give the parent a padding or border.
<section className="flow-root">
<h2 className="mt-8">Title</h2>
</section>3Verify
The space now appears inside the section, above the heading.
npm run devConfirmed by developer.mozilla.org
Cause 3 of 3
The class is not what you think it is (a percentage or a wrong value)
1Check
A percentage margin is relative to the containing block's width, not its height, so on a wide, short box it looks too large. Tailwind generates margin-top: <value> for the arbitrary form.
getComputedStyle($0).marginTop2Fix
Use the spacing scale (mt-4 is margin-top: calc(var(--spacing) * 4)) or a fixed length, and use gap on flex or grid parents.
<div className="mt-4">...</div>
<div className="flex flex-col gap-4">...</div>3Verify
The computed margin-top matches the scale value you chose.
getComputedStyle($0).marginTopConfirmed by tailwindcss.com
How do I stop it coming back?
- Prefer gap on flex and grid parents over margins on each child.
- Check the element's display type before blaming the class.
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