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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <h1>Common CSS Size Units</h1>

<p>There are many other units of measurement in CSS. Those listed are simply and introduction to some of the most common.</p>

<section>

	<h2>Pixels</h2>

	<p>The <code>px</code> unit is an absolute measurement. It is analogous to Points or Picas in print design.</p>

	<p>A pixel is equal to one dot on the display device. For low resolution devices, this is equal to one literal pixel on the screen. For high resolution devices, such as Retina or 4k displays, a pixel is set so that there are roughly 96 pixels per inch of screen.</p>

	<p>By default, the base size of type in the browser is set to 16px.</p>

	<p>Pixels are good for situations where you want to define an exact dimension and don’t want to scale them.</p>

</section>
	
<section>

	<h2>Rems</h2>

	<p>The <code>rem</code> is a type-relative measurement such that one em is equal to the base type size (the font-size of the <code>html</code> element).</p>

	<p>This means that, by default, <code>1rem</code> is equal to <code>16px</code>. Similarly, <code>2rem</code> equals <code>32px</code>.</p>

	<p>Though rems are defined relative to type, they can be used to size any property.</p>

	<p>Rems are a good option for scalable properties that should be sized relative to other elements and type.</p>

</section>
	
<section>

	<h2>Ems</h2>

	<p>Like rems, the <code>em</code> is a type-relative measurement, but such that one em is equal to the current type size (the type size of whatever HTML element you are targeting).</p>

	<p>This means that, by default, in any base-size <code>html</code> element, <code>1em</code> is equal to <code>16px</code>. Similarly, <code>2em</code> equals <code>32px</code>.</p>

	<p>However, ems are relative to the containing element, so if you set the type size of a <code>ul</code> to <code>.5em</code>, it will equal <code>8px</code>. But if you nest a second <code>ul</code> inside another <code>ul</code>, the type in the nested <code>ul</code> will be <code>.5em</code> of the first one, in other words, <code>4px</code>. If you nested yet another <code>ul</code> inside that one, you would get a type size of <code>2px</code>. This is usually not what you want and can lead to frustration.</p>

	<p><strong>For most purposes, it is best to avoid ems and use rems instead.</strong> They are mentioned here because they were common before rems became available.</p>

</section>
	
<section>

	<h2>Percentages</h2>

	<p><code>%</code> units are relative units based on a 100% scale.</p>

	<p>When used for things like font size, percentages are relative to the containing element type size. So setting a font size of <code>200%</code> of default body type would result in a font size equal to <code>32px</code>.</p>

	<p>When used for length measurements like width or margin, percentages are relative to the containing element. So a <code>div</code> that is a direct child of <code>body</code> with a width set to <code>50%</code> would have a width equal to half of the current width of the browser window.</p>

	<pre class="code-example-good language-css"><code>.example{
	font-size: 90%; /*90% of parent font size*/
	width: 50%; /*50% of parent width*/
}</code></pre>

	<p>Percentage lengths are great for sizes that scale relative to a user’s browser size. They are very useful in fluid / responsive design.</p>

</section>
	
<section>

	<h2>Viewport Units</h2>

	<p>Viewport Units are percentages of the size of the <em>browser window</em>. There are two different viewport unit value types:</p>

	<p><code>vw</code> (View Width): which is relative to the <em>width</em> of the browser window.</p>

	<p><code>vh</code> (View Height): which is relative to the <em>height</em> of the browser window.</p>

	<p>So in the following example:</p>

	<pre class="code-example-good language-css"><code>.example{
	height: 100vh;
	width: 50vw;
}</code></pre>

	<p>The element would be exactly as tall (<code>100%</code>) as the height of the browser window, and <code>50%</code> of the width of the window.</p>
	
</section>
              
            
!

CSS

              
                /* ==========================================================================
   Type
   ========================================================================== */

html {
	line-height: 1.4;
}

h3 {
	margin-top: 3rem;
}

ul{
	padding-left: 1.2rem;
}

li {
	margin-bottom: .5rem;
}

a {
	color: cornflowerblue;
	text-decoration: none;
}

a:hover, a:active, a:focus {
	border-bottom: 1px solid cornflowerblue;
}

.callout {
	font-size: 1.33rem;
}

/* ==========================================================================
   Page Layout
   ========================================================================== */

body {
	margin: 4rem auto;
	max-width: 35rem;
	scroll-behavior: smooth;
}

section {
	border-top: 1px solid #ccc;
	margin-top: 4rem;
	padding-top: 2rem;
}

/* ==========================================================================
   Code Examples
   ========================================================================== */

p > code,
li > code {
	background-color: #f5f2f0;
	color: #905;
	display: inline-block;
	margin: 0 .2rem;
	padding: .15rem .25rem;
}

pre[class*=language-]{
	margin-bottom: 3rem;
}

.bad {
	color: firebrick;
}

.code-example-bad {
	border-left: 3px solid firebrick;
}

.good {
	color: rgb(102, 153, 0);
}

.code-example-good {
	border-left: 3px solid rgb(102, 153, 0);
}

.rendered-example {
  background-color: ghostwhite;
  padding: .75rem;
}

.code-example-good + .rendered-example,
.code-example-good + .rendered-example {
	margin-top: -2rem;
}
              
            
!

JS

              
                
              
            
!
999px

Console