Sub topic 1
Why design for small screens first
Mobile-first design means you build the small-screen experience as the default and add features for larger screens afterward. This chapter explains the model, how it differs from desktop-first work, and where it goes wrong in practice. Later chapters cover the techniques in detail: ranking content, the viewport tag, fluid layouts and min-width queries.
Prerequisites
This chapter assumes you already have the following:
- Basic HTML structure and semantic elements such as
header,nav,mainandsection. - Basic CSS: selectors, the box model and units such as
px,em,remand%. - Some familiarity with your browser's developer tools, at least enough to open the inspector and resize the window.
You do not need to know media queries, Grid or Flexbox yet. The examples here are short and explained as they appear.
What "mobile-first" actually means
Mobile-first is a design order, not a device target. You do two things in sequence:
- Decide what the page must do for someone on a narrow screen, and build that version as the default styles.
- Add rules that apply only when more space is available.
The result still works on desktop. A mobile-first page is not a "mobile site". It is one page whose base styles assume little space and whose extra styles assume more.
Desktop-first reverses the order. You design a rich wide layout, then write rules to remove or rearrange parts when the screen is narrow. The end result can look identical at every width, but the process and the code differ.
Why the order matters
If the end result can look the same, the order seems unimportant. It matters for four reasons.
Constraints force priorities
A phone screen holds roughly one headline, one image and a few lines of text at a time. You cannot fit a sidebar, a promotional banner, a mega-menu and the main content all at once. So you must decide what comes first.
On a wide screen, a team can avoid that decision by placing everything somewhere. Then the page reaches a phone with all the content still marked as important. Starting small makes the ranking happen at the beginning, when it is cheap.
The cascade favours additive CSS
CSS applies base rules to every screen and lets later or more specific rules override them. A small-screen layout is usually the simplest one: elements stack in source order, each taking the full width. Simple styles make a good base, and each media query then adds to them.
Desktop-first works against this. Wide-screen layouts depend on floats, fixed widths, multi-column grids and positioning. Phone overrides have to undo all of that, and each undo rule must match the specificity of the rule it cancels.
Here is the same sidebar layout written both ways:
/* Desktop-first: build the wide layout, then undo it */
.layout {
display: grid;
grid-template-columns: 18rem 1fr;
gap: 1rem;
}
@media (max-width: 40em) {
.layout {
grid-template-columns: 1fr;
}
}/* Mobile-first: stacked by default, add columns when there is room */
.layout {
display: grid;
gap: 1rem;
}
@media (min-width: 40em) {
.layout {
grid-template-columns: 18rem 1fr;
}
}The two blocks produce the same result at each width. In the mobile-first version, the base rule has no layout logic to undo. A browser that fails to parse the media query still shows a usable stacked page.
The default cost lands on the right device
In a desktop-first stylesheet, a phone downloads and parses every rule, including the ones it overrides. The same applies to assets. If the base markup includes a large hero image, a phone fetches it unless you take extra steps.
A mobile-first page puts the light version in the base and loads heavier assets only where they are used. Phones are also the devices most likely to be on slow or metered connections, so the lower default cost helps most there. Later chapters on responsive images and page weight cover this in detail.
Most visits start on a small screen
Many sites receive the majority of their traffic from phones. Check your own analytics rather than assuming a number, because audiences differ by product. A back-office tool used at desks may be mostly desktop. A news site or a restaurant page is usually the opposite. If the largest share of your users arrives on small screens, the small-screen version is the main product, and it should get the first design effort.
Mobile-first versus related ideas
Several terms get mixed up. This table separates them.
| Term | What it describes | Relation to mobile-first |
|---|---|---|
| Responsive design | One page adapts to the available width using flexible layout, flexible images and media queries | Mobile-first is a way of working within responsive design |
| Adaptive design | Separate fixed layouts are chosen for a few set widths | Can be combined, but not the same as fluid, content-led layouts |
| Separate mobile site | A different URL or codebase for phones | The opposite of the approach in this tutorial: two sites to maintain |
| Progressive enhancement | Start with a baseline that works everywhere, then add features where supported | Mobile-first applies the same idea to screen size |
Progressive enhancement is the closest relative. A mobile-first stylesheet is a baseline plus conditional additions, which is the same structure it uses for features.
The first line of the mobile-first approach in code
Browsers on phones have a historical habit. Without instructions, they render the page as if the screen were about 980 CSS pixels wide, then shrink the result to fit. Your small-screen styles would never apply. The viewport meta tag turns this off:
<meta name="viewport" content="width=device-width, initial-scale=1">This tag tells the browser to make the layout viewport as wide as the device. It is the first step in any mobile-first page, and a later chapter covers it fully. For now, remember that without it nothing else in this tutorial works as described.
A small worked example
Here is a mobile-first card list. The base rules give one column, and the queries add columns only when space allows.
.card-list {
display: grid;
gap: 1rem;
padding: 1rem;
}
@media (min-width: 40em) {
.card-list {
grid-template-columns: repeat(2, 1fr);
}
}
@media (min-width: 64em) {
.card-list {
grid-template-columns: repeat(3, 1fr);
}
}Read this as a series of questions the browser asks:
- Always: stack cards in one column with
1remgaps and padding. - If the viewport is at least
40emwide (640px at the default font size): use two columns. - If it is at least
64emwide (1024px at the default): use three columns.
Each query only adds. No rule here resets another rule's work, which keeps the stylesheet short and easy to reason about.
Common errors
These mistakes show up often when teams say they are doing mobile-first.
- Shrinking the desktop design. Designers sketch the desktop page first and then "squeeze" it. The content order, navigation and image choices still reflect the desktop plan. Start with a sketch at about 360px wide, and rank content before you draw anything wide.
- Hiding content with
display: noneon small screens. If something is not needed on a phone, ask whether it is needed at all. Hidden content is usually still downloaded and can still confuse screen reader users. Later chapters on progressive disclosure show better options. - Mixing
max-widthandmin-widthqueries. A stylesheet with both types makes the cascade hard to follow, because the same width can match rules from two directions. Pickmin-widthas the default and keep to it. - Forgetting the viewport tag. The page looks like a tiny desktop site, and your media queries seem to do nothing.
- Testing only at one phone width. Real users have widths from about 320px to well beyond 1400px, and everything between. Resize continuously and watch for the point where the layout breaks.
- Treating the small screen as a lesser version. Mobile-first does not mean mobile-only. Wide screens should get meaningful improvements, such as using spare room for comparison or side-by-side reading, not just larger margins.
Trade-offs and when to bend the rule
Mobile-first is a strong default, not a law. Consider these cases.
- Dense, desktop-centred tools. A spreadsheet-like dashboard or an editor with many panels may be used almost entirely on large screens. Start from the real use case. You may still write mobile-first CSS for the sake of the cascade, but the design priority is the wide layout.
- Retrofitting an existing site. Converting a large desktop-first stylesheet all at once is risky. Migrate by section, starting with the pages that have the most small-screen traffic.
- Content that cannot shrink. Wide data tables and complex diagrams do not collapse into one column well. Plan a specific small-screen treatment, such as a scrollable container, instead of hoping the base layout copes.
What comes next
The remaining chapters follow the order of the build: ranking content, setting the viewport, building the single-column layout, adding min-width queries, choosing breakpoints, and then type, navigation, touch targets, disclosure, images, performance and testing. Each one applies the same idea from this chapter: start with what a small screen needs, and add only when there is room.
Exercise
A teammate's stylesheet has a base layout with float: left; width: 30% on a sidebar, followed by @media (max-width: 40em) { .sidebar { float: none; width: 100%; } }. Rewrite the sidebar rule in the mobile-first style and explain which part of the original code disappears from the base rules.
Show answer
Base rule: .sidebar { width: 100%; } (or no width rule at all, since a block element fills its container). Then add @media (min-width: 40em) { .sidebar { float: left; width: 30%; } }. The float and the 30% width move out of the base rules and into the enhancement, so the max-width override that undid them is no longer needed. Phones get the simple stacked layout by default, and the wider layout applies only when the viewport is at least 40em.
Exercise
Name two reasons why a page that looks identical at every width can still be better built mobile-first than desktop-first.
Show answer
Any two of these: (1) the base CSS is simpler, with no layout rules to undo, so overrides and specificity conflicts are fewer; (2) phones, which are often on slower connections, load only the light default assets and styles instead of the full desktop set; (3) the team had to rank content early, so the small-screen order reflects real priorities; (4) if a media query fails or is unsupported, the user still gets a usable single-column page.