If you’re seeing this, the site behind it is likely broken!

Hi, there. I use these course sites as little sandboxes to experiment with and learn various “brand new” CSS properties—and your browser does not support (at least) one of them. Apologies. It “should” always work in current/updating Safari and Chrome!

  • Typography & Interaction

    ’25–26

  • The Syllabus

  • Our Class

  • Unit Nº 1: “Type and the Web”

    Wks. 1–6

    • Week Nº 1

      Aug. 29

    • Everything Is a “Web Page”

    • Week Nº 2

      Sep. 5

    • It’s All About Type

    • Week Nº 3

      Sep. 12

    • An Intro to HTML

    • Week Nº 4

      Sep. 19

    • An Intro to CSS

    • Week Nº 5

      Sep. 26

    • The Box Model

    • Project Nº 1: “Manuscript”

      Oct. 3

    • Week Nº 6

      Oct. 3

  • Unit Nº 2: “There Is No Perfect Layout”

    Wks. 7–10

    • Week Nº 7

      Oct. 10

    • Responsive Design

    • What’s all this about Responsive Design?

      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).

      • 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.

      • Using CSS Custom Properties – MDN
        Sorry, last one! For now.

      Instead of building, designing, and serving a desktop site and a separate, minimal mobile version (if you even did at all)⁠—you could instead adapt one site to work across devices. This is responsive design.

      There was a confluence of events that allowed this: modern, self-updating browsers, and then the explosion of the mobile web⁠—precipitated, in no small part, by the iPhone in 2007. It 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.

      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.

      Bruce Lee, 1971

      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.

      Josh Clark, 2012

      The Viewport

      There wasn’t much of a mobile web, prior to the iPhone. Some sites had barebones WAP mobile versions, designed for the tiny screens and limited hardware of the era.

      This is how the Times looked on your Razr.
      This is how the Times looked on your Razr.

      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.

      The iPhone’s introduction is worth a watch. Safari!
      The iPhone’s introduction is worth a watch. Safari!

      Websites at the time were often designed to a standard width (usually 960px), which the phone shrank down to its 320px screen⁠—and then the user could zoom in or out, scrolling around to view the whole page. It somewhat worked⁠—and all the content was there, unlike most mobile sites⁠—but it was less than ideal.

      Their full desktop site scaled down, on an iPhone. Simpler times, those.
      Their full desktop site scaled down, on an iPhone. Simpler times, those.

      Viewport <meta> Tag

      You’ll see this meta element in the head of most websites, now:

      						<meta name="viewport" content="width=device-width, initial-scale=1">
      
      			
      	

      This meta element tells the browser not to do this scaling. It says, “I have a responsive design! Render me at my actual size. My content can reflow.”

      The width=device-width tells the browser to use whatever the screen’s actual pixel dimension is, and the initial-scale=1 sets the starting zoom for the page to 100%. This is how the browser knows how to make the page respond, and how our CSS rules know what width to use.

      We call the portion of the page visible at one time the viewport.

      The Times wasn’t fully responsive until 2018! They still maintained a separate mobile site and apps.
      The Times wasn’t fully responsive until 2018! They still maintained a separate mobile site and apps.

      Media Queries

      Responsive design could only really flourish when CSS (and browsers) added the @media at-rule around the same time.

      These are colloquially called media queries, and they allow us to check if 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, for the first time.

      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.

      These blocks are 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 some-criteria-or-rule {
      	/* CSS that only applies if a test passes. */
      }
      
      			
      	

      Width-Based Breakpoints

      There are many media queries we can use, but we’ll start with width⁠—which is by far the most commonly-used and really the core of responsive design. Usually when folks are talking about a page or site being responsive, they mean with regards to its width.

      Width tends to vary the most across devices⁠—from the 375px–428px of your phones, through to the ~1440px–1680px of your laptops, and then on up to the ~2560px–3440px you might see with large, desktop displays.

      This is from more than a dozen years ago, now. It’s really only gotten worse!
      This is from more than a dozen years ago, now. It’s really only gotten worse!

      Physical directions remain in use

      Note that we still use width here⁠—not the logical property inline-size⁠—because we are referencing the physical device characteristics, agnostic of the language being displayed.

      Management will accept px in queries

      We’ve changed our mind on this, since we went through initially: while em/​rem are technically correct for media queries, we’ve decided the tooling around this is unclear.

      We will now allow px, for ease of understanding.

      Since this width is usually our primary design constraint (height being handled through scrolling), we need width-based media queries to adjust our layouts across this wide range, lest our designs fall.

      This is done in steps, at different widths, that we call breakpoints⁠—the window/​device/​viewport sizes where the content starts to break, if it is not adjusted.

      If you think responsive’s simple, I feel bad for you son. We got 99 viewports, but the iPhone’s just one.

      Josh Brewer, 2012

      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!

      In this example, we would refer to 35rem 550px as our breakpoint:

      Drag the code/​example divide to the left to see it respond to the media query! You can double-click to reset it.

      This width rule/​test/​criteria uses math comparison operators⁠—meaning you can use < > = <= >= :

      Again, drag the divide to see rules apply. Exact matches (like the width = 550px here) are rarely useful!

      Use modern syntax when possible

      You’ll see lots of material out there referencing min-width or max-width media queries⁠—but we will be using the modern (and much more intuitive) range operator syntax shown here.

      Height-Based, Too

      You can also use height in the same way⁠—though again, with the usual vertical scrolling paradigm, height-based adjustments aren’t as necessary or anywhere nearly as common as width.

      This example is the same breakpoint of 550px as before, but now using height:

      These code examples are responsive, themselves⁠—stacking like this when they are narrow.

      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.

      Orientation

      You can also be less specific about your width/​height and instead use orientation⁠—like when you rotate your phone. The queries use the wonderfully tenacious names/​values of portrait or landscape:

      Everything was a painting before it was a photograph or a web page.

      And/​Or Combinations

      And speaking of conditional statements⁠—you can also merge multiple media queries into one test/​check, using and. This is often used for a range (to apply something between two breakpoints) or to combine width and height checks, together:

      The demo here is taller than 300px, for the second one.

      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 with and, as in the example above, by just swapping the colors. Code logic!

      There is also a not logic operator⁠—which will reverse the meaning of the media query. But this syntax gets confusing fast⁠—especially with things like >/​< rules making for double-negatives. So it is easier to avoid!

      Why say not portrait when you can just say landscape?

      Mobile-First Design

      So this can all get very complicated, very quickly⁠—especially with complex designs, overlapping rules, and the wide ranges of devices to consider.

      • Mobile First – A Book Apart
        Luke Wroblewski wrote the book (and the deck).

      • Progressive Enhancement – Wikipedia
        The term coined by Steve Champeon and Nick Finck in 2003.

      One of the easiest methodologies to keep things understandable is practicing mobile-first design (and development). This has become kind of buzzwordy in the past decade or so, but it is a good philosophy to adhere to, nonetheless. It jives with the concept of progressive enhancement.

      Your 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.”

      • In Code:

        Similarly, this means writing your styles for mobile… first, then adding width > # breakpoints (cascading below them) to progressively enhance your design as it scales up.

      Note we added a main container. The inline-size here are kind of tricky⁠—but this will be much easier with grid, we promise!

      This goes “with the grain,” following the general CSS pattern/​paradigm of the cascade⁠—and is much, much, much easier than adjusting desktop front-end after the fact. (Trust us.) Always think mobile-first !

      Mobile can be the majority of your traffic⁠—especially internationally! We’d like you to think of mobile-first design as a form of accessibility, in this light. Not everyone has your MacBook Pro.

      Briefly, CSS Variables

      Custom properties (folks almost always say CSS variables) aren’t strictly a part of responsive design or media queries, per se⁠—but they come up very often in modern, mobile-first practice and we’ll introduce them briefly, here. They allow you codify the relationships in your design.

      CSS Custom Properties Guide – CSS Tricks
      Web guru Chris Coyier’s robust overview.

      These bring another programming concept of variables into CSS. These are shorthand entities for values we want to reuse throughout a document⁠—or, in a responsive context, want to modify at certain breakpoints.

      Changing the value of a variable changes it everywhere it is referenced⁠—no copy/​pasting or find/​replacing. You could think of a color swatch, if you are in an Adobe mindset; other tech folks call these tokens. Again, these are just for you⁠—it is all the same to the computer. More ergonomics!

      In your CSS, you declare (set) these with a -- prefix in front of a subjective name you make up. And you reference (use) them by wrapping that variable name in var().

      						:root {
      	--brand-color: #e42a1d; /* Declare it. */
      }
      
      .brand-color {
      	color: var(--brand-color); /* Reference it. */
      }
      
      			
      	

      You can use these as values for any CSS property⁠—colors, spacing, etc.⁠—anything you use multiple times and want to be consistent, give a memorable name to, or easily change all together:

      Changing the spacing here is easy, even though we use it a bunch.

      You’ll often declare a set of variables for mobile⁠—type sizes, spacing, and so on⁠—and then adjust them, once, for desktop. No need to write all the properties out again, with all their own redundant media-queries! Variables are great. It used to be so much harder.

      They’ll help you avoid unwanted cascade (applying the same property), especially across breakpoints. But they also help to facilitate design system thinking⁠—focusing your design on the relative relationships of things.

      Variables are how you build design systems. Like relative type scaling, they help to identify, catalyze, and maintain relationships in your work.

      Other Media Features

      By far, the most common media queries will be width/​height/​orientation⁠—for adjusting your layouts across devices. But @media has some more tricks up its sleeve in testing for other browser features. We’ll look at some of the handy/​common ones.

      @media types/​features - MDN
      There are many of these! Meet your users where they are.

      screen vs. print

      In all of our above examples, there is an implied media type of screen⁠—since that is usually what we are concerned with, on the web. But there is also one for print ! You can use these to segment styles to one medium or the other:

      CSS paged media - MDN
      There are also some print-specific properties available.

      You can see the print style in action by going directly to the example, then ⌘ P to print. It is still A Thing, though often forgotten about in modern web design/​projects.

      Remember: Everything is a webpage

      Increasingly, this is how many “print” documents are created⁠—starting as webpages with print styles. When you get a PDF ticket/​receipt or even read a book, it’s likely styled HTML! Your Kindle’s EPUB files are just HTML/​CSS, too!

      hover

      Another common feature is hover, used to detect whether a browser has an input device that supports hovering⁠—which really just means a mouse, usually on laptop/​desktop computers.

      hover - MDN
      Mobile devices don’t have this!

      Mobile touch-based systems don’t have this behavior (and often react oddly to :hover CSS, “eating taps”), so you should adjust your interfaces to work in the absence of this state:

      If you view this on your phone, the aside should be visible without interaction. On your computer, you’ll have to mouse over the div. 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

      You see this one more and more these days⁠—prefers-color-scheme for switching up a site’s styles based on whether the user is in light or dark mode, popularized by the ol’ iPhone again:

      prefers-color-scheme - MDN
      Michael prefers dark; Rijk prefers light.

      You’ll see this differently depending on whether your system is in light or dark mode.

      Sometimes this feels appropriate⁠—especially in products/​applications, like maybe a messaging service. But sometimes the color scheme of a site is its brand (like ours), and probably shouldn’t change based on this query. It’s up to you! Continuing our ongoing discussion of who has the control.

      prefers-contrast /​ prefers-reduced-motion

      These last two are primarily concerned with accessiblity⁠—prefers-contrast for folks who run their device/​browser in a high-contrast mode to help with their vision, or prefers-reduced-motion for those who have animations turned off for vestibular reasons.

      • prefers-contrast - MDN
      • prefers-reduced-motion - MDN
        You can think of both subtlety and motion as progressive enhancements.

      Or these are just their preference! None of your business.

      						: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 i⁠OS.
      The corresponding settings in i⁠OS.
      						/* When “Reduce Motion” is *not* enabled. */
      @media (prefers-reduced-motion: no-preference) {
      	button {
      		animation: some-slick-animation;
      	}
      }
      
      			
      	
      undefined

      The power of the Web is in its universality.

      Access by everyone regardless of disability is an essential aspect.

      Tim Berners-Lee, 1997

    • DevTools (Web Inspector)

    • Week Nº 8

      Oct. 17

    • Finally, Flexbox

    • And (CSS) Grid

    • Week Nº 9

      Oct. 24

    • Some Additional, Advanced CSS

    • Project Nº 2: “Spread”

      Oct. 31

    • Week Nº 10

      Oct. 31

  • Unit Nº 3: “Typography as Interface”

    Wks. 11–15

    • Week Nº 11

      Nov. 7

    • Working with Images

    • Week Nº 12

      Nov. 14

    • Week Nº 13

      Nov. 21

    • Thanksgiving Week

    • Project Nº 3: “Binding”

      Dec. 5

    • Week Nº 14

      Dec. 5

    • Week Nº 15

      Dec. 12

  • Winter Break

  • Unit Nº 4: “Interface as Interface”

    Wks. 16–21

    • Week Nº 16

      Jan. 21

    • Week Nº 17

      Jan. 28

    • An Intro to JavaScript

    • Week Nº 18

      Feb. 4

    • Some More JavaScript

    • Week Nº 19

      Feb. 11

    • Week Nº 20

      Feb. 18

    • Project Nº 4: “Links”

      Feb. 25

    • Week Nº 21

      Feb. 25

  • Unit Nº 5: “If All You Have Is a Hammer, Everything Looks like a Nail”

    Wks. 22–30

    • Week Nº 22

      Mar. 4

    • Putting a (Link/​Meta) Bow on It

    • Week Nº 23

      Mar. 11

    • Spring Break

    • Week Nº 24

      Mar. 25

    • Week Nº 25

      Apr. 1

    • Week Nº 26

      Apr. 8

    • Week Nº 27

      Apr. 15

    • Project Nº 5: “Functions”

      Apr. 22

    • Week Nº 28

      Apr. 22

    • Week Nº 29

      Apr. 29

    • Week Nº 30

      May 6

    • “Everything Else”

    • The end