Set how auto-placed items are inserted in the CSS grid

The CSS grid-auto-flow property controls how auto-placed grid items are inserted in the grid container. It determines whether items flow into rows or columns and how they fill available spaces.

Syntax

selector {
    grid-auto-flow: value;
}

Possible Values

Value Description
row Items are placed by filling each row (default)
column Items are placed by filling each column
dense Items fill holes earlier in the grid
row dense Combines row flow with dense packing
column dense Combines column flow with dense packing

Example: Column Flow

The following example demonstrates items flowing into columns −

<!DOCTYPE html>
<html>
<head>
<style>
    .container {
        display: grid;
        grid-auto-columns: 80px;
        grid-auto-flow: column;
        gap: 10px;
        background-color: #f0f0f0;
        padding: 15px;
        width: fit-content;
    }
    .container > div {
        background-color: #4CAF50;
        color: white;
        text-align: center;
        padding: 20px 0;
        font-size: 18px;
        border-radius: 5px;
    }
</style>
</head>
<body>
    <div class="container">
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
        <div>6</div>
    </div>
</body>
</html>
Six green boxes numbered 1-6 arranged horizontally in columns, each 80px wide with 10px gaps between them.

Example: Row Flow (Default)

This example shows the default row flow behavior −

<!DOCTYPE html>
<html>
<head>
<style>
    .container {
        display: grid;
        grid-template-columns: repeat(3, 100px);
        grid-auto-flow: row;
        gap: 10px;
        background-color: #f0f0f0;
        padding: 15px;
        width: fit-content;
    }
    .container > div {
        background-color: #2196F3;
        color: white;
        text-align: center;
        padding: 20px;
        font-size: 18px;
        border-radius: 5px;
    }
</style>
</head>
<body>
    <div class="container">
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
        <div>6</div>
    </div>
</body>
</html>
Six blue boxes arranged in two rows of three columns each, with items flowing from left to right, then to the next row.

Conclusion

The grid-auto-flow property gives you control over how auto-placed items are arranged in your grid. Use column for horizontal flow and row for vertical flow, with optional dense for compact layouts.

Updated on: 2026-03-15T13:17:05+05:30

179 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements