Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <article>
  <h1>CSS Grid Layout</h1>

  <h2>Introducing the <code>fr</code> unit</h2>

  <p>The <code>fr</code> unit stands for "fraction". It is not a length like <code>px</code> or <code>%</code> but is instead considered a "flex" unit. The free space in a container is distributed amongst the <code>fr</code> values.</p>
  
  <hr>

  <section>
    <pre><code>grid-template-columns: 1fr 1fr 1fr 1fr;</code></pre>
    
    <div class="grid one">
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
    </div>
    
    <p>This 800px wide container has four flex units total. Each one gets calculated as:<br><br><strong>flex * total free space / total number of flex units</strong><br>or<br><strong>1fr * 800px / 4 total fr's = 200px per column</strong></p>
    <p>Sounds complicated, but you don't need to think about how values are calculated while you're working with it. Check it out...</p>
  </section>
  
  <hr>

  <section>
    <pre><code>grid-template-columns: 2fr 2fr 3fr 3fr;</code></pre>
    
    <div class="grid two">
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
    </div>
  </section>
  
  <hr>

  <section>
    <pre><code>grid-template-columns: 8fr 2fr 1fr 1fr;</code></pre>
    <div class="grid three">
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
    </div>
    
    <p>Pretty simple so far! Just supply a value for each of your columns. But wait!</p>
  </section>
  
  <hr>

  <section>
    <pre><code>grid-template-columns: 4fr 2fr;</code></pre>
    
    <div class="grid four">
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
    </div>
    
    <p>Things get interesting when you provide a different number of values than the total number of elements. You can imagine the values "repeating" for each of the unspecified columns.</p>
  </section>
  
  <hr>

  <section>
    <pre><code>grid-template-columns: 1fr;</code></pre>
    
    <div class="grid five">
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
    </div>
    
    <p>You can provide only one value if you want.</p>
  </section>

  <hr>
  
  <section>
    <pre><code>grid-template-columns: 400px 1fr 1fr 1fr;</code></pre>
    
    <div class="grid six">
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
    </div>
    
    <p>You can mix units!</p>
  </section>
  
  <hr>

  <section>
    <pre><code>grid-template-columns: 400px 30% 1fr 1fr;</code></pre>
    
    <div class="grid seven">
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
      <div class="column"></div>
    </div>
    
    <p>Whoooa, you can <em>really</em> mix units! 😮 This is crazy useful for making layouts quickly.</p>
  </section>
</article>
              
            
!

CSS

              
                :root {
  background-color: #263238;
  color: #ccc;
  font-family: helvetica, sans-serif;
  font-size: 17px;
  text-align: center;
}

article {
  max-width: 800px;
  margin: 0 auto;
  
  hr {
    border: 1px solid #383c46;
    margin: 30px 0;
  }
  section {
    margin: 60px 0;
  }
}

h1, h2, h3, h4, h5, h6, p {
  font-weight: 300;
  letter-spacing: .5px;
}
h1 {
  margin-top: 50px;
  text-transform: uppercase;
  font-weight: 500;
}
p {
  margin: 30px 0;
}

code {
  background: #354c5a;
  border-radius: 2px;
  padding: 0px 4px;
  font-family: monaco, monospace;
}

pre {
  margin-top: 30px;
  margin-bottom: 30px;
  
  code {
    background: transparent;
    border-radius: initial;
    padding: initial;
  }
}

.grid {
  display: grid;
  width: 100%;
  margin: 30px auto;
  background-color: #ff6d6d;
  border-radius: 3px;

  .column {
    background-color: deepskyblue;
    min-height: 200px;
    margin: 3px;
    border-radius: 3px;
  }
}

.grid.one {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}
.grid.two {
  grid-template-columns: 2fr 2fr 3fr 3fr;
}
.grid.three {
  grid-template-columns: 8fr 2fr 1fr 1fr;
}
.grid.four {
  grid-template-columns: 4fr 2fr;
}
.grid.five {
  grid-template-columns: 1fr;
}
.grid.six {
  grid-template-columns: 400px 1fr 1fr 1fr;
}
.grid.seven {
  grid-template-columns: 400px 30% 1fr 1fr;
}
              
            
!

JS

              
                
              
            
!
999px

Console