What is a Flex Box?

Oscar de la Hera Gomez
A flower that represents Digital Craft with the text "What is a Flex Box?" beneath it.

A flex box, or Flexible Layout, is a World Wide Web Consortium (W3C) specification that describes a box model optimized for user interface design.

In the flex layout model, the children of a flex container can be laid out in any direction, and can “flex” their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent.

An image annotated with the terms used for a flexbox:
<p>main axis/main dimension: The main axis of a flex container is the primary axis along which flex items are laid out. It extends in the main dimension.</p>
<p>main-start/main-end: The flex items are placed within the container starting on the main-start side and going toward the main-end side.</p>
<p>main size/main size property: The width or height of a flex container or flex item, whichever is in the main dimension, is that box’s main size. Its main size property is thus either its width or height property, whichever is in the main dimension. Similarly, its min and max main size properties are its min-width/max-width or min-height/max-height properties, whichever is in the main dimension, and determine its min/max main size.</p>
<p>cross axis/cross dimension: The axis perpendicular to the main axis is called the cross axis. It extends in the cross dimension.</p>
<p>cross-start/cross-end: Flex lines are filled with items and placed into the container starting on the cross-start side of the flex container and going toward the cross-end side.</p>
<p>cross size/cross size property: The width or height of a flex container or flex item, whichever is in the cross dimension, is that box’s cross size. Its cross size property is thus either its width or height property, whichever is in the cross dimension. Similarly, its min and max cross size properties are its min-width/max-width or min-height/max-height properties, whichever is in the cross dimension, and determine its min/max cross size.</p>

An illustration of the various directions and sizing terms as applied to a row flex container. Source: W3C.

Flex layout is superficially similar to block layout. It lacks many of the more complex text- or document-centric properties that can be used in block layout, such as floats and columns. In return it gains simple and powerful tools for distributing space and aligning content in ways that web apps and complex web pages often need.

An image showing the align content and justify content properties of a flex box.

An illustration showing how content can be laid out using the align-content and justify-content css properties.

The contents of a flex container:

  • can be laid out in any flow direction (leftwards, rightwards, downwards, or even upwards!)
  • can have their display order reversed or rearranged at the style layer (i.e., visual order can be independent of source and speech order)
  • can be laid out linearly along a single (main) axis or wrapped into multiple lines along a secondary (cross) axis
  • can “flex” their sizes to respond to the available space
  • can be aligned with respect to their container or each other on the secondary (cross)
  • can be dynamically collapsed or uncollapsed along the main axis while preserving the container’s cross size

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details