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

              
                - var dim = 2;
- var nl = 4;

body(style=`--dim: ${dim}; --nl: ${nl}; --c: #ff9800` data-dim=dim)
	form
		div.toggle(role='group' aria-label='Switch between 2D and 3D view for the graphics below.')
			- for(var i = 0; i < 2; i++) {
				input(type='radio' name='dim' id=`dim${i}` value=i + 2 checked= dim === i + 2)
				label(for=`dim${i}` style=`--i: ${i}`) #{i + 2}D
			- }
			div.toggle__vis(aria-hidden='true')

	section.ani(role='graphics-document' aria-label='Shows how backgrounds are layered, animating from 2D to 3D.')
		- for(var i = 0; i < nl; i++)
			.rect.layer.ani(style=`--j: ${i}; background: var(--g${i})`)
	
	pre
		- for(var i = 0; i < nl; i++) {
			span.code.layer.ani(class=`${i > 1 ? 'corner' : 'edges'}` style=`--j: ${i}; --m: var(--m${i > 1 ? 'c' : 'e'})`)
				span.token--func linear-gradient
				span.token--punc (
				span.token--args
					- if(i !== 1) {
						span.token--arg.token--dir
							span.token--ang
								span.token--num #{i > 0 ? 135 : 90}
								span.token--unit deg
						span.token--punc ,
						|  
					- }
					span.token--arg.token--stop
						span.token--col
							span.token--func var
							span.token--punc (
							span.token--args
								span.token--arg.token--prop --c0
							span.token--punc )
						|  
						span.token--pos
							- if(i < 2) {
								span.token--func var
								span.token--punc (
								span.token--args
									span.token--arg.token--prop --b
								span.token--punc )
							- }
							- else {
								span.token--num 50
								span.token--unit %
							- }
					span.token--punc ,
					|  
					- if(i < 2) {
						span.token--arg.token--stop
							span.token--col
								span.token--keyw transparent
							|  
							span.token--pos
								span.token--num 0
						span.token--punc ,
						|  
						span.token--arg.token--stop
							span.token--col
								span.token--keyw transparent
							|  
							span.token--pos
								span.token--func calc
								span.token--punc (
								span.token--args
									span.token--arg.span.token--pos
										span.token--num 100
										span.token--unit %
									|  
									span.token--oper -
									|  
									span.token--arg
										span.token--func var
										span.token--punc (
										span.token--args
											span.token--arg.token--prop --b
										span.token--punc )
								span.token--punc )
						span.token--punc ,
						|  
					- }
					span.token--arg.token--stop
						span.token--col
							span.token--func var
							span.token--punc (
							span.token--args
								span.token--arg.token--prop --c1
							span.token--punc )
						|  
						span.token--pos
							span.token--num 0
				span.token--punc )
				- if(i > 1) {
					-let j = i%2, k = 1 - j;
					|  
					span.token--pos
						span.token--num #{j*100}
						if j
							span.token--unit %
					|  
					span.token--pos
						span.token--num #{k*100}
						if k
							span.token--unit %
					span.token--oper /
					|  
					span.token--dim
						span.token--func var
						span.token--punc (
						span.token--args
							span.token--arg.token--prop --b
						span.token--punc )
					|  
					span.token--dim
						span.token--func var
						span.token--punc (
						span.token--args
							span.token--arg.token--prop --b
						span.token--punc )
					|  
					span.token--keyw no-repeat
				- }
		- }
              
            
!

CSS

              
                $sh: 7px;
$bg: #323232;
$fg: #f7f7f7;
$c-main: #d92727;
$c-sec: #ff6fff;
$lh: 1.5;
$b: 3em;

$pen-b: .125em;
$pen-p: .125em;
$pen-r: .25em;
$pen-g: 1vw;

$btn-d: 1em;

$cell-w: $btn-d + $pen-b + $pen-p;

$form-fs: 1.5rem;
$form-lh: 1;

$rect-lw: 4px;
$rect-o: -.5*$rect-lw;
$rect-min: 4*$b;
$rect-dim: 80%;
$rect-max: 10*$b;

$u: $lh*1em;
$o: 3rem;
$t: 1s;

/* GENERAL STYLES + LAYOUT */
* {
	margin: 0;
	font: inherit
}

body {
	--f3d: calc(var(--dim) - 2);
	--c3d: calc(1 - var(--f3d));
	--me: 1;
	--mc: 1;
	--b: #{$b};
	display: grid;
	grid-template-rows: max-content 1fr max-content;
	overflow: hidden;
	height: 100vh;
	background: $bg;
	color: $fg;
	font: 1.25em/ #{$lh} consolas, monaco, monospace;
	
	@media (max-width: 1175px) {
		--me: 2;
		
		.edges .token--stop:nth-last-child(3):before {
			content: '\A     '
		}
	}
	
	@media (max-width: 985px) {
		--mc: 2;
		
		.corner > .token--punc + .token--pos:before {
			content: '\A   '
		}
	}
	
	@media (max-width: 640px) {
		--me: 3;
		
		.edges .token--stop:nth-last-child(4n - 1):before {
			content: '\A     '
		}
	}
	
	@media (max-width: 585px) { font-size: 1.125em }
	
	@media (max-width: 525px) {
		--mc: 3;
		--me: 4;
		
		.corner .token--stop:nth-last-child(4n - 1):before,
		.edges .token--stop:nth-last-child(2n - 1):before {
			content: '\A     '
		}
		
		.edges .token--stop:nth-last-child(7):before {
			content: ''
		}
	}
	
	@media (max-width: 420px) { font-size: 4.25vw }
}

/* MAIN PAGE COMPONENTS */
form {
	box-shadow: 0 0 $sh #000;
	font-size: 1.5rem;
	line-height: $form-lh;
}

section {
	place-self: center;
	position: relative;
	min-width: $rect-min; min-height: $rect-min;
	width: $rect-dim; height: $rect-dim;
	max-width: $rect-max; max-height: .5*$rect-max;
	transform: translatey(calc(var(--f3d)*(var(--mc) + var(--me))*#{$u}));
}

pre {
	display: flex;
	flex-direction: column-reverse;
	align-items: flex-start;
	box-shadow: 0 0 calc(var(--c3d)*#{$sh}) rgba(#000, var(--c3d));
	transition: box-shadow .5*$t;
	
	[data-dim='2'] & { transition-delay: $t }
}

/* DETAIL COMPONENTS */
.ani {
	transition: transform ease-out $t
}

.layer {
	--dy: calc((.5*(var(--nl) - 1) - var(--j))*(100vh - #{$o})/var(--nl) - 1em);
}

.toggle {
	display: grid;
	place-content: center;
	grid-template: 100% / max-content repeat(2, $cell-w) max-content;
	height: $o;
}

[type='radio'] {
	position: absolute;
	left: -100vw;

	+ label {
		--i: 0;
		--j: calc(1 - var(--i));
		grid-row: 1;
		grid-column: calc(2*var(--i) + 1)/ span 2;
		place-self: center;
		position: relative;
		z-index: 1;
		padding: 0 $pen-r;
		margin: 0 calc(var(--j)*(#{$cell-w} + #{$pen-g})) 
			0 calc(var(--i)*(#{$cell-w} + #{$pen-g}));
		width: max-content;
		border-radius: $pen-r;
		white-space: nowrap;
		cursor: pointer;
		transition: $t;
		
		&:before {
			--cover-w: calc(#{$cell-w} + #{$pen-g});
			position: absolute;
			left: calc(var(--j)*100% - var(--i)*var(--cover-w));
			width: var(--cover-w);
			height: 100%;
			content: ''
		}
		
		&:first-of-type { justify-self: end }
	}
	
	~ [aria-hidden='true'] {
		grid-row: 1;
		grid-column: 2/ span 2;
		place-self: center;
		position: relative;
		z-index: 0;
		border: solid $pen-b $fg;
		padding: $pen-p;
		width: 2*$btn-d; height: $btn-d;
		border-radius: $btn-d;
		color: $c-sec;
		transition: color $t;
		
		&:before {
			position: absolute;
			width: $btn-d; height: $btn-d;
			border-radius: 50%;
			transform: translate(calc(var(--f3d)*100%));
			background: currentcolor;
			transition: transform $t;
			content: ''
		}
	}

	&:checked + label {
		color: $c-sec
	}

	&:focus, &:hover {
		+ label {
			background: $c-main;
			color: $fg
		}

		~ div { color: $c-main }
	}
}

.rect {
	position: absolute;
	width: 100%; height: 100%;
	transform-style: preserve-3d;
	transform: 
		translatey(calc(var(--f3d)*var(--dy)))
		perspective(35em) 
		rotatex(calc(var(--f3d)*65deg));
	
	&:before {
		position: absolute;
		top: 100%;
		padding: 0 .25em;
		border-radius: 0 0 5px 5px;
		backface-visibility: hidden;
		transform-origin: 0 0;
		transform: rotateX(calc(var(--f3d)*-65deg + var(--c3d)*-90deg));
		background: mix($fg, $c-sec);
		color: $bg;
		font-size: 1rem;
		counter-increment: j var(--j);
		content: 'layer ' counter(j)
	}
	
	&:after {
		position: absolute;
		top: $rect-o; right: $rect-o; bottom: $rect-o; left: $rect-o;
		border: dotted $rect-lw $fg;
		content: ''
	}
}

.code {
	position: relative;
	padding: 0 1vw;
	transform: 
		translate(
			calc(var(--f3d)*(50vw - 50%)),
			calc(var(--f3d)*(#{.5*$o} - 50vh + 50% + var(--co, 0px) + var(--dy))));
	
	&:nth-child(2) { --co: calc(var(--me)*#{$u}) }

	&:nth-child(3) { --co: calc((2*var(--me))*#{$u}) }

	&:nth-child(4) { --co: calc((var(--mc) + 2*var(--me))*#{$u}) }

	&:before {
		position: absolute;
		z-index: -1;
		top: 0; right: 0; bottom: 0; left: 0;
		opacity: .85;
		background: $bg;
		content: ''
	}
	
	& + &:after { content: ',' }
}

.token {
	&--func { color: #cfa8ff }
	
	&--num { color: #ffdd75 }
	
	&--unit { color: #ffb694 }
	
	&--prop { color: #b0f3f8 }
	
	&--keyw { color: #ff80ae }
}
              
            
!

JS

              
                const OFF = .2, INT = 1 - OFF, 
			S = document.body.style;

let hex_str = S.getPropertyValue('--c').trim(), 
		rgb_arr = hex_str.substr(1).match(/.{2}/gi).map(c => parseInt(c, 16)/255);
		
S.setProperty('--c0', `rgb(${rgb_arr.map(c => Math.round(c*INT*255))})`);
S.setProperty('--c1', `rgb(${rgb_arr.map(c => Math.round((OFF + c*INT)*255))})`);

[...document.querySelectorAll('.code')].forEach((c, i) => S.setProperty(`--g${i}`, c.textContent));

addEventListener('change', e => {
	document.body.style.setProperty('--dim', document.body.dataset.dim = +e.target.value)
}, false);
              
            
!
999px

Console