Performance: Mobile-first philosophy
This concept affects initial page load speed and rendering performance on mobile devices by prioritizing lightweight styles and content first.
.btn { padding: 1rem; } @media (min-width: 768px) { .btn { padding: 2rem; } }.btn { padding: 2rem; } @media (max-width: 767px) { .btn { padding: 1rem; } }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Desktop-first CSS | Same | Same | Higher due to larger CSS | [X] Bad |
| Mobile-first CSS | Same | Same | Lower due to smaller initial CSS | [OK] Good |
md: applies styles at medium screen size and above.md:, so it applies on medium and larger screens. Others apply on small, large, or all screens.md: means medium screens and up [OK]<div class="bg-red-500 md:bg-green-500">Box</div>What background color will the box have on a small screen?
bg-red-500 applies to all screens by default. The md:bg-green-500 applies only on medium and larger screens.md:bg-green-500 is ignored, so background stays red.<p class="md:text-red-500 text-blue-500">Hello</p>
md:.text-blue-500 applies on all screens, overridden by md:text-red-500 on medium+ screens, matching the goal.w-full for full width on small screens (default). Use md:w-[200px] to set width 200px on medium+ screens.Pass the test and this pattern moves unknown