Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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

              
                <label id="toggle">
  <input type="checkbox" checked />
  Border Box
</label>

<ul class="legend">
  <li class="content">Content</li>
  <li class="padding">Padding</li>
  <li class="border">Border</li>
  <li class="margin">Margin</li>
</ul>

<div class="container">
  <div class="shelf">
    <div class="box content-box">
      <div class="inner">
        <span class="title">Content-box</span>
        <ul>
            <li>Element Width: 590px (25px + 20px + 500px + 20px + 25px)</li>
            <li>Element Height: 390px (25px + 20px + 300px + 20px + 25px)</li>
            <li>(Default style) The width and height properties are measured including only the content, but not the border, margin, or padding.</li>
            <li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing">MDN Box-sizing</a></li>
        </ul>
      </div>
    </div>
  </div>
</div>

<div class="container">
  <div class="shelf">
    <div class="box border-box">
      <div class="inner">
        <span class="title">Border-box</span>
        <ul>
            <li>Element Width: 500px</li>
            <li>Element Height: 300px</li>
            <li>The width and height properties include the padding and border, but not the margin.</li>
            <li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing">MDN Box-sizing</a></li>
        </ul>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                .box {
    width: 500px;
    height: 300px;

    border-top: 25px solid #9999ff;
    border-right: 25px solid #9999ff;
    border-bottom: 25px solid #9999ff;
    border-left: 25px solid #9999ff;

    padding-top: 20px;
    padding-right: 20px;
    padding-bottom: 20px;
    padding-left: 20px;

    margin: 15px;

    background-color: #99ff99;
}

.content-box{
    box-sizing: content-box;
}

.border-box{
    box-sizing: border-box;
}

.border-box.is-off {
  box-sizing: content-box !important;
}


/* --- Set Up --- */
body {
    font-family: 'Helvetica Neue', Arial, sans-serif
}

li {
    margin-bottom: 5px;
}

.title {
    text-transform: uppercase;
    font-size: 18px;
    font-weight: bold;
    color: #bbb;
    display: block;
    border-bottom: 1px solid #ccc;
    margin-bottom: 10px;
}

.shelf {
  display: inline-block;
  margin-bottom: 10px;
  background-color: #ff9999;
}

.inner {
  height: 100%;
  background-color: #fff;
}

#toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.5rem;
  background-color: #000;
  color: #fff;
}

.legend {
  position: absolute;
  top: 4rem;
  right: 1rem;
  width: 120px;
  list-style-type: none;
}

.legend li {
  margin: 0 0 0.5rem;
  padding: 0.5rem;
  border: 1px solid #f2f2f2;
}

.padding {
  background-color: #99ff99;
}

.border {
  background-color: #9999ff;
}

.margin {
  background-color: #ff9999;
}
              
            
!

JS

              
                $('#toggle').on('click', function() {
  $('.border-box').toggleClass('is-off');
})
              
            
!
999px

Console