Sub topic 2
Enhancing Larger Screens with Min-Width Media Queries
Assume you know semantic HTML, basic CSS selectors, the box model, and browser developer tools. This chapter builds on a mobile-first base layout.
Add space only when the content needs it
A mobile-first stylesheet starts with the narrowest useful layout. A min-width media query applies styles when the viewport is at least a specified width. The base rules remain active on smaller screens.
.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);
}
}The page begins as one column, then gains columns as space becomes available. This keeps the small-screen experience simple and avoids overriding a desktop layout with many narrow-screen fixes.
Choose breakpoints from the content
A breakpoint is the width where the layout changes. Do not choose it because a particular phone or tablet has that width. Resize the page until the current layout becomes cramped, then add a breakpoint just before that failure.
Check for:
- Headings that wrap awkwardly.
- Navigation links that no longer fit.
- Cards that become too narrow to read.
- Excessive empty space beside readable content.
This approach continues to work as new devices appear.
> callout tip > Test intermediate widths, not only common device presets. A layout can work at 390px and 1280px but fail at 760px.
Keep text readable
Use a readable base size and line height. clamp() lets a heading grow between a minimum and maximum without a breakpoint.
body {
font-size: 1rem;
line-height: 1.5;
}
h1 {
font-size: clamp(1.75rem, 1.25rem + 2vw, 3rem);
}Keep navigation usable by touch
On small screens, show only essential navigation or use a clearly labelled menu control. Give links enough area to tap and enough space to avoid accidental taps.
.site-nav a {
display: inline-flex;
align-items: center;
min-block-size: 44px;
min-inline-size: 44px;
padding-inline: 1rem;
}Exercise
When should you add a min-width breakpoint?
Show answer
Add it when the current content-driven layout becomes cramped or difficult to read, not when a named device width is reached.