<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>
</section>
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 100px);
  grid-template-rows: repeat(auto-fill, 100px);
  grid-gap: 20px;
  height: 100%;
}

body {
  padding: 20px;
}

html, body {
  height: 100%;
}

External CSS

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

External JavaScript

This Pen doesn't use any external JavaScript resources.