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

              
                
<h2>Here's the default browser styling for an h2</h2>

<p>And here you have a paragraph just after (and adjacent) to that level-2 heading.</p>

<p>Note how (by default) all of these elements have margins both above - and below.</p>

<h2>These styles are a nice default to have, if there's no CSS</h2>

<p>But the logic it takes to space these out is interesting. The margins overlap. That's not how margins normally work. But in this default state, this is how the spacing gets decided so that the various headings and paragraphs achieve a legible amount of spacing.</p>

<p>When two elements are adjacent (next to each other), then the one with the bigger margin takes precedent. It's not that crazy. Just think about it a little. Pretend you were in charge of designing a plan for this. It's a nice default</p>

              
            
!

CSS

              
                
h2 {
	font-size: 2rem;
}

p {
	font-size: 1rem;
	line-height: 1.3;
}

/*
    any paragraph 
    ↓
immediatly preceded by another paragraph... 
↓                                              */
p + p {
	margin-top: 1em;
}

h2 + p {
	margin-top: 1em;
}

p + h2 {
	margin-top: 1em;
}















































/* 

we've faked how this looks just to help you see what's happening behind the scenes by default











































don't think about this - and snoop around ;) 

*/


































































body {
	padding: 20px;
}

* {
	box-sizing: border-box;
}


/* We're just faking it here -- so that you can see what it's all at one time (and the dev tools only let you highlight one at a time) */
h2 {
	position: relative;
	&::before {
		display: block;
		content: '';

		position: absolute;
		top: 0;
		left: 0;

		width: 100%;
		height: 100%;

		background-color: rgb(200 0 0 / 0.2);
/* 		transform: translateY(-30%);
		padding-bottom: 1.5em; */
		border: 1px solid rgb(0 0 0 / 0.2);
	}
}

p {
	position: relative;
	padding-right: 4em;
	&::before {
		display: block;
		content: '';

		position: absolute;
		top: 0;
		left: 0;

		width: 100%;
		height: 100%;

		background-color: rgb(0 200 200 / 0.2);
/* 		transform: translateY( calc( 1em * -1 ) ); */
/* 		padding-bottom: 2em; */
		border: 1px solid rgb(0 0 0 / 0.2);
	}
}

body > * {
/* 	--depth: 15px;
	&:nth-child(2) {
		transform: translateX( calc( var(--depth) * 1 ) );
	}
	&:nth-child(3) {
		transform: translateX( calc( var(--depth) * 2 ) );
	}
	&:nth-child(4) {
		transform: translateX( calc( var(--depth) * 3 ) );
	}
	&:nth-child(5) {
		transform: translateX( calc( var(--depth) * 4 ) );
	}
	&:nth-child(6) {
		transform: translateX( calc( var(--depth) * 5 ) );
	} */
}

hr {
	padding-block: 2em;
	border: 0;
}
              
            
!

JS

              
                
              
            
!
999px

Console