<h2>Specifying Start and End Positions for Grid Items</h2>
  <p>Use the button to toggle the <code>grid-row-start</code>, <code>grid-row-end</code>, <code>grid-column-start</code>, <code>grid-column-end</code> values for grid items #1 and #11.</p>
  <div class="btns">
    <button>Toggle Start/End Values</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="item">5</div>
    <div class="item">6</div>
    <div class="item">7</div>
    <div class="item">8</div>
    <div class="item">9</div>
    <div class="item">10</div>
    <div class="item">11</div>
    <div class="item">12</div>
    <div class="item">13</div>
    <div class="item">14</div>
    <div class="item">15</div>
    <div class="item">16</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>
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-rows: repeat(4, 1fr);
  grid-template-columns: repeat(4, 1fr);

.gridtemplateareas .item:nth-child(1) {
  grid-row-start: 1;
  grid-row-end: 3;
  grid-column-start: 1;
  grid-column-end: 4;

.gridtemplateareas .item:nth-child(11) {
  grid-column-start: 2;
  grid-column-end: 4;
  grid-row-start: 4;
  grid-row-end: 6;

.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: #fff;
  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.