Why Do We Care?#
Underneath the “buzzwords” of responsive design (or something being fully responsive)—what might this concept have to offer us, as designers?
Why should a designer care about “responsive design”?
-
It’s underlying premise of progressive enhancement (or mobile-first, below) will help us organize our design process.
-
It makes us unpack the reasoning and rationale for our design decisions—in order for them to work in many different scenarios.
-
Starting with the tightest/hardest constraints, first, makes later decisions much easier.
-
It’s a form of accessibility—meeting our audience where they are, on whatever device they have.
-
There are so many different devices out there! And it’s always changing.
-
It sure beats designing (and building) separate things!
What’s all this about Responsive Design?#
Instead of designing, implementing, and serving separate sites for different devices and specific scenarios—we can adapt just one to work across them all. This is responsive design.
-
Responsive Design – MDN
A pretty nice overview. -
Beginner’s Guide to Media Queries – MDN
Slightly overlapping, but also good. -
Using Media Queries – MDN
Okay, that’s probably enough MDN.
This term was coined in 2010 or so by Ethan Marcotte—wrapping a name around a progressive enhancement and mobile-first web design approach/philosophy that had been growing in the mid-2000s (sometimes called liquid, flexible, fluid, or elastic design).
There was a confluence of events that allowed this: modern,
The iPhone was the first mobile device that ran a desktop-class browser (in terms of functionality), which hadn’t been available in a small screen before. And with its crazy success—and the subsequent proliferation of its paradigm in Android—the web, and then world, scrambled to respond.
You’ve probably noticed this kind of pattern:
A typical/example responsive layout, adjusting the content to reflow based on the device width.
Empty your mind. Be formless, shapeless, like water.
You put water into a cup, it becomes the cup. You put water into a bottle, it becomes the bottle. You put it into a teapot, it becomes the teapot.
Now water can flow or it can crash. Be water, my friend.
Content is like water.
Content’s going to take many forms, flow into many different containers, many of which we haven’t even imagined yet. Build from content out, not container in.
The Viewport#
There wasn’t much of a mobile web, prior to the iPhone. Some sites had bare-bones WAP mobile versions, designed for the tiny screens and limited hardware of the era.


The iPhone’s introduction is worth a watch. Safari! ↗
When the iPhone came on the scene, most desktop websites still didn’t have narrow/smaller (let alone flexible) layouts—so the phone would instead scale or zoom out a desktop site design down to fit.
Websites at the time were often designed to a standard width (usually 960px )320px

Their full desktop site back then, scaled down, on an iPhone. ↗
Viewport <meta> Tag#
<meta>So the web had to evolve for this new class of devices.
You’ll see this <meta><head>
-
Viewport concepts – MDN
Usually “the browser window.” -
value – MDNviewport
How the page should be sized!
<meta name="viewport" content="width=device-width, initial-scale=1">
You’re saying “this page has a responsive design! Render it at its actual size. The content can reflow.”
The width=device-widthinitial-scale=1width

