<h2>Implicitly Defined Sizes for Rows and Columns</h2>
  <p>Grid rows and columns can be implicitly defined using the <code>grid-auto-rows</code> and <code>grid-auto-columns</code> properties. The grid below is already defined but the button will toggle auto-sizing via these two properties.</p>
  <div class="btns">
    <button>Toggle Row/Column Size</button>
  <div class="container">
    <div class="item">1</div>
    <div class="item">2</div>
    <div class="item">3</div>
    <div class="item">4</div>
  <div class="dir">
    <label for="ltr">left-to-right <input type="radio" value="ltr" name="direction" id="ltr" checked></label>
    <label for="rtl">right-to-left <input type="radio" value="rtl" name="direction" id="rtl"></label>
* {
  box-sizing: border-box;

body {
  font-family: Arial, sans-serif;
  font-size: 20px;
  padding: 0 20px 30px;
  line-height: 1.4;

main {
  max-width: 800px;
  margin: 0 auto;

h2 {
  text-align: center;

code {
  font-family: Consolas, monospace;
  background: #ccc;
  padding: 1px 3px;

.btns {
  text-align: center;

button {
  margin: 0 auto 1em;

.container {
  border: solid 2px;
  background: #f8ddf0;
  margin-bottom: 1em;
  padding: 4px;
  display: grid;
  grid-template-areas: "head head"
                       "nav  main"
                       "nav  main"
                       "nav  foot";

.gridtemplateareas {
  grid-auto-rows: minmax(auto, 75px);
  grid-auto-columns: minmax(auto, 394px);

.item:nth-child(1) {
  grid-area: head;

.item:nth-child(2) {
  grid-area: main;

.item:nth-child(3) {
  grid-area: nav;

.item:nth-child(4) {
  grid-area: foot;

.ltr {
  direction: ltr;

.rtl {
  direction: rtl;

.dir {
  text-align: center;

label {
  margin-right: 1.3em;
  padding: 8px;

.item {
  background: #c565a8;
  border: solid 2px #305077;
  text-align: center;
  font-size: 2em;
  margin: 4px;
  color: white;
  font-weight: bold;
let container = document.querySelector('.container'),
    dirs = document.querySelector('.dir').querySelectorAll('input');

document.querySelector('button').addEventListener('click', function () {
}, false);

for (i of dirs) {
  (function(i) {
    i.addEventListener('click', function() {
      clearClasses(container, dirs);
    }, false);

function clearClasses (el, cl) {
  for (i of cl) {

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.