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

              
                <html lang="en">
<head>
	<meta charset="utf-8" />
	<title>Custom Range Input with CSS and JavaScript</title>
	<script src="rangeinputSGE.js"></script>
	<link rel="stylesheet" href="rangestyleSGE.css" type="text/css" />
</head>
<body onload="setValue(88,1,false);setValue(38,2,false);setValue(50,3,true);">
<div id="wrapper">
  <div class="col" id="col1">
    <div class="slidershell" id="slidershell1">
	<div class="sliderfill" id="sliderfill1"></div>
	<div class="slidertrack" id="slidertrack1"></div>
	<div class="sliderthumb" id="sliderthumb1"></div>
	<div class="slidervalue" id="slidervalue1">0</div>
	<input class="slider" id="slider1" type="range" min="0" max="100" value="0"
	oninput="showValue(value,1,false);" onchange="showValue(value,1,false);"/>
</div>
<div class="slidershell" id="slidershell2">
	<div class="sliderfill" id="sliderfill2"></div>
	<div class="slidertrack" id="slidertrack2"></div>
	<div class="sliderthumb" id="sliderthumb2"></div>
	<div class="slidervalue" id="slidervalue2">0</div>
	<input class="slider" id="slider2" type="range" min="0" max="100" value="0"
	oninput="showValue(value,2,false);" onchange="showValue(value,2,false);"/>
</div>
  </div>
  <div class="col" id="col2">
    <div class="slidershell" id="slidershell3">
	<div class="sliderfill" id="sliderfill3"></div>
	<div class="slidertrack" id="slidertrack3"></div>
	<div class="sliderthumb" id="sliderthumb3"></div>
	<div class="slidervalue" id="slidervalue3">0</div>
	<input class="slidervertical" id="slider3" type="range" min="0" max="100" value="0"
	oninput="showValue(value,3,true);" onchange="showValue(value,3,true);"  orient="vertical" />
</div>
  </div>
  
  <p>This code from 2015 still works but is more complex than needed today. A simpler approach is at <a href="https://codepen.io/sgestrella/pen/rPWOKv" target="_top">my new pen.</a></p>
  
  </div>
</body>
</html>


              
            
!

CSS

              
                @charset "UTF-8";
/* CSS by Steven Estrella. http://www.stevenestrella.com */
/* The .slider and .slidervertical classes are for the range inputs. 
	Set the z-index high so its on top. */
.slider, .slidervertical {position:absolute;left:0px;top:0px;overflow:visible;z-index:100;}

/* slidershell exists only
to provide a positioning context for the range input and other elements.*/
.slidershell {border:0 none;position:relative;left:0px;top:0px;overflow:visible;}

