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

              
                <div class="container">
  <div>
    <h2>Our "Box"</h2>
    <span id="inline-example">This text will be on the same line as our box when you set Display Type to "inline" or "inline-block"</span>
    <div id="box">Some Content</div>
    <hr>
    
    

    <h2>Current values</h2>
    <button onclick="resetAll()">Reset All</button>
    <ul>
        <li>Content Width: 
        <select onchange="onChange(event)" name="width-sel">
          <option value="auto">auto (default)</option>
          <option value="400px">400px</option>
        </select>
      </li>
        <li>Content Height: 
        <select onchange="onChange(event)" name="height-sel">
          <option value="auto">auto (default)</option>
          <option value="200px">200px</option>
        </select>
      </li>
            </li>
     <li>Line Height: 
        <select onchange="onChange(event)" name="line-sel">
          <option value="auto">normal (default)</option>
          <option value="50px">50px</option>
        </select>
      </li>
      <li>Padding: 
        <select onchange="onChange(event)" name="padding-sel">
          <option value="0px">0px</option>
          <option value="20px">20px</option>
        </select>
      </li>
      <li>Border: 
        <select onchange="onChange(event)" name="border-sel">
          <option value="1px solid black">1px solid black</option>
          <option value="none">none (default)</option>
        </select>
      </li>
      <li>Margin: 
        <select onchange="onChange(event)" name="margin-sel">
          <option value="0px">0px</option>
          <option value="10px">10px</option>
        </select>
      </li>
      <li>Box Type: 
        <select onchange="onChange(event)" name="type-sel">
          <option value="content-box">content-box (default for all elements)</option>
          <option value="border-box">border-box</option>
        </select>
      </li>
      <li>Display Type: 
        <select onchange="onChange(event)" name="display-sel">
          <option value="block">block (default for a `p` element)</option>
          <option value="inline">inline</option>
          <option value="inline-block">inline-block</option>
          <option value="none">none</option>
        </select>
      </li>
    </ul>

  </div>

<h2>Box Model Calculation</h2>
    <div id="content-explanation">
      <p>The current box type is set to <strong>content-box</strong>, which means:</p>
      <ul>
        <li>Margin does not affect the box size, just the spacing around the box</li>
        <li>Total height = height + top padding + bottom padding + top border + bottom border</li>
        <li>Total width = width + left padding + right padding + left border + right border</li>
      </ul>
    </div>
    <div id="border-explanation">
      <p>The current box type is set to <strong>border-box</strong>, which means:</p>
      <ul>
        <li>Margin does not affect the box size, just the spacing around the box</li>
        <li>Total height = height</li>
        <li>Total width = width</li>
      </ul>
    </div>
 
</div>

              
            
!

CSS

              
                
#box {
  background-color: orange;
  border: 1px solid black;
}

#border-explanation {
  display: none;
}

hr {
  margin-top: 40px;
}

#inline-example {
  background-color: lightgreen;
  border: 1px solid black;
}
              
            
!

JS

              
                const el = document.querySelector('#box');

function onChange(e) {
  const selectId = e.target.name;
  switch (selectId) {
    case 'padding-sel':
      el.style.padding = e.target.value;
      break;
    case 'width-sel':
      el.style.width = e.target.value;
      break;
    case 'height-sel':
      el.style.height = e.target.value;
      break;
    case 'border-sel':
      el.style.border = e.target.value;
      break;
    case 'margin-sel':
      el.style.margin = e.target.value;
      break;
    case 'type-sel':
      const cb = document.querySelector('#content-explanation');
      const bb = document.querySelector('#border-explanation');
      if (e.target.value === 'content-box') {
        cb.style.display = 'block';
        bb.style.display = 'none';
      } else {
        cb.style.display = 'none';
        bb.style.display = 'block';
      }
      el.style.boxSizing = e.target.value;
      break;
    case 'display-sel':
      el.style.display = e.target.value;
      break;
    case 'line-sel':
      el.style.lineHeight = e.target.value;
      break;
  }
}

function resetAll() {
  const selectEls = document.querySelectorAll('select');
  selectEls.forEach(s => {
    s.selectedIndex = 0;
  });
  
  el.style.width = 'auto';
  el.style.height = 'auto';
  el.style.lineHeight = 'normal';
  el.style.padding = '0px';
  el.style.border = '1px solid black';
  el.style.margin = '0px';
  el.style.boxType = 'content-box';
  el.style.display = 'block';
}
              
            
!
999px

Console