Sub topic 1
Why Design for Small Screens First
Prerequisites
Assume you know basic HTML structure, semantic elements, CSS selectors, the box model, and relative units such as rem and %. You should also know how to open browser developer tools.
Start with the smallest screen
Mobile-first design means creating the narrow-screen layout first, then enhancing it for wider screens. Desktop-first design starts with a wide layout and removes or rearranges content for smaller screens.
Starting small exposes difficult decisions early. A narrow screen cannot display every option at once, so the design must focus on the user's main task. Larger screens can then add columns, spacing, and secondary controls without changing the essential structure.
Decide what matters most
Rank content before writing CSS. Ask what a visitor must see or do first, what supports that task, and what can wait.
A product page might rank its content like this:
- Product name, price, and primary action.
- Main product image and essential description.
- Delivery information and reviews.
- Related products and detailed policies.
This ranking guides the document order. Put important content early in the HTML when possible. Use CSS to enhance its presentation rather than hiding essential information on small screens.
Set the viewport
The viewport is the browser area used to display a page. Without the viewport meta tag, some mobile browsers pretend the page is much wider than the device and scale it down.
Place this element inside the document's head:
<meta name="viewport" content="width=device-width, initial-scale=1">width=device-width matches the layout viewport to the device width. initial-scale=1 prevents an initial zoomed-out view.
Build the single-column base
Begin with a simple layout that needs no media query. A media query is a CSS condition that applies rules when the viewport matches a requirement.
.card-list {
display: grid;
gap: 1rem;
padding: 1rem;
}
@media (min-width: 40em) {
.card-list {
grid-template-columns: repeat(2, 1fr);
}
}The base rule gives each card its own row. The min-width query adds a second column only when the content has enough room.
Exercise
Why should the narrow-screen layout be the base rule?
Show answer
It makes content priorities explicit and lets wider layouts add complexity instead of removing essential content.