/* .slidertrack is the visible track on which the user drags the thumb button. */
.slidertrack {border:2px outset #666;border-radius:4px;position:absolute;}

/* .sliderfill adds color (or a gradient as seen here) to the track as the user 
	drags the thumb. */
.sliderfill {border:2px solid #00767f;border-radius:4px;
	position:absolute;opacity:0.2;pointer-events:none;
	background:#00767f;background: linear-gradient(90deg,#005555,#006699);
	}

/* .sliderthumb can be any css you like including an image. 
	The dimensions must match those found in the rule for 
	input[type=range]::-webkit-slider-thumb. */
.sliderthumb {width:40px;height:40px;
	background-image:url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/358203/thumb.png');background-size: 40px 40px;
	background-position:0px 0px;
	background-repeat: no-repeat;background-color:transparent;
	position:absolute;left:0px;top:0px;border:0 none;
	padding:0px;margin:0px;text-align:center;
	pointer-events:none;
}

/* .slidervalue can be styled as you see fit */
.slidervalue {width:40px;height:40px;line-height:40px;color:#fff;
	font-family:helvetica,sans-serif;font-size:18px;
	position:absolute;left:0px;top:0px;border:0 none;
	padding:0px;margin:0px;text-align:center;
	pointer-events:none;
}


/* First we have to make transparent all the default elements of the range input.
	We use color:transparent to eliminate the default tick marks in IE. */

input[type=range]::-ms-track {
	width:100%;height:100%;
	-webkit-appearance:none;margin:0px;padding:0px;border:0 none;
	background:transparent;color:transparent;overflow:visible;
}
input[type=range]::-moz-range-track {
	width:100%;height:100%;
	-moz-appearance:none;margin:0px;padding:0px;border:0 none;
	background:transparent;color:transparent;overflow:visible;
}
input[type=range] {
	width:100%;height:100%;
	-webkit-appearance:none;margin:0px;padding:0px;border:0 none;
	background:transparent;color:transparent;overflow:visible;
}
/* we need a separate rule for when the range input is to be vertical */
input[type=range].slidervertical {
	-webkit-appearance: slider-vertical;
	writing-mode: bt-lr; /* IE */
	opacity:0.01; /* needed to hide the default slider-vertical appearance */
}

input[type=range]:focus::-webkit-slider-runnable-track {
	background:transparent;border:transparent;}
input[type=range]:focus {outline: none;}
	
/* Make the thumbs the same size as your custom sliderthumb. 
	they will not be visible but they will be draggable. 	*/
input[type=range]::-ms-thumb {width:40px;height:40px;
	border-radius:0px;border:0 none;background:transparent;}
input[type=range]::-moz-range-thumb {width:40px;height:40px;
	border-radius:0px;border:0 none;background:transparent;}	
input[type=range]::-webkit-slider-thumb {width:40px;height:40px;
	border-radius:0px;border:0 none;background:transparent;-webkit-appearance:none;}

/* microsoft IE10+ and Edge - eliminates default fills before and after thumb */
input[type=range]::-ms-fill-lower {background:transparent;border:0 none;}
input[type=range]::-ms-fill-upper {background:transparent;border:0 none;}
input[type=range]::-ms-tooltip { display: none;}



/* other rules you may need for page styling */
body {font-family:sans-serif;background:#0effff;}
.slider2column, td, tr, th {width:400px;border:0 none !important;}

.col {display:inline-block;margin:40px;vertical-align:top;}
.col #slidershell1 {margin:0 0 100px 0;}

#wrapper {max-width:600px;margin:0 auto;background:white;padding:40px;}
              
            
!

JS

              
                /* Code by Steven Estrella. http://www.shearspiremedia.com */
/* we need to change slider appearance oninput and onchange */
function showValue(val,slidernum,vertical) {
	/* setup variables for the elements of our slider */
	var thumb = document.getElementById("sliderthumb" + slidernum);
	var shell = document.getElementById("slidershell" + slidernum);
	var track = document.getElementById("slidertrack" + slidernum);
	var fill = document.getElementById("sliderfill" + slidernum);
	var rangevalue = document.getElementById("slidervalue" + slidernum);
	var slider = document.getElementById("slider" + slidernum);
	
	var pc = val/(slider.max - slider.min); /* the percentage slider value */
	var thumbsize = 40; /* must match the thumb size in your css */
	var bigval = 250; /* widest or tallest value depending on orientation */
	var smallval = 40; /* narrowest or shortest value depending on orientation */
	var tracksize = bigval - thumbsize;
	var fillsize = 16;
	var filloffset = 10;
	var bordersize = 2;
	var loc = vertical ? (1 - pc) * tracksize : pc * tracksize;
	var degrees = 360 * pc;
	var rotation = "rotate(" + degrees + "deg)";
	
	rangevalue.innerHTML = val;
	
	thumb.style.webkitTransform = rotation;
	thumb.style.MozTransform = rotation;
	thumb.style.msTransform = rotation;
	
	fill.style.opacity = pc + 0.2 > 1 ? 1 : pc + 0.2;
	
	rangevalue.style.top = (vertical ? loc : 0) + "px";
	rangevalue.style.left = (vertical ? 0 : loc) + "px";
	thumb.style.top =  (vertical ? loc : 0) + "px";
	thumb.style.left = (vertical ? 0 : loc) + "px";
	fill.style.top = (vertical ? loc + (thumbsize/2) : filloffset + bordersize) + "px";
	fill.style.left = (vertical ? filloffset + bordersize : 0) + "px";
	fill.style.width = (vertical ? fillsize : loc + (thumbsize/2)) + "px";
	fill.style.height = (vertical ? bigval - filloffset - fillsize - loc : fillsize) + "px";
	shell.style.height = (vertical ? bigval : smallval) + "px";
	shell.style.width = (vertical ? smallval : bigval) + "px";
	track.style.height = (vertical ? bigval - 4 : fillsize) + "px"; /* adjust for border */
	track.style.width = (vertical ? fillsize : bigval - 4) + "px"; /* adjust for border */
	track.style.left = (vertical ? filloffset + bordersize : 0) + "px";
	track.style.top = (vertical ? 0 : filloffset + bordersize) + "px";
}
/* we often need a function to set the slider values on page load */
function setValue(val,num,vertical) {
	document.getElementById("slider"+num).value = val;
	showValue(val,num,vertical);
}


              
            
!
999px

Console