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

              
                - let lyr_data = { top: 'source', bottom: 'destination' };
- let lyr_ent = Object.entries(lyr_data);
- let lyr_val = Object.values(lyr_data);
- let lyr_n = lyr_ent.length;
- let mod_data = {
- 	hue: [0, 1, 1], 
- 	saturation: [1, 0, 1], 
- 	luminosity: [1, 1, 0], 
- 	color: [0, 0, 1]
- };
- let mod_kys = Object.keys(mod_data);
- let mod_ent = Object.entries(mod_data);
- let mod_n = mod_ent.length;
- let mod = mod_ent[mod_n - 1][0];
- let hsl_data = {
- 	h: { max: 360, val: 'rand', uni: '°' }, 
- 	s: { val: 100, uni: '%' }, 
- 	l: { uni: '%' }
- };
- let hsl_kys = Object.keys(hsl_data);
- let hsl_ent = Object.entries(hsl_data);
- let hsl_n = hsl_ent.length;
- let hsl_str = hsl_kys.map((c, i) => `--${c}: var(--${c}${mod_data[mod][i]})`).join('; ');
- let sub_str = hsl_kys.map((c, i) => `--sub-${c}: '${lyr_val[mod_data[mod][i]].charAt(0)}'`).join('; ');
- let sel_str = hsl_kys.map((c, i) => `--sel-${c}: ${mod_data[mod][i]}`).join('; ');

