Sub topic 6
Setting up mobile, tablet, and desktop frames
This chapter assumes you know the CSS box model, px, rem, and percentage units, and the basics of a frame-based design tool such as Figma. It also assumes you have read the earlier chapters on the viewport and on min-width media queries.
A design frame is a fixed-width canvas in your design tool. Your CSS breakpoints are the widths where the layout changes in code. The two should match, or the designer and the developer will be building different pages.
What the frames are for
A frame shows one state of the layout. You do not draw one frame per device. You draw one frame per layout that your content needs, and you check that the layout still works between those frames.
Most projects start with three frames:
| Frame | Starting width | Matching CSS |
|---|---|---|
| Mobile | 360 px | Base styles, no media query |
| Tablet | 768 px | `@media (min-width: 48em)` |
| Desktop | 1280 px | `@media (min-width: 80em)` |
The tablet and desktop widths in the table are the same values used in the earlier .layout example: 48em is 768 px and 80em is 1280 px at the default 16 px font size.
Frame width and breakpoint are different things
Each frame has a width, and each breakpoint is a threshold. They are related but not equal.
- The mobile frame is a typical small width. The mobile styles apply from 0 up to the tablet breakpoint.
- The tablet frame is drawn at the width where the tablet layout first applies, so it shows the tightest version of that layout.
- The desktop frame is drawn at a common large width, and it usually has a maximum content width, so wider screens get margins instead of stretched content.
Draw the tablet frame at the breakpoint itself. That is the layout most likely to look cramped, so it is the one worth checking.
Set up the frames in the design tool
- Create a page named "Layouts" and add three frames named
Mobile 360,Tablet 768, andDesktop 1280. - Add a layout grid to each frame. Use 4 columns on mobile, 8 on tablet, and 12 on desktop, with a margin and gutter that match the
1rempadding and gap in the CSS. - Put the frames side by side so you can compare how the same content reflows.
- Build one component, such as a card, and place it in all three frames. Use the same component, so a change shows in every frame.
- Write the breakpoint values on the frame names or in a note, so the developer sees them without asking.
Record the three widths as design tokens (named, shared values), for example breakpoint-tablet and breakpoint-desktop. Then the design file and the stylesheet refer to the same names. In CSS, custom properties cannot be used inside a media query condition, so keep the numbers in one documented place and repeat them in the queries.
From frames to code
Here is the layout from the frames written as mobile-first CSS. The base rules are the mobile frame, and each query adds what the larger frame needs.
.layout {
display: grid;
gap: 1rem;
padding: 1rem;
}
/* Tablet 768 and up */
@media (min-width: 48em) {
.layout {
grid-template-columns: 1fr 1fr;
}
}
/* Desktop 1280 and up */
@media (min-width: 80em) {
.layout {
grid-template-columns: 2fr 1fr 1fr;
max-width: 80rem;
margin-inline: auto;
}
}Common errors
- Frames that do not match the code. If the design says 1024 px and the CSS says
48em, the tablet layout will appear at the wrong width. Agree on one set of values. - Designing only at the three widths. The page also has to work at 500 px, 900 px, and every width in between. The frames are checkpoints, not the full set of screens.
- Drawing desktop first. Starting from the largest frame leads to layouts that are hard to squeeze down. Start with the mobile frame.
- Naming frames after devices. A name like "iPhone 15" goes out of date. Name them by width.
Exercise
A designer draws a tablet frame at 834 px, but the CSS uses @media (min-width: 48em). What goes wrong, and how do you fix it?
Show answer
48em is 768 px at the default font size, so the tablet layout begins at 768 px, not 834 px. The frame shows a layout the code produces only from 834 px upward, and it misses the cramped layout between 768 px and 833 px. Fix it by choosing one value. Either redraw the tablet frame at 768 px, or change the breakpoint to match a width chosen from where the content breaks, then update the frame name, the layout grid, and the CSS together.