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

    • DevTools (Web Inspector)

    • Week Nº 8

      Oct. 17

    • Finally, Flexbox

    • A Long Time Coming

      Flexbox, short for flexible boxes⁠—which folks will often just shorten all the way to flex⁠—is a later (mid-2010s, slow adoption) addition to CSS.

      • CSS Flexbox Layout Guide – CSS Tricks
        This page is a classic! It probably bought Chris Coyier a house.

      • Basic Concepts of Flexbox – MDN
        Can’t go wrong.

      • Flexbox Froggy
        A little game.

      Flex was created to facilitate and allow CSS layouts that the box model (despite its float and position) either made difficult, brittle, or even impossible. It is a display property. It’s extremely useful and widely-used.

      And let us tell you⁠—being a web designer was a whole lot harder before flex came on the front-end scene. (Hence the “Finally.”) Notice, for instance, that we haven’t talked about any vertical centering at all yet⁠—you don’t want to know! And you don’t have to worry about it. Flex encapsulates a lot of practical, helpful design paradigms in its system.

      Main and Cross Axes

      Flexbox is a one-dimensional layout system⁠—meaning it is (…usually) focused on arranging items either horizontally in rows, or vertically in columns.

      These are called the axes.

      The one running in the direction of your flex items is your main axis; perpendicular to this is your cross axis:

      						.some-container {
      	display: flex;
      	flex-direction: row; /* Default! */
      }
      
      			
      	
      						.some-container {
      	display: flex;
      	flex-direction: column; /* Rotated! */
      }
      
      			
      	

      Start/​End, Justify/​Align

      Flex also lets us position elements along/​within the axes, in both directions⁠—in relation to the start or the end of the direction.

      For the main axis, you justify ; for the cross axis, you align :

      						.some-container {
      	display: flex;
      	flex-direction: row; /* Default! */
      }
      
      			
      	

      For rows (the default): justify moves items inline (left/​right); align moves block (top/​bottom).

      						.some-container {
      	display: flex;
      	flex-direction: column; /* Rotated! */
      }
      
      			
      	

      For columns (rotated): justify moves items block (top/​bottom); align moves inline (left/​right).

      Shorthand

      Like a lot of CSS, flex has shorthand properties.

      But again, we would avoid them⁠—the system can be hard enough to understand. This will be true when we get to grid as well⁠—often being a little bit more verbose in your code will make things easier to understand, especially starting out.

      Container (Parent) Properties

      Unlike most (…all?) of the CSS we’ve been introduced to, flex is applied on a parent element⁠—but actually adjusts the layout of the children. An element with display: flex; is really telling you what its kids are going to be doing.

      There is also display: inline-flex; which behaves the same, but the parent behaves as an inline element while its children are flexing. You don’t see it used very much.

      Design tools offer approximations

      Figma’s auto layout system maps almost directly to flexbox, in defining rows or columns and then distributing items⁠—and is likewise applied on the parent/​container.

      flex-direction

      After specifying an element as flex, we can set its main axis with the flex-direction property. By default (you don’t have to write it), this behaves as flex-direction: row;⁠—so you’ll generally only be adding it when you want something going vertical, with flex-direction: column; :

      flex-direction – MDN
      Always row by default.

      The first list is display: block; by default. Also note that we gave them all a min-block-size, to show start/​end!

      You can also combine these with a -reverse suffix, which visually reorders the items along the main axis, flipping the start and end:

      Keep in mind that all flex reordering is only visual⁠—it obviously can’t change the order in your HTML. This means that keyboard navigation and screen readers still sequence through the items as they are in your code. So for good, logical accessibility, keep in mind the semantic reading order!

      flex-wrap

      Since flexbox is one-dimensional, by default it will try to cram everything into one line⁠—even when there is not enough room! But you can tell it to wrap onto additional lines by adding the flex-wrap: wrap; property/​value (set to nowrap by default):

      flex-wrap – MDN
      The only two-dimensional flex use.

      Without the height restriction, the last one would just grow taller, by default.

      If you want to make a grid, use (CSS) grid

      You can use this to make grids, and it is sometimes sufficient. But but the more recent CSS Grid properties will give you more control! We’ll talk about grid shortly!

      There is also a -reverse suffix when wrapping, which will sequence items from end to start:

      You could do some weird, unique layouts with these⁠—but keep in mind the order is still only visual!

      justify-content

      So most of what we’ve seen here is… somewhat possible using float and position⁠—though not at all easily and only when you know the size/​counts of your content.

      justify-content – MDN
      How should we space items out?

      But the justify-content property is where flexbox starts to allow novel layouts, by dividing up the extra/​available free space between elements⁠—akin to distribute options in Figma/​Adobe applications. justify-content does this on our main axis:

      The start/​end values have some nuance with different writing directions, but this doesn’t come up often.

      When our main axis is vertical, with flex-direction: column; :

      These only works with the block-size to justify within⁠—otherwise the container would cinch up to the content height, as usual.

      align-items

      And then perpendicular to justify along the main axis, flexbox has the align-items property to position elements along the cross axis. It has similar values:

      align-items – MDN
      For the cross/​perpendicular axis.

      And for the vertical:

      align-content

      When we have a flex element with flex-wrap set, we can also position the lines within the parent/​container with the align-content property⁠—akin to justify-content with each line:

      align-content – MDN
      When there is extra room.

      These wouldn’t do anything without the block-size and the flex-wrap.

      align-content can also be used with a vertical/​flex-direction: column; axis, not shown here. This doesn’t often come up, as you have to specify/​know a height to force a column wrap.

      gap /​ row-gap /​ column-gap

      While you could use margin to separate your flex children, it would apply to the items on the outer edges, too. (Hence our many :not(:first-child) selectors for margin in the examples, so far.)

      • gap – MDN
      • row-gap – MDN
      • column-gap – MDN
        These are common with CSS grid!

      Flex added support for intuitive gap properties, which fix this problem⁠—by applying spacing only between children. This is particularly helpful with dynamic, wrapping content and responsive designs⁠—where you won’t always know which element ends or starts a line (to take their margin off):

      Note the last one, gap are really minimums and only apply when there isn’t otherwise space.

      flex and grid share vocabulary

      Note that the justify, align, and gap properties are also shared (in name and behavior) with CSS Grid, up next!

      Item (Child) Properties

      Flexbox is usually applied on the parent/​container. But once you’ve set display: flex; on an element, there are also some individual override properties that can be given to its children, flex items.

      order

      Kind of like the -reverse suffix⁠—you can individually apply the order property to a flex item (child). Items with the same/​tied order (like everything with the default of order: 0; ) will be displayed in their HTML/​source order:

      order – MDN
      Visual/​display only!

      Other order-based selectors (like :first-child) won’t be fooled by this reordering⁠—as you can see, we used them here. They still use the HTML/​DOM order. And again, this change is only visual⁠—so don’t use it when screen reader/​content sequence accessibility is a concern!

      flex-grow /​ flex-shrink

      These properties tell the flex items to… grow or shrink, if necessary⁠—defining the amount of available/​remaining space in the container an element should take up⁠—filling the whole container, like bento boxes.

      • flex-grow – MDN
      • flex-shrink – MDN
        Who takes up the extra space?

      It takes a unitless proportional value, akin to fractions or a factor/​multiplier. If you give one flexed child flex-grow: 1; it will take up all the extra space; another element with flex-grow: 2; would then take twice as much of that space as the first one (the available space with 3 total units):

      And flex-shrink works the same way⁠—defining what proportion an element should shrink when forced to by the flex layout. The most use you’ll see of this is flex-shrink: 0; , which tells all the other items to shrink instead!

      flex-basis

      The flex-basis property is a little like inline-size and block-size⁠—depending on your main axis. It defines what the child item’s content box size should be before any remaining space is distributed.

      flex-basis – MDN
      How much of the space.

      This defaults to auto, which falls back to any specified inline-size or block-size⁠—and if those aren’t present, will just use the size of the content. You specify this flex-basis with length units like % and px :

      You are usually fine just specifying inline-size /​ block-size.

      align-self

      Finally, we have an individual override for an align-items property set on the parent⁠—the align-self property⁠—which adjusts (with the same keywords/​values) the alignment of the specific child item it is applied to:

      align-self – MDN
      Overrides this child! Rebels.

      This is a lot of stuff! Flex can sometimes be tough to wrap one’s head around, but it is so much better than float and inline-size and margin shenanigans.

      Much of what you look at on the web is laid out in flexbox (and its followup which we keep mentioning, CSS Grid).

    • 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