css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <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>
            
          
!
            
              :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;
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console