How to align flexbox columns left and right using CSS ?

The flex columns can be aligned left or right by using the align-content property in the flex container class. The align-content property changes the behavior of the flex-wrap property. It aligns flex lines. It is used to specify the alignment between the lines inside a flexible container.

  • For aligning columns to the left, the align-content property will set to ‘flex-start’.
  • For aligning columns to the right, the align-content property will set to ‘flex-end’.
  • For aligning columns to the extreme ends, the align-content property will set to ‘space-between’.

Example 1: This example display the flex box into the columns.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <style>
        .flex-container {
            display: flex;
            height:400px;
            flex-flow: column wrap;
            background-color: green;
        }
          
        .flex-container > div {
            background-color: #fff;
            width: 100px;
            margin: 10px;
            text-align: center;
            line-height: 75px;
            font-size: 30px;
        }
    </style>
</head>
  
<body>
    <div class="flex-container">
        <div>1</div>
        <div>2</div>
        <div>3</div
        <div>4</div>
        <div>5</div>
        <div>6</div>
        <div>7</div
        <div>8</div
    </div>
</body>
  
</html>

chevron_right


Output:

Example 2: This example align the flex box columns into the left.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <style>
        .flex-container {
            display: flex;
            height:400px;
            flex-flow: column wrap;
            background-color: green;
            align-content: flex-start;
        }
          
        .flex-container > div {
            background-color: #fff;
            width: 100px;
            margin: 10px;
            text-align: center;
            line-height: 75px;
            font-size: 30px;
        }
    </style>
</head>
  
<body>
    <div class="flex-container">
        <div>1</div>
        <div>2</div>
        <div>3</div
        <div>4</div>
        <div>5</div>
        <div>6</div>
        <div>7</div
        <div>8</div
    </div>
</body>
  
</html>

chevron_right


Output:



Example 3: This example align the flex box columns into right.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <style>
        .flex-container {
            display: flex;
            height:400px;
            flex-flow: column wrap;
            background-color: green;
            align-content: flex-end;
        }
          
        .flex-container > div {
            background-color: #fff;
            width: 100px;
            margin: 10px;
            text-align: center;
            line-height: 75px;
            font-size: 30px;
        }
    </style>
</head>
  
<body>
    <div class="flex-container">
        <div>1</div>
        <div>2</div>
        <div>3</div
        <div>4</div>
        <div>5</div>
        <div>6</div>
        <div>7</div
        <div>8</div
    </div>
</body>
  
</html>

chevron_right


Output:

Example 3: This example align the flex box into both end points.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <style>
        .flex-container {
            display: flex;
            height:400px;
            flex-flow: column wrap;
            background-color: green;
            align-content: space-between;
        }
          
        .flex-container > div {
            background-color: #fff;
            width: 100px;
            margin: 10px;
            text-align: center;
            line-height: 75px;
            font-size: 30px;
        }
    </style>
</head>
  
<body>
    <div class="flex-container">
        <div>1</div>
        <div>2</div>
        <div>3</div
        <div>4</div>
        <div>5</div>
        <div>6</div>
        <div>7</div
        <div>8</div
    </div>
</body>
  
</html>

chevron_right


Output:




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.