Base CSS
Write the simplest usable layout first.
Mobile-first CSS starts with the smallest practical screen, then enhances the design as more space becomes available.
.cards { display: grid; gap: 1rem; }
@media (min-width: 48rem) {
.cards { grid-template-columns: repeat(3, 1fr); }
}
Responsive mental model
Mobile-first does not mean mobile-only. It means the default CSS should work on a narrow screen before larger layouts are added.
The smallest screen forces decisions. What must be visible first? Which spacing is essential? Which layout can wait until there is enough room?
Professional responsive CSS starts with readable content, usable controls and a single-column structure. Wider screens then receive enhancements with min-width queries.
Write the simplest usable layout first.
Add larger layouts only when space supports them.
Put the most important content first in the source.
Mobile-first avoids writing desktop CSS and then fighting it back down.
Visual model
Start with readable stacked content.
Controls must work before the design becomes fancy.
Add columns when there is room.
Do not hide important information to save space.
Good CSS versus fragile CSS
.cards {
display: grid;
gap: 1rem;
}
@media (min-width: 48rem) {
.cards { grid-template-columns: repeat(3, 1fr); }
}
.cards { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 47.99rem) {
.cards { grid-template-columns: 1fr; }
.card { padding: 12px; }
}
Rules of thumb
Most content reads best on mobile as a clear stack.
Add complexity when the viewport can support it.
A mobile user still needs the same information.
The design should respond to content pressure, not only device names.
Mobile-first works best when HTML order already makes sense.
Do not wait until the end to discover text and buttons do not fit.
Production thinking
Mobile-first CSS keeps layouts honest. If the page works when space is tight, larger screens become an upgrade instead of a rescue mission.
A clean mobile-first source order helps keyboard users, screen readers and zoomed layouts follow the page naturally.
Use mobile-first for most marketing sites, dashboards, articles and learning platforms. It usually leads to smaller, calmer CSS.
Search engines index mobile experiences seriously. A mobile-first page with complete content is a safer foundation than a hidden desktop clone.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If the answer is vague, resize the lab idea mentally and explain what should change.
Senior audit upgrade
Mobile-first is not a slogan. The practical exercise is to start with the simplest narrow layout, then add complexity only when the content can use the space.
Write the one-column, content-first version without a media query.
Add min-width media queries for layout changes when space improves the design.
A good mobile-first refactor usually removes many max-width undo rules.
.cards { display: grid; gap: 1rem; }
@media (min-width: 48rem) {
.cards { grid-template-columns: repeat(3, 1fr); }
}