-
-
Notifications
You must be signed in to change notification settings - Fork 227
Closed
Description
System Information
- Tailwind CSS: v4.0.6
- Build Tool: Vite v6.0.11
- Node.js: v22.11.0
- Browser: Chrome v130.x
- Operating System: Windows 11 LTSC
Reproduction URL
Issue Description
With Tailwind CSS v4, breakpoints (e.g., sm
, md
, etc.) were switched to use rem
instead of px
. However, this causes inconsistencies because media queries in browsers do not respect a custom rootFontSize
—leading to incorrect breakpoint calculations.
The Tailwind VS Code extension correctly calculates pixel equivalents based on the configured tailwindCSS.rootFontSize
, but browsers always interpret 1rem = 16px
in media queries, ignoring any custom font size settings.
Expected Behavior
If tailwindCSS.rootFontSize
is set to 15px
, the VS Code extension displays:
.sm\:bg-green-100 {
@media (width >= 40rem /* 600px */) {
background-color: var(--color-green-100);
}
}
- The
40rem /* 600px */
part suggests that1rem = 15px
, which aligns with the expected base font size.
Actual Behavior
- Browsers do not respect
rootFontSize
in media queries and always interpret1rem = 16px
, meaning40rem = 640px
, not 600px. - This leads to a situation where using
rem
for breakpoints is not only inconvenient but also functionally incorrect in media queries.
Steps to Reproduce
- Set the base font size to
15px
(either viaaddBase
in Tailwind config or using plain CSS:html { font-size: 15px; }
- Use a
sm:bg-green-100
class in Tailwind. - Observe the Tailwind VS Code extension displaying:
@media (width < 40rem /* 600px */) { flex-wrap: wrap; }
- Check the actual media query behavior in a browser using DevTools:
- The breakpoint still applies at 640px, not 600px, proving that browsers ignore the custom font size in media queries.
Screenshots
Incorrect calculations in the VS Code extension vs. actual browser behavior:
Proposed Fix
- Option A: The VS Code extension should always assume
1rem = 16px
in media queries, regardless oftailwindCSS.rootFontSize
, ensuring the correct pixel values (40rem = 640px
, not 600px) are displayed. - Option B: Revert breakpoints to use
px
instead ofrem
, asrem
does not behave as expected in media queries.
Metadata
Metadata
Assignees
Labels
No labels