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 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

              
                - let data = [
- 	{ val: 317, max: 500, uni: 1000, mrk: 50, num: 6, suf: '€', lbl: 'price' }, 
- 	{ min: 1, val: 5, max: 10, pas: .1, mrk: .5, num: 10, lbl: 'value' }
- ];
- let n = data.length;

- for(let i = 0; i < n; i++)
	- let c = data[i];
	- let min = c.min || 0, val = c.val || 0, max = c.max || 100;
	- let uni = c.uni || 1, pas = c.pas || 1, suf = c.suf || '';
	.wrap(role='group' aria-label=`${c.lbl}` class=pas%1 ? 'dec' : null style=`--min: ${min}; --val: ${val}; --max: ${max}; --pas: ${pas}; --uni: ${uni}; --suf: '${suf}'${c.mrk ? `; --mrk: ${c.mrk}` : ''}${c.num ? `; --num: ${c.num}` : ''}`)
		input(id=`r${i}` type='range' min=min value=val max=max step=pas list=c.num ? `l${i}` : null)
		output(for=`r${i}`)
		if c.num
			- let u = (max - min)/(c.num - 1);
			datalist(id=`l${i}`)
				- for(let i = 0; i < c.num; i++)
					option(value=(min + i*u) label=(min + i*u)*(c.uni || 1))
              
            
!

CSS

              
                /* reduced the SCSS code by almost 20% */
$track-p: 1.5em;
$track-w: 26em;
$track-h: .375em;
$track-r: $track-h/2;
$track-s: 
	inset 0 1px #999, 
	inset 0 1px .125em #555, 
	inset 0 -1px .125em #ccc;
$track-c: #31a9e6;

$thumb-d: 1em;

$ruler-h: .5em;
$ruler-c: #808080;

$t: .3s;

@mixin track($f: 0) {
  width: 100%; height: $track-h;
  border-radius: $track-r;
	box-shadow: 0 1px #aaa, $track-s;
  background: #b5b5b4;
	
	@if $f > 0 {
		background-image: 
			linear-gradient(90deg, 
				$track-c calc(var(--js, 0)*var(--pos)), transparent 0)
	}
}

@mixin thumb($o: 0) {
	margin-top: $o*($track-r - .5*$thumb-d);
  border: solid 1px #2f59a7;
  width: $thumb-d; height: $thumb-d;
  border-radius: .25*$thumb-d;
  background: linear-gradient(#d5e3ef, #4e94cc)
}

* {
	box-sizing: inherit;
	margin: 0;
	padding: 0;
	background: transparent;
	color: inherit;
	font: inherit
}

@property --houdini {
	syntax: '<number>';
	initial-value: 1;
	inherits: true
}

.js { --js: 1 }

body {
	// assume no support for registering custom props at first
	--s: var(--houdini, 0);
	// assume narrow screen scenario
	--k: var(--wide, 0);
	display: grid;
	grid-gap: 1em;
	place-content: center;
	overflow-x: hidden;
	min-height: 100vh;
	
	@media (min-width: 350px) { --wide: 1 }
}

.wrap {
	// slider range
	--range: calc(var(--max) - var(--min));
	// slider width
	--track-w: Min(#{$track-w}, calc(100vw - 2*#{$track-p}));
	// current position of vertical midline of thumb
	--pos: calc(.5*#{$thumb-d} + (var(--val) - var(--min))/var(--range)*(var(--track-w) - #{$thumb-d}));
	// initial state: not focused
	--focus: 0;
	display: grid;
	grid-gap: .125em;
	padding: 2em $track-p .5em;
	width: var(--track-w);
	background: rgba(#f9f9f9, var(--focus));
	color: #c7c8cb;
	font: 1em/ 1.5 ubuntu mono, consolas, monaco, monospace;
	// grayscale if not focused
	filter: grayScale(calc(1 - var(--focus)));
	transition: $t;
	transition-property: background-color, filter;
	
	&:focus-within { --focus: 1 }
}

input, output { grid-area: 1/ 1 }

input[type='range'] {
	&, &::-webkit-slider-thumb, 
	&::-webkit-slider-runnable-track { -webkit-appearance: none }
	
	width: 100%; height: $thumb-d;
	cursor: pointer;
	
	&::-webkit-slider-runnable-track { @include track(1) }
  &::-moz-range-track, &::-moz-range-progress { @include track() }
	&::-moz-range-progress { background: $track-c }
	
  &::-webkit-slider-thumb { @include thumb(1) }	
  &::-moz-range-thumb { @include thumb() }
  
  &:focus { outline: none }
}

@property --prod {
	syntax: '<number>';
	initial-value: 0;
	inherits: true
}

@property --int {
	syntax: '<integer>';
	initial-value: 0;
	inherits: true
}

@property --dec {
	syntax: '<integer>';
	initial-value: 0;
	inherits: true
}

output {
	// so not to repeat the product
	--prod: calc(var(--val)*var(--uni));
	display: var(--js, none);
	place-self: start;
	transform: translate(calc(var(--pos) - 50%), -100%);
	color: #1f1f1f;
	counter-reset: val calc(var(--val)*var(--uni));
	
	.dec & {
		// basically floor(var(--prod)) 
		// when combined with registering --int as integer
		--int: Max(0, calc(var(--prod) - .5));
		// basically var(--prod) % 1
		--dec: calc(10*(var(--prod) - var(--int)));
		counter-reset: int var(--int) dec var(--dec);

		&::after {
			// not displayed if --houdini can't be registered
			display: var(--houdini, none);
			content: counter(int) '.' counter(dec) var(--suf)
		}
	}
	
	&::after {
		display: block;
		transform-origin: 50% 100%;
		transform: scale(var(--focus));
		transition: transform $t;
		content: counter(val) var(--suf)
	}
}

datalist {
	--ratio0: 1/(var(--num) - 1);
	--ratio1: calc(var(--mrk)/var(--range));
	--list-w: calc((1 + var(--ratio0))*(100% - #{$thumb-d}));
	--list-u: calc(var(--list-w)/var(--num));
	--pad: calc((1 + var(--k))*#{$ruler-h});
	display: flex;
	justify-content: space-between;
	margin: 0 calc(50% - .5*var(--list-w));
	padding-top: var(--pad);
	width: var(--list-w);
	background: 
		repeating-linear-gradient(90deg, 
				$ruler-c 0 2px, 
				transparent 0 calc((100% - 2px)*var(--ratio0))) 
			50% 0/ 
			calc((var(--num) - 1)*100%/var(--num) + 2px) var(--pad), 
		repeating-linear-gradient(90deg, 
				rgba($ruler-c, var(--k)) 0 2px, 
				transparent 0 calc((100% - 2px)*var(--ratio1))) 
			50% 0/ 
			calc((var(--num) - 1)*100%/var(--num) + 2px) $ruler-h;
	background-repeat: no-repeat;
	text-align: center;
}

option {
	display: grid;
	place-content: center;
	width: var(--list-u);
	
	&:not(:first-child):not(:last-child) { display: var(--wide, none) }
}
              
            
!

JS

              
                /* external resources *only* for displaying the info boxes */
/* after update, JS down from 68 lines to just 10 incl. comms (150 bytes minified) */
/* this below is all the JS needed for the demo itself to work */
document.documentElement.classList.add('js');

addEventListener('input', e => {
	let _t = e.target;
	
	_t.parentNode.style.setProperty('--val', +_t.value)
}, false)
              
            
!
999px

Console