<div class="container">
  <h2>Flexbox: flex-wrap and flex</h2>
  <ul class="flex">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
  </ul>
</div>

<div class="container">
  <h2>Grid: auto-fit and minmax()</h2>
  <ul class="grid">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
  </ul>
</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  width: 100vw;
  min-height: 100vh;
  font-family: "Exo", Arial, sans-serif;
  background-color: #557;
  color: #fff;
  padding: 1rem;
}

ul {
  list-style: none outside none;
}

h2 {
  margin-bottom: 1rem;
}

li {
  background-color: #09f;
  font-size: clamp(2rem, 2vw + 2rem, 3rem);
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 6px;
  box-shadow: 0 0 1px 2px rgb(0 0 0 / 0.125);
  text-shadow: 1px 1px 0 rgb(0 0 0 / 0.25);
  min-height: 180px;
}

.container + .container {
  margin-top: 2rem;
}

:root {
  --item-size: 400px;
  --gap: 1rem;
}

.flex {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
}

.flex li {
  flex: 1 1 var(--item-size);
}

.grid {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(var(--item-size), 1fr));
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.