Performance: Mobile-first approach
This approach affects the initial page load speed and rendering performance on mobile devices by prioritizing simpler styles first.
Jump into concepts and practice - no test required
body { font-size: 1rem; } @media (min-width: 768px) { body { font-size: 1.2rem; } }body { font-size: 1.2rem; } @media (max-width: 767px) { body { font-size: 1rem; } }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Desktop-first CSS | Same | Multiple reflows due to overrides | Higher paint cost on mobile | [X] Bad |
| Mobile-first CSS | Same | Single reflow on mobile | Lower paint cost on mobile | [OK] Good |
min-width to add or change styles for tablets and desktops.min-width to add styles for bigger screens.@media screen and (min-width: 600px) targets screens wider than 600px correctly.body { background: white; }
@media (min-width: 600px) { body { background: blue; } }
@media (min-width: 800px) { body { background: green; } }body { font-size: 14px; }
@media (max-width: 600px) { body { font-size: 16px; } }max-width: 600px, which targets small screens.min-width for bigger screens, so this is reversed.@media (min-width: 768px) to set width 200px for larger screens.