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

              
                - var fn = [
-		{ name: 'blur', mult: .2, unit: 'px' }, 
-		{ name: 'brightness', mult: 2 }, 
-		{ name: 'contrast', mult: 4 }, 
-		{ name: 'grayscale' }, 
-		{ name: 'invert' }, 
-		{ name: 'opacity' }, 
-		{ name: 'saturate', mult: 5 }, 
-		{ name: 'sepia' }, 
-		{ name: 'hue-rotate', mult: 3.6, unit: 'deg' }
- ]
- var n = fn.length;
- var val = 45;

#box(style=`--val: ${val}; --filter: ${fn[0].name}(${fn[0].mult*val}${fn[0].unit})`)
	pre
		span.ctrl
			button#fnc.token--fnc(aria-haspopup='true' 
														aria-expanded='false' 
														aria-controls='pop-fnc') #{fn[0].name}
			form#pop-fnc.popup(data-trig='fnc')
				- for(var i = 0; i < n; i++) {
					input(type='radio' checked=!i 
								name='fn' id=`${fn[i].name}` 
								data-mult=fn[i].mult
								data-unit=fn[i].unit)
					label(for=`${fn[i].name}`) #{fn[i].name}
				- }
		span.token--punc (
		span.ctrl
			button#arg.token--arg(aria-haspopup='true' 
														aria-expanded='false' 
														aria-controls='pop-arg')
				span#num.token--num #{fn[0].mult*val}
				span#unit.token--unit #{fn[0].unit}
			form#pop-arg.popup(data-trig='arg')
				input#val(type='range' value=val step=5)
		span.token--punc )
              
            
!

