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

              
                <h1>Heading level 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis eum, distinctio vero dignissimos eveniet accusamus, sit accusantium amet at ipsa ab culpa adipisci doloribus possimus officiis ea voluptatem debitis! Repellendus.</p>

<h2>Heading level 2</h2>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis eum, distinctio vero dignissimos eveniet accusamus, sit accusantium amet at ipsa ab culpa adipisci doloribus possimus officiis ea voluptatem debitis! Repellendus.</p>


<h3>Heading level 3</h3>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis eum, distinctio vero dignissimos eveniet accusamus, sit accusantium amet at ipsa ab culpa adipisci doloribus possimus officiis ea voluptatem debitis! Repellendus.</p>


<h4>Heading level 4</h4>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis eum, distinctio vero dignissimos eveniet accusamus, sit accusantium amet at ipsa ab culpa adipisci doloribus possimus officiis ea voluptatem debitis! Repellendus.</p>


<h5>Heading level 5</h5>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis eum, distinctio vero dignissimos eveniet accusamus, sit accusantium amet at ipsa ab culpa adipisci doloribus possimus officiis ea voluptatem debitis! Repellendus.</p>

              
            
!

CSS

              
                // I've seen a few examples recently of CSS variables and I thought 
// I'd do a quick demo of some good and bad ways to use them.


// I'm going to use modular scales as an example.
// I'm going to use a scale 1.2 for smalls screens and 1.33 for large: 

//     1.2           1.33
//  ___________________________
//  |  2.488rem 	|  4.209rem  |
//  |  2.074rem 	|  3.157rem  |
//  |  1.728rem 	|  2.369rem  |
//  |  1.44rem 	  |  1.777rem  |
//  |  1.2rem 	  |  1.333rem  |
//  |  1rem 	    |  1rem      |
//  ---------------------------

// This is a perfect situation to use CSS variables and the way 
// I've seen most people it is something like this:

:root {
	
	// scale for 1.2:
	--ms-small-1: 1em;
	--ms-small-2: 1.2em;
	--ms-small-3: 1.44rem;
	--ms-small-4: 1.728rem;
	--ms-small-5: 2.074rem;
	--ms-small-6: 2.488rem;
	
	// scale for 1.33:
	--ms-large-1: 1rem;     
	--ms-large-2: 1.333rem; 
	--ms-large-3: 1.777rem; 	
	--ms-large-4: 2.369rem; 
	--ms-large-5: 3.157rem;
	--ms-large-6: 4.209rem;
	
}

// It seems like a fairly logical start to define variables for different
// values in the scale. Next I'd expect to see this:

// Small scale:
h1 {
  font-size: var(--ms-small-6);
}
h2 {
  font-size: var(--ms-small-5);
}
h3 {
  font-size: var(--ms-small-4);
}
h4 {
  font-size: var(--ms-small-3);
}
h5 {
  font-size: var(--ms-small-2);
}
h6 {
  font-size: var(--ms-small-1);
}

// And then large scale above 800px

@media screen and (min-width: 800px) {
	h1 {
		font-size: var(--ms-large-6);
	}
	h2 {
		font-size: var(--ms-large-5);
	}
	h3 {
		font-size: var(--ms-large-4);
	}
	h4 {
		font-size: var(--ms-large-3);
	}
	h5 {
		font-size: var(--ms-large-2);
	}
	h6 {
		font-size: var(--ms-large-1);
	}
}

// This is now working pretty good! 
// It might seem like the most logical way to do this because this is
// exactly what I might do with Sass, but this is not taking advantage 
// of how CSS variables work.

// Let's try again, remembering that CSS variables are scoped to the DOM
// therefore subject to inheritance and the cascade. 


:root {
	
	// Rather than changing which variables we use, the value of the 
	// variable itself is going to change. So let's name them accordingly: 
	
	// scale for 1.2:
	--font-size-1: 1em;
	--font-size-2: 1.2em;
	--font-size-3: 1.44rem;
	--font-size-4: 1.728rem;
	--font-size-5: 2.074rem;
	--font-size-6: 2.488rem;

}

@media screen and (min-width: 800px) {
	:root {
			// scale for 1.33:
		--font-size-1: 1rem;     
		--font-size-2: 1.333rem; 
		--font-size-3: 1.777rem; 	
		--font-size-4: 2.369rem; 
		--font-size-5: 3.157rem;
		--font-size-6: 4.209rem;
	}
}

h1 {
	font-size: var(--font-size-6);
}
h2 {
	font-size: var(--font-size-5);
}
h3 {
	font-size: var(--font-size-4);
}
h4 {
	font-size: var(--font-size-3);
}
h5 {
	font-size: var(--font-size-2);
}
h6 {
	font-size: var(--font-size-1);
}

// This is the exact same result!!! 
// The difference is we're taking advantage of how CSS variables work
// so that we can store all of our responsive logic in the variable.
// The code is also far more readable.

// I can imagine most sites that use CSS variables well, will not have any
// media queries other than for changing values in CSS variables.


// In short if a media query swaps variables, there is a good chance
// you're doing it wrong. Change the values of variables not which 
// variables are used. This should also result in more samentic naming 
// conventions.







// Not related to demo

body {
	width: 90%;
	max-width: 700px;
}
              
            
!

JS

              
                
              
            
!
999px

Console