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


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


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.


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.


                <h1>The CSS Box Model</h1>
<p>All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout.</p>

<p>The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content. The image below illustrates the box model:</p>

<div class="margin">
<h3 class="title">Margin</h3>
<div class="border box-model">
<h3 class="title">Border</h3>
<div class="padding box-model">
<h3 class="title">Padding</h3>
<div class="content box-model">
<h3 class="title">Content</h3>
</div><!-- end .content -->
</div><!-- end .padding -->
</div><!-- end .border -->
</div><!-- end .margin -->

<p>Explanation of the different parts:</p>
  <strong><li>Content </strong> - The content of the box, where text and images appear</li>
 <strong><li>Padding </strong> - Clears an area around the content. The padding is transparent</li>
   <strong><li>Border </strong> - A border that goes around the padding and content</li>
   <strong><li>Margin </strong> - Clears an area outside the border. The margin is transparent</li>

<p>The box model allows us to add a border around elements, and to define space between elements. </p>

<div class="example1">
      div.example1 {
        width: 300px;
        border: 25px solid green;
        padding: 25px;
        margin: 25px;

<h1>Width and Height of an Element</h1>

<p>In order to set the width and height of an element correctly in all browsers, you need to know how the box model works.</p>

<div class="important">
<p><strong>Important:</strong> When you set the width and height properties of an element with CSS, you just set the width and height of the <strong>content area</strong>. To calculate the full size of an element, you must also add padding, borders and margins.</p>

<p>Assume we want to style a &lt;div&gt; element to have a total width of 350px:</p>

<div class="example2">
      div.example2 {
        width: 320px;
        padding: 10px;
        border: 5px solid gray;
        margin: 0; 

<p>Here is the math:</p>
<div class="math">
    320px (width)
    + 20px (left + right padding)
    + 10px (left + right border)
    + 0px (left + right margin)
    = 350px

<p>The total width of an element should be calculated like this:</p>

<p>Total element width = width + left padding + right padding + left border + right border + left margin + right margin</p>

<p>The total height of an element should be calculated like this:</p>

<p>Total element height = height + top padding + bottom padding + top border + bottom border + top margin + bottom margin</p>

<p><strong>Note for old IE:</strong> Internet Explorer 8 and earlier versions, include padding and border in the width property. To fix this problem, add a &lt;!DOCTYPE html&gt; to the HTML page.</p>


 {background-color: lightgray;
  border: 1px dashed dimgray;
  height: 475px;}

 {background-color: firebrick;
  height: 340px;}

 {background-color: lightsteelblue;
 height: 225px;}

 {background-color: gold ;
  border: 1px dashed dimgray;
  height: 100px;}

 {text-align: center;
  padding-top: 20px;}

 {width: 85%;
  height: 100%;
  margin: 0 auto;}

 {width: 300px;
  border: 25px solid red;
  padding: 25px;
  margin: 25px;}

 {background-color: silver;
  border-left: 5px solid blue;
  padding: 5px;}

 {width: 320px;
  padding: 10px;
  border: 5px solid gray;
  margin: 0;}

 {border-top: 1px solid green;
  border-right: 1px solid green;
  border-bottom: 1px solid green;
  border-left: 1px solid green;}