Essential CSS
JavaScript Roadmap
Learn JavaScript
Mastering Web Typography
Practical Astro
Understanding Async JS
Unorthodox Tailwind
API Masterclass
Build and Deploy
The Beginner Freelancer
Real World Node
Profile Billing Logout
Essential CSS
Lesson Plan
  1. Introduction
    1. Welcome to Essential CSS
    2. Getting started with the course
    3. What are file formats?
    4. Web standards
    5. What is HTML?
    6. What is CSS?
    7. Devtools, your indispensable best friend
  2. CSS Key Concepts
    1. Some background about CSS
    2. CSS Syntax and Terminology
    3. Selectors
    4. Cascade and Specificity
    5. Origin and Importance
    6. Inheritance
    7. How browsers handle CSS
  3. Basic Mental Model
    1. Everything on the web is a box
    2. The box model
    3. How big is your box?
    4. The relationship between px and em
    5. The `box-sizing` property
    6. The `display` property
    7. Formatting contexts
    8. Block boxes
    9. Inline boxes
    10. What is inline-block?
  4. Flexbox and Grid
    1. The parent-child relationship
    2. Sizing in Flexbox
    3. Flex directions
    4. Basic grid concepts
    5. Setting up a grid
    6. Placing grid items
    7. Box alignment
  5. Building web layouts
    1. Arranging your boxes on the web
    2. Positioning schemes
    3. Floating boxes
  6. Typography
    1. Making your text look good
    2. What is a font?
    3. Typesetting with CSS

Flex directions

1m:57s

In the previous sections on block boxes and inline boxes, you might have noticed that content flow is closely related to the writing system being used.

For a language like English, text flows from left-to-right, and blocks of text are stacked top-to-bottom. So we say left-to-right is the inline direction, and top-to-bottom is the block direction. But you cannot really change this flow direction easily.

Same issue happens if you are using a language that flows from right-to-left, like Hebrew or Arabic, in that case, making your boxes flow in the opposite direction from left-to-right is very challenging as well. And bottom-to-top is nearly impossible to do.

The flex layout model introduces the concept of flex direction, that makes it possible for your boxes to flow in any of the 4 directions, not just in the directions dictated by the used writing system. This provides a lot more options when it comes to laying out content on your web page.

The terminology for flex directions is illustrated in the diagram below, and they are determined by the writing mode of the element in question.

In the default horizontal, top-to-bottom writing mode, flex items along the main axis flow from left to right and if they wrap, will continue down along the cross axis.

Diagram showing flex directions of 3 row flex line

If the writing-mode is vertical, right-to-left, then the flex items along the main axis flow from top to bottom, and wrap from right to left along the cross axis.

Diagram showing flex directions of 4 column flex line

You can control the direction which the flex items are flowing via the flex-direction property. Its initial value is row. This means flex items flow along the main axis, as seen in the example below.

Screenshot of devtools showing flex direction property

You can change the flex direction by setting the value to column, which changes your flex container’s main axis direction. The flex items now flow from top to bottom instead of left to right.

Screenshot of devtools showing flex direction of column

With the different writing mode directions and the ability to change the flex direction, it is possible to make your content flow in either of the 4 directions when the properties are combined in various ways.