HTML & CSSEasy
What is mobile-first design?
Mobile-first design means designing and writing CSS for the smallest screens first, then progressively adding layout and features for larger screens with min-width media queries. The base styles are simple and fast for phones, and larger screens get enhancements on top.
In CSS
.cards { display: grid; gap: 1rem; } /* phone: one column */
@media (min-width: 48em) { .cards { grid-template-columns: 1fr 1fr; } }
@media (min-width: 64em) { .cards { grid-template-columns: repeat(3, 1fr); } }
Compare desktop-first, which starts with complex layouts and then undoes them with max-width queries, overriding many declarations along the way.
Why it works well
- Performance: phones, often on slower networks, load the least CSS complexity, and you think early about image sizes and payload.
- Focus: a small screen forces you to prioritize the most important content and actions.
- Simpler CSS: adding columns is easier than removing them; fewer overrides.
- Mobile traffic: most web traffic is mobile, and Google uses mobile-first indexing, crawling the mobile version of your pages.
Mobile-first checklist
<meta name="viewport" content="width=device-width, initial-scale=1">- Touch targets at least 24×24px (44×44px recommended).
- Readable base font size (16px) and fluid type with
clamp(). - No hover-only interactions; check
(hover: hover). - Responsive images with
srcsetandsizes.
Interview tip
Mention that mobile-first is about content priority and progressive enhancement, not just the direction of your media queries.
Code example
html
1<!doctype html>2<html lang="en">3<head>4 <meta name="viewport" content="width=device-width, initial-scale=1">5 <style>6 /* Base = mobile */7 body { font: 1rem/1.5 system-ui; margin: 0; }8 header { padding: 12px; background: #0b1020; color: white; }9 nav { display: none; } /* hidden behind a menu on phones */10 .menu-btn { min-height: 44px; min-width: 44px; } /* touch friendly */11 main { padding: 12px; display: grid; gap: 12px; }12 article { border: 2px solid #0b1020; border-radius: 8px; padding: 12px; }1314 /* Enhance for larger screens */15 @media (min-width: 48em) {16 header { display: flex; justify-content: space-between; align-items: center; }17 nav { display: flex; gap: 16px; }18 .menu-btn { display: none; }19 main { grid-template-columns: 2fr 1fr; padding: 24px; }20 }21 </style>22</head>23<body>24 <header><strong>Shop</strong><button class="menu-btn" aria-label="Menu">☰</button>25 <nav><a href="#" style="color:white">Men</a><a href="#" style="color:white">Women</a></nav></header>26 <main><article>Main content first</article><article>Sidebar later</article></main>27</body>28</html>
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.