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 = [
- 	{ col: -1, val: 55, uni: 1000, suf: ' light years', lbl: 'distance' }, 
- 	{ col: -1, prg: 1, val: 35, uni: 1000000, end: 1, suf: ' miles', lbl: 'distance' }, 
- 	{ val: 0, max: 10, end: 1, mrk: .5, num: 5, suf: ' mm', lbl: 'size' }, 
- 	{ min: -50, max: 50, end: 1, mrk: 5, num: 5, suf: '°', lbl: 'temperature' }, 
- 	{ prg: 1, val: 80, uni: 50, end: 1, mrk: 5, num: 5, prf: '$', lbl: 'price' }, 
- 	{ prg: 1, val: 90, uni: 1000, end: 1, mrk: 5, num: 5, suf: '€', lbl: 'price' }
- ];
- 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;
	.wrap(role='group' aria-label=`${c.lbl} (${(c.prf || c.suf).trim()})` class=c.mrk && c.mrk%1 ? 'dec' : null style=`--min: ${min}; --val: ${val}; --max: ${max}; --prg: ${c.prg || 0}; --prf: '${c.prf || ''}'; --suf: '${c.suf || ''}'${c.col ? `; --col: ${c.col}` : ''}${c.mrk ? `; --mrk: ${c.mrk}` : ''}${c.num ? `; --num: ${c.num}` : ''}; --uni: ${c.uni || 1}`)
		output(for=`r${i}` aria-hidden='true' style=`--val: var(--min)`)
		output(for=`r${i}` aria-hidden='true' style=`--val: var(--max)`)
		input(id=`r${i}` type='range' min=c.min value=c.val max=c.max step=c.mrk 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

              
                $n: 5;
$t: .3s;

$input-hl: #eb566a;
$input-ll: #dde2e6;
$label-ll: #221d19;
$label-hl: #fff;

$track-w: 25em;
$track-h: 1.125em;
$track-r: $track-h/3;

$thumb-p: $track-r;
$thumb-h: 1.5em;
$thumb-w: .5*$thumb-h + 2*$thumb-p;

@mixin track() {
	width: 100%; height: $track-h;
	border-radius: $track-r;
	background-color: $input-ll;
	background-image: 
		linear-gradient(90deg, 
				// no hprogress highlight if no js (--js: 0) or
				// if current slider shouldn't have a progress (--prg: 0)
				$input-hl calc(var(--js, 0)*var(--prg)*var(--pos)), 
				transparent 0);
}

@mixin thumb($f: 0) {
	box-sizing: border-box;
	margin-top: $f*.5*($track-h - $thumb-h);
	border: none;
	padding: 0 $thumb-p;
	width: $thumb-w; height: $thumb-h;
	background: $input-hl content-box;
}

* {
	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);
	// blergh to setting it here, but need it for grid-template-columns 
	// ... or do I? I don't fucking get grid
	--colmn-w: Min(#{1 + 1/($n - 1)}*#{$track-w}, calc(#{(1 - 1/$n)}*(100vw - 6em)));
	--track-u: calc(var(--colmn-w)/#{$n - 1});
	display: grid;
	grid-gap: 1em 2em;
	grid-template-columns: repeat(auto-fit, var(--colmn-w));
	place-content: center space-evenly;
	overflow-x: hidden;
	margin: 0 auto;
	padding: 0 2em;
	max-width: calc(3*var(--colmn-w)); min-height: 100vh;
	background: #262626
}

.wrap {
	// slider range
	--range: calc(var(--max) - var(--min));
	// wrapper size, smaller than width of column(s) reserved for wrapper 
	// because of that padding on the wrapper
	--input-w: Min(calc((1 - var(--col, 0))*var(--colmn-w)), calc(#{(1 - 1/$n)}*(100vw - 8em)));
	// current position of vertical midline of thumb
	--pos: calc(.5*#{$thumb-w} + (var(--val) - var(--min))/var(--range)*(var(--input-w) - #{$thumb-w}));
	// initial state: not focused
	--focus: 0;
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	// only 1st 2 wrappers have --col set to -1
	// this will have no effect on the other wrappers
	grid-column: 1/ var(--col);
	place-self: center;
	position: relative;
	// give tooltip padding space as it will overflow content-box
	padding: 0 4em;
	width: var(--input-w);
	font: 1em/ 1.375 sans-serif;
	// grayscale if not focused
	filter: grayScale(calc(1 - var(--focus)));
	transition: filter $t;
	
	&:focus-within { --focus: 1 }
}

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

  &::-webkit-slider-thumb { @include thumb(1) }
  &::-moz-range-thumb { @include thumb }
  
  &:focus { outline: none }
}

@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));
	counter-reset: val var(--prod);
	
	&:not([aria-hidden]) {
		// not displayed unless js is enabled (--js: 1)
		display: var(--js, none);
		position: absolute;
		// move tooltip depending on current position of thumb midline --pos
		transform: translate(calc(var(--pos) - 50%));
		
		.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)));
			// not displayed if --houdini can't be registered
			display: var(--houdini, none);
			counter-reset: int var(--int) dec var(--dec);
			
			&::after { content: var(--prf) counter(int) '.' counter(dec) var(--suf) }
		}
		
		&::after {
			transform-origin: 50% 100%;
			// scaled to zero unlss the slider is focused (--focus: 1)
			transform: scale(var(--focus));
			background-color: $input-hl;
			color: $label-ll;
			transition: transform $t;
			
			// tooltip arrow is created with conic-gradient
			@supports (background: conic-gradient(red, tan)) {
				background-clip: border-box;
				--mask: 
					linear-gradient(red, red) padding-box, 
					conic-gradient(from -45deg at 50% 100%, red 0% 25%, transparent 0%) 50% 100%/ 50% 50% no-repeat border-box;
				-webkit-mask: var(--mask);
								mask: var(--mask)
			}
		}
	}
	
	&::after {
		display: block;
		border: solid $track-r transparent;
		border-width: $track-r 0;
		padding: 0 $track-r;
		border-radius: #{$track-r}/ #{2*$track-r};
		background: $input-ll padding-box;
		color: $label-ll;
		content: var(--prf) counter(val) var(--suf)
	}
}

datalist {
	--ratio0: 1/(var(--num) - 1);
	--ratio1: calc(var(--mrk)/var(--range));
	--list-w: calc((1 + var(--ratio0))*(100% - #{$thumb-w}));
	display: flex;
	margin: 0 calc(50% - .5*var(--list-w));
	padding-top: 1em;
	width: var(--list-w);
	background: 
		repeating-linear-gradient(90deg, 
				currentcolor 0 2px, 
				transparent 0 calc((100% - 2px)*var(--ratio0))) 
			50% 0/ calc((var(--num) - 1)*100%/var(--num) + 2px) 1em, 
		repeating-linear-gradient(90deg, 
				currentcolor 0 2px, 
				transparent 0 calc((100% - 2px)*var(--ratio1))) 
			50% 0/ calc((var(--num) - 1)*100%/var(--num) + 2px) .5em;
	background-repeat: no-repeat;
	color: $input-ll;
	text-align: center
}

option { flex: 1 }
              
            
!

JS

              
                /* external resources *only* for displaying the info boxes */

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