body.pwrap(style=`--mod: ${mod}; ${sel_str}` data-hsl=hsl_kys.join(' ') data-lyr=lyr_val.map(c => c.charAt(0)).join(' '))
	section.i.pwrap
		- for(let i = 0; i < lyr_n; i++)
			article(style=hsl_kys.map(c => `--${c}: var(--${c}${i})`).join('; '))
				h3 #{lyr_ent[i][0]} layer 
					span (#{lyr_val[i]})
				form
					- for(let j = 0; j < hsl_n; j++) {
						- let c = hsl_ent[j];
						- let m = c[1].max || 100;
						- let v = c[1].val === 'rand' ? Math.round(Math.random()*m) : c[1].val;
						div(role='group' style=`--max: ${m}; --val: var(--${c[0]}); --sel: var(--sel-${c[0]})`)
							label(for=`${c[0]}${i}`) #{c[0]}
								sub #{lyr_val[i].charAt(0)}
							input(id=`${c[0]}${i}` type='range' max=c[1].max value=v)
							output(for=`${c[0]}${i}` data-unit=c[1].uni || '')
					- }
				.box(id=`i${i}`)
	section.o
		article#o0
			h3 CSS blending
			.box
			pre
				span.token--prop mix-blend-mode
				span.token--punc :
				span.token--val.ctrl
					button(aria-haspopup='true' aria-expanded='false' aria-controls='pop')
						output(for=mod_kys.join(' ')).token--keyw #{mod}
					form#pop
						- for(let i = 0; i < mod_n; i++) {
							- let c = mod_ent[i];
							input(type='radio' name='mod' id=`mod${i}` value=c[0] data-v=`${c[1].join(' ')}` checked=c[0] === mod)
							label(for=`mod${i}` style=`--idx: ${i}`) #{c[0]}
						- }
		article#o1(style=`${hsl_str}; ${sub_str}`)
			h3 HSL approximation
			.box
			pre
				span.token--prop background
				span.token--punc :
				span.token--val
					span.token--func hsl
					span.token--punc (
					span.token--args
						- for(let i = 0; i < hsl_n; i++) {
							if i > 0
								span.token--punc ,
							span.token--arg(style=`--sub: var(--sub-${hsl_kys[i]})`) #{hsl_kys[i]}
								sub
						- }
					span.token--punc )
              
            
!

CSS

              
                $u: 1.25;
$r: 5em;
$s: 2*$r;
$g: #000 #1b1d22 #22242a #323741 #484d5a #7b849c #c4c4c4 #fff;
$c: #bf79f0 #fb678c #fb8c6c #eaa753;
$t: .3s;

$label-w: 1.25em;

$value-w: 2.5em;
$value-b: .3em;
$value-r: 5px;
$value-a: 70deg;
$value-e: 5deg;

$thumb-d: 1em;
$thumb-r: .5*$thumb-d;
$thumb-f: .5;
$thumb-l: 3px;

$track-m: .5*$value-w - $thumb-r + .2*$value-b;
$track-w: $s - 2*$track-m;
$track-h: 6px;
$track-r: .5*$track-h;

// wide --wide: 1
$break-0: 2*(2*($s + $label-w + $value-w + $value-b + .5*$track-m) + 3*$track-m) + 3*$track-m;
// narr --wide: 0
$break-1: 2*(2*$s + 3*$track-m) + 3*$track-m;
// wide --wide: 1
$break-2: 2*($s + $label-w + $value-w + $value-b + .5*$track-m + 2*$track-m) + 3*$track-m;
// narr --wide: 0
$break-3: 2*$s + 3*$track-m + 3*$track-m;
// wide --wide: 1
$break-4: $s + $label-w + $value-w + $value-b + .5*$track-m + 4*$track-m;
// narr --wide: 0

@mixin track() {
	border: none;
	width: 100%; height: $track-h;
	border-radius: $track-r;
	background: 
		radial-gradient(circle at var(--pos), 
			transparent calc(#{$thumb-f}*#{$thumb-r} + #{$thumb-l}), 
			nth($g, 5) calc(#{$thumb-f}*#{$thumb-r} + #{$thumb-l} + 1px))
}

@mixin thumb($f: 0) {
	margin-top: calc(#{$f}*(#{$track-r} - #{$thumb-r}));
	border: none;
	width: $thumb-d; height: $thumb-d;
	border-radius: 50%;
	transform: scale(calc(var(--not-hl)*#{$thumb-f} + var(--hl)));
	background: nth($c, 4);
	transition: transform $t;
	cursor: ew-resize
}

* { margin: 0; border: none; padding: 0; background: transparent; color: inherit; font: inherit }

body, section, article, form { display: grid }

body {
	overflow-x: hidden;
	padding: $track-m;
	background: nth($g, 3);
	color: nth($g, 6);
	font: clamp(.625em, 6.25vw, #{$u*1em})/ 1.25 raleway, 
		trebuchet ms, verdana, arial, sans-serif
}

.pwrap {
	grid-gap: $track-m;
	
	> :not(.pwrap) {
		padding: $track-m;
		border-radius: 5px;
		box-shadow: 0 0 1px 1px nth($g, 5);
		background: nth($g, 2)
	}
}

section {
	grid-template-columns: repeat(auto-fit, minmax(calc(#{$s} + #{2*$track-m}), 1fr))
}

article {
	--i: var(--parity, 1);
	--not-i: calc(1 - var(--i));
	grid-gap: $track-m;
	align-content: start;
	
	&:nth-child(odd) { --parity: 0 }
	
	.i & {
		grid-template-columns: repeat(auto-fit, minmax(Max(#{$s}, calc(50% - 2*#{$track-m})), 1fr));
		direction: var(--parity, rtl);
		
		form { grid-gap: .675em }
	}
}

h3, form { direction: ltr }

h3 {
	grid-column: 1/ -1;
	font-weight: 700
}

form, pre { font-family: ubuntu mono, consolas, monaco, monospace }

[role='group'] {
	--j: var(--wide, 1);
	--not-j: calc(1 - var(--j));
	--hl: 0;
	--not-hl: calc(1 - var(--hl));
	--used: calc(1 - Max(calc(var(--sel) - var(--i)), calc(var(--i) - var(--sel))));
	--pos: calc(#{$thumb-r} + var(--val)/var(--max)*(100% - #{$thumb-d}));
	display: grid;
	align-items: center;
	grid-gap: 0 .25*$track-m;
	grid-template-columns: calc(var(--j)*#{$label-w} + var(--not-j)*100%) var(--wide, 1fr #{$value-w + $value-b});
	z-index: var(--hl);
	padding: calc(var(--not-j)*.5*#{$track-m}) $track-m;
	border-radius: 5px;
	box-shadow: 
		0 0 0 calc(var(--used)*1px) nth($c, 1), 
		0 0 0 calc(var(--used)*4px) rgba(nth($c, 1), .35);
	
	* {
		filter: Saturate(var(--hl));
		transition: filter $t
	}
	
	[for] { text-align: center }
	
	label { width: $label-w }
	
	&:focus-within { --hl: 1 }
	
	@media (min-width: $u*$break-1) and (max-width: $u*$break-0), 
				 (min-width: $u*$break-3) and (max-width: $u*$break-2), 
				 (max-width: $u*$break-4) { --wide: 0 }
}

sub { font-size: .675em }

[type='range'] {
	&, &::-webkit-slider-runnable-track, 
	&::-webkit-slider-thumb { -webkit-appearance: none }
	
	grid-column: calc(1 + var(--j));
	min-width: $track-w;
	height: $thumb-d;
	cursor: pointer;
	
	&:focus { outline: none }
	
	&::-webkit-slider-runnable-track { @include track }
  &::-moz-range-track { @include track }
	
	&::-webkit-slider-thumb { @include thumb(1) }
  &::-moz-range-thumb { @include thumb }
	
	+ output {
		--xy: calc(var(--not-j)*50%) calc((2 - var(--j))*50%);
		display: grid;
		grid-column: calc(1 + 2*var(--j));
		position: relative;
		left: calc(var(--not-j)*var(--pos));
		margin-right: calc(var(--j)*#{-$value-b});
		margin-bottom: calc(var(--not-j)*#{-2*$value-b - $u*1em});
		border: solid $value-b transparent;
		width: $value-w;
		transform-origin: var(--xy);
		transform: 
			translate(calc(var(--not-j)*-50%), calc(var(--not-j)*(#{-$thumb-d} - 100% - 1px))) 
			scale(calc(var(--not-j)*var(--hl) + var(--j)));
		color: nth($g, 2);
		transition: transform $t;
		counter-reset: val var(--val);
		
		&::before, &::after { grid-area: 1/ 1 }
		
		&::before {
			margin: -$value-b;
			background: 
				conic-gradient(
						from calc(var(--j)*90deg - .5*#{$value-a}) 
						at var(--xy), 
						transparent, 
						nth($c, 4) $value-e $value-a - $value-e, 
						transparent  $value-a) 
					var(--xy)/ 50% 50% no-repeat;
			content: ''
		}

		&::after {
			border-radius: $value-r;
			background: nth($c, 4);
			content: counter(val) attr(data-unit)
		}
	}
}

.box {
	--j: var(--narr, 1);
	--not-j: calc(1 - var(--j));
	--c0: HSL(var(--h0), calc(var(--s0)*1%), calc(var(--l0)*1%));
	--c1: HSL(var(--h1), calc(var(--s1)*1%), calc(var(--l1)*1%));
	padding: $r;
	background: HSL(var(--h), calc(var(--s)*1%), calc(var(--l)*1%));
	
	.o & {
		grid-row: calc(var(--not-j)*2 + var(--j)*(var(--not-i)*3 + var(--i)));
		
		@media (min-width: 545px) { --narr: 0 }
	}
	
	[id='o0'] & {
		background: linear-gradient(var(--c0), var(--c0)) var(--c1);
		background-blend-mode: var(--mod)
	}
	
	[id='o1'] & {
		background: HSL(var(--h), calc(var(--s)*1%), calc(var(--l)*1%));
	}
}

pre, span, button, label {
	display: inline-flex;
	flex-wrap: wrap;
	align-items: flex-end
}

pre { align-self: start }

.token {
	&--prop { color: nth($c, 2) }
	
	&--val { margin-right: .75em }
	
	&--func { color: nth($c, 1) }
	
	&--keyw { color: nth($c, 3) }
	
	&--arg { color: nth($c, 4) }
	
	&--punc + :not(&--args) {
		&::before { content: ' ' }
	}
	
	&--arg {
		sub::after { content: var(--sub) }
	}
}

.ctrl { position: relative }

[aria-controls] {
	--hl: 0;
	padding: 0 .25em;
	border-radius: 5px;
	box-shadow: 0 0 0 calc(var(--hl)*2px) nth($c, 3);
	font-weight: 900;
	cursor: pointer;
	
	&:focus { outline: none }
	&:focus, &:hover { --hl: 1 }
}

[id='pop'] {
	--exp: 0;
	--not-exp: calc(1 - var(--exp));
	display: grid;
	grid-auto-flow: dense;
	grid-template-columns: max-content 1em;
	overflow: hidden;
	position: absolute;
	bottom: calc(100% + .5em); left: 0;
	padding: .5em;
	border-radius: 5px;
	transform-origin: 0 100%;
	transform: 
		perspective(35em)
		//rotatex(calc(var(--not-exp)*90deg)) 
		translate(calc(var(--not-exp)*-50%));
	opacity: var(--exp);
	box-shadow: 0 0 0 1px nth($g, 5), 
		4px 4px 33px rgba(nth($g, 1), .35), 
		inset 0 0 13px rgba(nth($g, 1), .2);
	background: nth($g, 3);
	transition: $t calc(var(--not-exp)*#{$t});
	transition-property: opacity, transform;
	
	[aria-expanded='true'] + & { --exp: 1 }
}

[type='radio'] {
	grid-column: 2;
	place-self: center;
	opacity: .0001;
	
	+ label {
		--sel: 0;
		position: relative;
		transform: 
			translate(calc(var(--not-exp)*50%));
		opacity: var(--exp);
		transition: inherit;
		transition-delay: calc(var(--exp)*#{$t} + (var(--idx) - 1)*.05s);
		cursor: pointer;
		
		&::after {
			display: grid;
			place-content:center;
			position: absolute;
			left: 100%; top: 0;
			width: 1em; height: 100%;
			opacity: var(--sel);
			content: '✔'
		}
	}
	
	&:checked + label { --sel: 1 }
}
              
            
!

JS

              
                const _BODY = document.body, 
			_O1 = document.getElementById('o1'), 
			HSL = _BODY.dataset.hsl.split(' '), 
			LYR = _BODY.dataset.lyr.split(' '), 
			_BTN = document.querySelector('button[aria-controls]');

function setVal(_e) { _BODY.style.setProperty(`--${_e.name || _e.id}`, _e.value) }

function toggleExp(val) {
	_BTN.setAttribute('aria-expanded', val || `${!(_BTN.getAttribute('aria-expanded') === 'true')}`)
}

[...document.querySelectorAll('input')].forEach(_e => setVal(_e));

addEventListener('input', e => setVal(e.target));

addEventListener('change', e => {
	let _t = e.target;
	
	if(_t.type === 'radio') {
		let _o = document.querySelector(`output[for*=${_t.value}]`), 
				v = _t.dataset.v.split(' ').map(c => + c);

		setVal(_t);
		_o.textContent = _t.value;
		HSL.forEach((c, i) => {
			_BODY.style.setProperty(`--sel-${c}`, `${v[i]}`);
			_O1.style.setProperty(`--${c}`, `var(--${c}${v[i]})`);
			_O1.style.setProperty(`--sub-${c}`, `'${LYR[v[i]]}'`)
		})
	}
})

addEventListener('click', e => toggleExp(e.target.parentNode === _BTN ? null : 'false'));
              
            
!
999px

Console