CSS

              
                $url: url(https://images.unsplash.com/photo-1544070078-a212eda27b49?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ);
$b: 2em; // border-width
$rect: inset(0);
$dark: rgba(#262626, .95);
$llight: #ddd;
$hlight: #f90;
$track-w: 12.5em;
$track-h: .125em;
$thumb-d: 1em;
$thumb-r: .5*$thumb-d;
$input-w: $track-w + $thumb-d;

@mixin track() {
	box-sizing: border-box;
	border: none;
	width: $input-w; height: $track-h;
	border-radius: $track-h;
	background: radial-gradient(circle at calc(var(--pos) + #{$thumb-r}) 50%, 
				transparent $thumb-r, $llight 0);
}

@mixin thumb() {
	box-sizing: border-box;
	width: $thumb-d; height: $thumb-d;
	border-radius: 50%;
	transform: scale(.5);
	background: $llight;
}

@mixin thumb-focus {
	transform: scale(1);
	background: $hlight;
}

* { margin: 0; padding: 0; font: inherit }

body {
	box-sizing: border-box;
	padding: 2em;
	min-height: 100vh;
	background: repeating-linear-gradient(45deg, 
		$llight, $llight 2px, transparent 0, transparent 7px);
}

#box {
	--pos: calc(var(--val)*#{.01*$track-w});
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	margin: 0 auto;
	border: solid $b rgba(#000, .03);
	padding: 5em 2em;
	min-width: 17em;
	width: 80%;
	max-width: 30em;
	background: $url 50%/ cover 
								border-box /* background-origin */
								padding-box /* background-clip */;
	font: 500 1.375em/ 1.375 consolas, monaco, monospace;
	
	&:before {
		position: absolute;
		z-index: -1; /* put it *behind* parent */
		/* go outside padding-box by 
		 * a border-width ($b) in every direction */
		top: -$b; right: -$b; bottom: -$b; left: -$b;
		border: inherit;
		border-color: transparent;
		background: inherit;
		background-clip: border-box;
		/* -webkit-prefixed version 
		 * still needed for 
		 * some mobile browsers 💔😭 */
		-webkit-filter: var(--filter);
						filter: var(--filter);
		clip: rect(0 100% 100% 0); /* Edge */
		/* -webkit-prefixed version 
		 * still needed for 
		 * some mobile browsers 💔😭 */
		-webkit-clip-path: $rect;
						clip-path: $rect;
		content: ''
	}
}

pre {
	padding: .5em .75em;
	border-radius: 5px;
	background: $dark;
	color: $llight;
	
	* { color: inherit; font: inherit }
	
	span, button { display: inline-block }
}

.token {
	&--fnc { color: #f39dd4 }
	
	&--num { color: #f8f087 }
	
	&--unit { color: #b7e3c0 }
}

.ctrl {
	position: relative;
	white-space: normal;
}

button {
	border: solid 1px transparent;
	padding: 0 .125em;
	border-radius: 5px;
	background: none;
	cursor: pointer;
	
	&:focus {
		outline: dotted 0px transparent;
		border-color: $hlight
	}
	
	span { pointer-events: none }
}

.popup {
	display: none;
	position: absolute;
	top: 100%; left: 50%;
	padding: .5em;
	border-radius: 5px;
	transform: translate(-50%);
	background: $dark;
	
	[aria-expanded='true'] + & { display: block }
}

input {
	&[type='radio'] {
		position: absolute;
		left: -100vw;
		
		+ label {
			display: block;
			line-height: 1.375;
			cursor: pointer;
		}
		
		&:focus + label, + label:hover {
			color: #95a;
		}
		
		&:checked {
			+ label {
				color: $hlight;
			}
		}
	}
	
	&[type='range'] {
		&, &::-webkit-slider-thumb { -webkit-appearance: none }
	
		display: block;
		margin: .75em 0;
		width: $input-w; min-height: $thumb-d;
		background: transparent;
		cursor: pointer;

		&::-webkit-slider-runnable-track { @include track() }
		&::-moz-range-track { @include track }
		&::-ms-track {
			@include track;
			background: $llight
		}

		&::-webkit-slider-thumb {
			margin-top: .5*($track-h - $thumb-d);
			@include thumb
		}
		&::-moz-range-thumb { @include thumb }
		&::-ms-thumb {
			margin-top: 0;
			@include thumb
		}

		&::-ms-tooltip { display: none }
		
		&:focus {
			outline: solid 0px transparent;
			
			&::-webkit-slider-thumb { @include thumb-focus }

			&::-moz-range-thumb { @include thumb-focus }

			&::-ms-thumb { @include thumb-focus }
		}
	}
}
              
            
!

JS

              
                const _BOX = document.getElementById('box'), 
			_FNC = document.getElementById('fnc'), 
			_NUM = document.getElementById('num'), 
			_UNI = document.getElementById('unit');

let popup = null, 
		val = _BOX.style.getPropertyValue('--val'), 
		mult = _NUM.textContent/val;

function isIn(_el, cls) {
	/*
	 * ckecks if _el or any of its ancestors
	 * all the way up to the body have the 
	 * cls class
	 */
	
	if(_el === document.body) return false;
	return (_el.classList.contains(cls) ? 
		true : isIn(_el.parentNode, cls))
};

function openPopup(trig, new_pop) {
	trig.setAttribute('aria-expanded', true);
	popup = new_pop;
};

function closePopup() {
	/*
	 * close the currently open popup
	 * there can be only one, stored in 
	 * global popup variable
	 */
	if(popup) {
		document.getElementById(popup.dataset.trig)
			.setAttribute('aria-expanded', false);
		popup = null
	}
};

function update(e) {
	let _tg = e.target;
		
	if(_tg.type === 'radio') {
		mult = (+_tg.dataset.mult || 1);
		_FNC.textContent = _tg.id;
		_NUM.textContent = val*mult;
		_UNI.textContent = _tg.dataset.unit || '%';
	}
	
	if(_tg.type === 'range') {
		_BOX.style.setProperty('--val', val = +_tg.value)
		_NUM.textContent = val*mult;
	}
	
	_BOX.style.setProperty('--filter', `${_FNC.textContent}(${_NUM.textContent}${_UNI.textContent})`)
};

addEventListener('click', e => {
	let _tg = e.target;
	
	if(_tg.hasAttribute('aria-haspopup')) {
		let new_pop = _tg.nextElementSibling;
				
		if(popup !== new_pop) {
			if(popup) closePopup();
			
			openPopup(_tg, new_pop);
		}
		
		return
	}
	else if(!isIn(_tg, 'popup')) { closePopup() }
}, false);

addEventListener('input', update, false);
addEventListener('change', update, false);
              
            
!
999px

Console