title: Setting minimum and maximum number of columns using CSS Grid
body: <p>I have 10 divs (64px x 64px) that I want to display in 5 columns maximum (for Large and Extra Large viewports) and 3 columns minimum (for small viewports like iPhone 7 etc).</p>
  
  <p>I am trying to do this with CSS Grid but not able to do the minimum columns part (It goes to 2 columns even if there is space to fit 3 cols).</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    background-color: wheat;
  }
  
  .parent {
    display: grid;
    grid-gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(100px, 140px));
    max-width: 800px;
  }
  
  .child {
    height: 64px;
    width: 64px;
    background-color: brown;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
    &lt;div class="parent"&gt;
      &lt;div class="child"&gt;&lt;/div&gt;
      &lt;div class="child"&gt;&lt;/div&gt;
      &lt;div class="child"&gt;&lt;/div&gt;
      &lt;div class="child"&gt;&lt;/div&gt;
      &lt;div class="child"&gt;&lt;/div&gt;
      &lt;div class="child"&gt;&lt;/div&gt;
      &lt;div class="child"&gt;&lt;/div&gt;
      &lt;div class="child"&gt;&lt;/div&gt;
      &lt;div class="child"&gt;&lt;/div&gt;
      &lt;div class="child"&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Max width for the grid container is 800px.</p>
  
  <p>Here is the link for <a href="https://codepen.io/baggasumit/pen/EeGzJY?editors=1100" rel="noreferrer">Codepen</a></p>
  
  <p>Edit: If possible, I want to accomplish this only using CSS Grid i.e. without using Media Queries or Flexbox.</p>