Performance: Why responsive design is non-negotiable
Responsive design affects how quickly and smoothly a page adapts to different screen sizes, impacting user experience and loading speed on various devices.
<div class="w-full max-w-screen-lg mx-auto px-4">Content</div><div class="w-full" style="width:1200px;">Content</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed width layout | Low | Multiple on resize | High due to layout shifts | [X] Bad |
| Responsive layout with Tailwind | Low | Single or none | Low and stable | [OK] Good |
sm:, md:, lg:, and xl: to target screen sizes.md: prefix applies styles starting at medium screen widths and up.<div class="bg-red-500 sm:bg-green-500">Hello</div>
bg-red-500 applies red background always. The sm:bg-green-500 applies green background only on small screens and larger.bg-red-500 applies, so background is red.<div class="p-4 md:p-8 sm:p-6">Content</div>
p-4 md:p-8 sm:p-6 is incorrect because sm:p-6 comes after md:p-8, which can cause unexpected overrides.<button class="?">Click me</button>
sm:, desktops start at md:.bg-blue-500 sm:bg-green-500 md:bg-red-500.Pass the test and this pattern moves unknown