The Times wasn’t fully responsive until 2018! They still maintained a separate mobile site and apps. ↗
We call the portion of the page visible at one time the viewport.
Media Queries#
Responsive design could really only flourish when CSS (and browsers) added the @media
CSS media queries – MDN
Checking for viewport values.
These are colloquially called media queries, and they allow us to check if our reader’s screen is a certain width or resolution (or other features, which we’ll get to)—and then apply selective CSS only in that scenario/situation. These let site layouts respond intentionally to different devices.
Practically, these are blocks of CSS—a little bit like selectors that contain other selectors—but which only apply conditionally when the test/criteria is met.
Like any other CSS—if there are multiple conditions that are met, or there is a tie between properties—the rules cascade down and the lowest/last one takes precedent.
/* Our CSS has all been out here! */
@media (feature = value) {
/* CSS that only applies when true. */
}
In a broader code and programming context, it can be helpful to think of media queries as conditional if statements.
We’ll talk about this in detail later with JavaScript, where conditionals are ubiquitous and powerful! You may have also heard of If This Then That, which takes its name from this kind of logic.
Width-Based Breakpoints#
There are many media queries we can use, but we’ll start with width —width .
width
The most common, by far.
Our design responds in steps, at different width ,
There Is No Perfect Layout#
The horizontal axis tends to vary the most across devices—from the 375px –428px1440px –1680px2560px –3440px
Since this widthheight
You might add a breakpoint because lines of text get too short or too long, becoming hard to read. It might be to prevent a grid of images from becoming too small on a phone—while you can have many columns on desktop, often you can only have one (or two) on mobile.
You can add as many breakpoints as you need to make your page/design work across devices. Don’t think of these as written for specific devices; write for your design and for your content!
There are very, very few layouts that won’t need some amount of horizontal responsiveness/breakpoints!
If you think responsive’s simple, I feel bad for you son. We got 99 viewports, but the iPhone’s just one.
Changing Properties#
In their simplest form, we just change whatever properties/values when they need adjustment! In this example, we would refer to the viewport (width > 500px)
Our examples now all include the viewport <meta>@media
Adjusting Variables#
Thinking more systematically, we can instead adjust the --variables
Again, drag the divider to see rules apply. Same result as before! Try removing the first --background
Nesting Queries#
We can also combine these with the pattern nesting to make our rules and their code self-contained, and less redundant:
Nesting at-rules – MDN
Don’t repeat yourself!
You can nest queries for your “global” :root
Using Comparisons#
Our queries can also use other simple math comparison operators: <>=<=>= .min-width
Query Range Syntax - CSS Tricks
More modern, more intuitive.
Exact matches (like the width = 500px
And Ranges#
This new comparison syntax also allows simple, combined ranges to be specified—to see if the viewport is between two lengths:
New syntax for range media queries - web.dev
Comparison of old vs. new syntax.
Be mindful about “painting yourself into corners” with these! They make it easier to have unconsidered (or worse, overlapping) scenarios.
Height-Based, Too#
You can also use the viewport’s other axis heightwidth .
height
Less common, but still useful.
This example has the same breakpoint of 500pxheight :
These code examples are responsive, themselves—stacking like this when they are narrow.
Also, Orientation#
Sometimes you can benefit from being less-specific about your width /heightorientation —portraitlandscape :
orientation
Often more useful than width
Note the : ,= .
Combinations#
And#
Speaking of conditional statements—you can also merge multiple media queries into one test, using andwidthheight /orientation :
Logic in CSS Media Queries – CSS Tricks
This can all get very complicated!
The demo here is taller than 400px ,
“Or”#
You can also use comma-separated queries (similar to selector lists) to apply or logic—setting the same styles for different scenarios:
Note that you could do this again with a range and swapping the colors. In code, there are often many ways to do achieve the same result!
Not#
There is also a not()> /<
Why confusingly say @media not (width < 500px)@media (width > 500px) ?
Or @media not (orientation: portrait) ,@media (orientation: landscape) ?
Mobile-First Design#
This can all get very complicated, very quickly—especially with complex designs, overlapping rules, and the wide ranges of devices to consider.
Progressive Enhancement#
It will help to organize our thinking in a pattern of progressive enhancement—always starting with basic functionality, then enriching the experience, when possible.
-
Progressive Enhancement – Wikipedia
The term coined by Steve Champeon and Nick Finck in 2003. -
Mobile First – A Book Apart
Luke Wroblewski wrote the book (and the deck).
In terms of making our work responsive, this manifests as mobile-first design (and development)—the easiest methodology to keep things understandable (and resilient). This has become kind of buzzwordy in the past decade or so, but it is a good philosophy to adhere to, nonetheless.
Your mobile design constraints will be tighter and more challenging, by tackling your smallest layout first—but it is almost always easier to scale things up than scale them down. A mobile design can always work as a passable desktop one; the reverse is rarely true.
Another way to think of it: if it doesn’t work on mobile, it doesn’t work!
-
In Design
Mobile-first means considering small screens and then adding complexity, limits, or considerations for larger screens. Start from your “worst-case scenario” and build up your design.
-
In Code
Similarly, this means writing your styles for mobile… first, then adding
breakpoints (cascading below them) to progressively enhance your design as it scales up.width >
Start Small, Start Simple#
This also goes “with the grain” of CSS, following its general pattern/paradigm of the cascade—and likewise jives with our “general to specific” (or “always to sometimes”) approach to organizing our styles.
It is also much, much, much easier than adjusting desktop front-end after the fact. (Trust us.) Always think
Note we added a maincalc()grid ,
Responsive Lengths#
CSS also added some additional functions, beyond just calc()min- /max-margin ,padding ,font-size ,vw /vh .
CSS min() ,max() ,clamp()
For more than just -size !
We can use these to make sure our designs work responsively, even without explicit @media
min() #
min()The min()
min()
Select the smallest value.
Drag that divider! Note that you can do maths right within min() ,calc()max()clamp()
max() #
max()On the other end of things, the max()
max()
Or the largest.
We can also use these functions in variable definitions themselves, like --spacing: max(5vw, 5rem);
clamp() #
clamp()You’ll often want to set both a floor and a ceiling on flexible units, and we can do these together with the clamp()
clamp()
Or within a minimum/maximum.
Best of both worlds! We can scale our designs—but not too small and not too big.
Use these functions to prevent your design from breaking—without having to know or plan for every scenario!
Other Media Features#
By far, the most common media queries will be width/height/orientation—for adjusting your layouts across different devices. But @media
@media
There are many of these! Meet your visitors where they are.
screen vs. print #
screenprintIn all of our above examples, there is an implied media type of screen —print !
CSS paged media - MDN
There are also some print-specific properties available.
You can see the print
hover #
hoverAnother common feature to check for is hover
hover
Mobile devices don’t have this!
Perhaps obviously, mobile touch-based systems don’t have this behavior—and often react oddly to :hover
If you view this on your phone, the asidesection :
Note how this is written with a mobile-first style, only adding the hover state later/lower for folks who have it!
Hover states are a good feature for progressive-enhancement, as we did here—to add them in after you have a working mobile design. Maybe a third to a half of your audience (depending on your project) won’t see them—so don’t rely on them being seen!
prefers-color-scheme #
prefers-color-schemeYou see this one more and more these days—prefers-color-scheme
prefers-color-scheme
Michael prefers dark ;light .
Sometimes this feels appropriate—especially in products/applications, like maybe a messaging service. But other times the color scheme of a site is its brand (like ours), and probably shouldn’t change based on this query. Continuing our ongoing discussion of who has the control—it’s up to you:
You’ll see this differently depending on whether your system is in light or dark mode!
prefers-contrast / prefers-reduced-motion #
prefers-contrastprefers-reduced-motionThese last two are primarily concerned with accessibility—prefers-contrastprefers-reduced-motion
Or these are just their preference! None of your business.
- MDNprefers-contrast - MDNprefers-reduced-motion
You can think of both subtlety and motion as progressive enhancements.
:root {
/* Default to high contrast… */
--background: white;
--foreground: black;
}
p {
background-color: var(--background);
color: var(--foreground);
}
/* When “Increase Contrast” is *not* enabled. */
@media (prefers-contrast: no-preference) {
:root {
/* …use designer/subtle/nuanced colors. */
--background: lightgray;
--foreground: slategray;
}
}

The corresponding settings in iOS.
/* When “Reduce Motion” is *not* enabled. */
@media (prefers-reduced-motion: no-preference) {
button {
animation: some-slick-animation;
}
}

The power of the Web is in its universality.
Access by everyone regardless of disability is an essential aspect.
