Skip to content

Media Queries

In Figma you have separate artboards for desktop, tablet, and mobile. You decide which layers are visible, which fonts are larger, which columns collapse. A media query is how you express exactly that logic in CSS — “apply these rules when the screen is this wide”.

@media (max-width: 480px) {
/* rules inside here only apply when the viewport is 480 px wide or narrower */
}
@media (min-width: 480px) {
/* rules inside here only apply when the viewport is 480 px wide or wider */
}

Think of it as an if statement for CSS:

  • max-width = “if the screen is at most this wide, do this” (large → small)
  • min-width = “if the screen is at least this wide, do this” (small → large)

A real example — card that changes layout

Section titled “A real example — card that changes layout”

The preview pane below is your screen. Make your browser window narrower (or view on a phone) and watch the card reflow. Because the preview pane is itself about half the page width on a desktop monitor, the max-width: 420px breakpoint will trigger there — you can see the effect without needing a phone.

At wider widths the image and text sit side by side. When the pane narrows past 420 px, the single @media (max-width: 420px) block kicks in and stacks them vertically. This is exactly what you would show a developer by switching between your mobile and desktop artboards in Figma.

You are not limited to layout. You can change font sizes, hide elements, adjust spacing — anything in CSS can be overridden inside a media query.

h1 {
font-size: 2.5rem; /* default: large screen */
}
@media (max-width: 420px) {
h1 {
font-size: 1.6rem; /* smaller on narrow screens */
}
}
What does `@media (max-width: 480px)` mean?
In the card example, what CSS change triggers on narrow screens?
Why are small breakpoints (around 420 px) recommended for the live preview in this course?