Have 30-200 Employees? Make $50k-$500k selling your data for AI Training.

Learn More

A Friendly Introduction to Flexbox for Beginners

Christian Krammer
Christian Krammer
Published in
·Updated:

The AI briefing for Developers

Stay up to date with AI tools, model releases, and developer workflows that matter.

Weekly. Free. One click to leave.

Share this article

A Friendly Introduction to Flexbox for Beginners
SitePoint Premium
Stay Relevant and Grow Your Career in Tech
  • Premium Results
  • Publish articles on SitePoint
  • Daily curated jobs
  • Learning Paths
  • Discounts to dev tools
Start Free Trial

7 Day Free Trial. Cancel Anytime.

Key Takeaways

  • Flexbox is a CSS layout tool ideal for one-dimensional layouts, such as a string of similar items, and can be used as a fallback for Grid layouts in older browsers.
  • Flexbox allows for easy layout adjustments in any direction, visual order rearrangement, responsive size adjustments, and equal-column layouts irrespective of content volume.
  • The ‘flex’ value of the ‘display’ property is the core element of flexbox, turning container elements into flex items, which are placed side by side by default and adapt to the available space.
  • Flexbox properties like ‘order’, ‘align-items’, ‘align-self’, ‘justify-content’, and ‘flex’ offer flexibility in changing the order of elements, aligning items both horizontally and vertically, distributing available space evenly among elements, and controlling the length of elements in relation to others in a flex container.

In recent years, CSS layout has come of age, with dedicated tools for complex layouts replacing the various workarounds of using tables, floating, absolute positioning and so on. Flexbox (or the Flexible Box Layout Module) was the first of these dedicated layout modules, followed by CSS Grid Layout. In this article, we provide a user-friendly introduction to flexbox.

With the introduction of CSS Grid Layouts, you may be asking if flexbox is needed at all. While there is some overlap in what they can do, they each have very specific purposes and roles within CSS layout. As a very general rule, the sweet spot for flexbox is layout in one dimension (say, a string of similar items), while Grid is ideal for layout in two dimensions (such as the elements of a whole page).

That said, flexbox can be used for full-page layouts. Both flexbox and Grid are now supported in all current major browsers (MDN marks both as widely available), so the choice between them is about the shape of your layout, not browser support. They also work well together: use Grid for the overall page and flexbox for the rows and groups of items inside it.

Advantages of Using Flexbox

Some of the advantages of flexbox are:

  • page content can be laid out in any direction (to the left, to the right, downwards or even upwards)
  • bits of content can have their visual order reversed or rearranged
  • items can “flex” their sizes to respond to the available space and can be aligned with respect to their container or each other
  • achieving equal-column layouts (irrespective of the amount of content inside each column) is a breeze.

To illustrate the various properties and possibilities, let’s assume the following simple layout for some of the demos in this article:




header content here




main content here




footer content here


The first step is to place the elements within .main, i.e.,

Christian KrammerChristian Krammer

Christian Krammer has been a web designer for more than a decade and currently earns his keep at a small advertising agency. He is also the proud owner of css3files.com, a comprehensive guide to CSS3. Besides that he is married, the proud father of a six year old boy and a movie lover. His portfolio can be examined at chriskrammer.com.

© 2000 – 2026 SitePoint Pty. Ltd.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.