<h2><code>grid-auto-flow: row;</code></h2>
<p> The auto-placement algorithm places items by filling each row in turn</p>

<section class="grid">
  <div class="item">item1</div>
  <div class="item">item2</div>  
  <div class="item">item3</div>
  <div class="item">item4</div>  
  <div class="item">item5</div>
  <div class="item">item6</div>
</section>

<h2><code>grid-auto-flow: column;</code></h2>
<p> The auto-placement algorithm places items by filling each column in turn</p>

<section class="grid grid2">
  <div class="item">item1</div>
  <div class="item">item2</div>  
  <div class="item">item3</div>
  <div class="item">item4</div>  
  <div class="item">item5</div>
  <div class="item">item6</div>
</section>
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: 100px 100px;
  grid-gap: 20px;
}

.grid2 {
  grid-auto-flow: column;
}



body {
  padding: 20px;
}

h2 {
  margin-bottom: 1em;
}

External CSS

  1. https://codepen.io/matuzo/pen/vmpaWe.css

External JavaScript

This Pen doesn't use any external JavaScript resources.