Performance: Max-width responsive variants
This affects how CSS rules apply at different screen widths, impacting rendering speed and layout stability during resizing.
/* Tailwind using max-width variant only */ "max-sm": "@media (max-width: 639px)", /* Usage */ max-sm\:p-2 { padding: 0.5rem; }
/* Tailwind config or CSS */ @media (min-width: 640px) { .btn { padding: 1rem; } } @media (max-width: 639px) { .btn { padding: 0.5rem; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using both min-width and max-width media queries | Low | Multiple reflows on resize | Medium | [X] Bad |
| Using only max-width responsive variants | Low | Single reflow on resize | Low | [OK] Good |
md:max-w-lg do?md:md: means the style applies from medium screen sizes and up.max-w-lgmax-w-lg sets the maximum width to a large size.md: + max-w-lg = Sets the max-width to large only on medium screens and larger [OK]md: with lg:lg:.max-w-md.lg: for large screens, then max-width size [OK]md: instead of lg:<div class="max-w-sm md:max-w-lg lg:max-w-xl">Content</div>
lg) breakpoint in Tailwind.lg:max-w-xl overrides smaller breakpoints.lg: classes apply = max-w-xl [OK]<div class="max-w-md sm:max-w-lg md:max-w-sm">Box</div>
sm:max-w-lg), but at medium screens it drops to small (md:max-w-sm).sm: is invalid for max-widthlg: to cause errorsmax-w-sm for small max-width on mobile (no prefix).md:max-w-md to set medium max-width starting at medium breakpoint.lg:max-w-xl to set extra-large max-width starting at large breakpoint.sm: for mobile default instead of no prefixPass the test and this pattern moves unknown