HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<main id="app">
<h1>Price Range Slider</h1>
<p>Using <a href="https://simeydotme.github.io/svelte-range-slider-pips/en/getting-started/">Range Slider Pips component</a></p>
<div id="slider"></div>
<p>With fancy, bouncy, floating labels!</p>
</main>
<!--
social icons
-->
<a class="social-icon codepen" href="https://codepen.io/simeydotme" title="view my codepens">
Made by Simey
</a>
<a class="social-icon twitter" href="https://twitter.com/simeydotme">
<svg viewBox="0 0 24 24">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M22 4.01c-1 .49 -1.98 .689 -3 .99c-1.121 -1.265 -2.783 -1.335 -4.38 -.737s-2.643 2.06 -2.62 3.737v1c-3.245 .083 -6.135 -1.395 -8 -4c0 0 -4.182 7.433 4 11c-1.872 1.247 -3.739 2.088 -6 2c3.308 1.803 6.913 2.423 10.034 1.517c3.58 -1.04 6.522 -3.723 7.651 -7.742a13.84 13.84 0 0 0 .497 -3.753c-.002 -.249 1.51 -2.772 1.818 -4.013z"></path>
</svg>
</a>
<a class="social-icon github" href="https://github.com/simeydotme">
<svg viewBox="0 0 24 24">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5"></path>
</svg>
</a>
/**
inspired by https://dribbble.com/shots/2056202-Range-Selection-with-Frequency-Chart
**/
#PriceGradient {
/** colors for the handles and range */
--color1: hsl(219, 73%, 65%);
--color2: hsl(283, 100%, 69%);
--colorMix: hsl(256, 100%, 59%);
--range-pip: #ccc;
--range-pip-in-range: var(--colorMix);
/** linear springs from for easing nicely */
--spring-duration: 1.5s;
--spring-easing: linear(
0, 0.576 4%, 0.79, 0.964, 1.102, 1.205, 1.275 13.6%, 1.298, 1.313, 1.32, 1.32,
1.313 19.3%, 1.299 20.7%, 1.256 23.4%, 1.111 30.5%, 1.047 34.2%, 1.018, 0.996,
0.979, 0.968 42.9%, 0.961 46.1%, 0.962 49.7%, 0.994 63.9%, 1.004 72%,
1.005 79.2%, 1
);
--color: var(--color1);
--shadow-color: 0deg 0% 0%;
--shadow-elevation-medium:
0px 0.4px 0.4px hsl(var(--shadow-color) / 0.1),
0px 0.8px 0.8px -0.8px hsl(var(--shadow-color) / 0.09),
0px 1.6px 1.7px -1.5px hsl(var(--shadow-color) / 0.08),
0px 3.5px 3.6px -2.3px hsl(var(--shadow-color) / 0.08),
0px 6.9px 7.2px -3px hsl(var(--shadow-color) / 0.07);
height: 14px;
}
#PriceGradient .rangeBar {
height: 100%;
background: linear-gradient(90deg, var(--color1), var(--color2));
}
#PriceGradient .rangeHandle[data-handle="1"] {
--color: var(--color2);
}
#PriceGradient .rangeHandle {
width: 34px;
height: 34px;
top: calc( 50% - 1px );
border-radius: 50%;
background: white;
border: 2px solid var(--color);
box-shadow: var(--shadow-elevation-medium);
perspective: 500px;
}
#PriceGradient .rangeNub {
display: none;
}
#PriceGradient .rangeFloat {
border-radius: .5em;
padding: .3em .6em;
background: white;
color: black;
font-weight: bold;
border: 2px solid var(--color);
top: -1em;
transform-origin: bottom center;
transform: translate(-50%, -100%) rotateX(100deg) scaleY(0.75);
transition: all var(--spring-easing) var(--spring-duration);
}
#PriceGradient .rangeFloat:after {
content: '';
position: absolute;
bottom: -2px;
left: 50%;
width: 9px;
height: 9px;
background: white;
transform: translate(-50%, 50%) rotate(45deg);
border-right: 2px solid var(--color);
border-bottom: 2px solid var(--color);
}
#PriceGradient.focus .rangeHandle .rangeFloat,
#PriceGradient.hoverable .rangeHandle:hover .rangeFloat,
#PriceGradient.hoverable:hover .rangeFloat {
top: -1em;
transform: translate(-50%, -100%) rotateX(0deg);
opacity: 1;
}
/** move the slider to the left or right while dragging */
#PriceGradient.up .rangeHandle.active .rangeFloat {
transform: translate(-60%, -100%) rotateZ(-15deg);
}
#PriceGradient.down .rangeHandle.active .rangeFloat {
transform: translate(-40%, -100%) rotateZ(15deg);
}
/** style the pips when active and in range */
#PriceGradient .pip {
height: 2px;
width: 2px;
border-radius: 2px;
}
#PriceGradient.focus .pip.in-range {
background: white;
box-shadow:
0 0 2px 1px var(--range-pip-in-range),
0 0 5px 2px var(--range-pip-in-range),
0 0 2px 0px var(--range-pip-in-range);
}
#app {
flex: 1 1 100%;
}
body, html {
flex: 0 1 90%;
display: flex;
align-items: center;
justify-content: center;
background: hsl(var(--canvas), 15%, 96%);
color: black;
text-align: center;
}
h1, p {
margin: 0;
}
p {
font-size: 1.4rem;
color: #999;
font-weight: 300;
margin-bottom: 3em;
}
p:last-child {
margin-top: 3em;
margin-bottom: 0em;
}
import RangeSliderPips from "https://cdn.skypack.dev/svelte-range-slider-pips@2.2.2";
let vals = [3000, 7000];
let timer;
const $slider = document.getElementById("slider");
const currency = new Intl.NumberFormat("en", {
style: "currency",
currency: "USD",
maximumFractionDigits: 0
});
const formatter = (value) => currency.format(value);
const stop = () => {
const $slider = document.querySelector("#PriceGradient");
$slider.classList.remove("up", "down");
};
const slide = (e) => {
const $slider = document.querySelector("#PriceGradient");
const delta = -(e.detail.previousValue - e.detail.value);
if (delta > 0) {
$slider.classList.add("up");
$slider.classList.remove("down");
} else {
$slider.classList.add("down");
$slider.classList.remove("up");
}
clearTimeout(timer);
timer = setTimeout(stop, 66);
};
const slider = new RangeSliderPips({
target: $slider,
props: {
id: "PriceGradient",
min: 0,
max: 10000,
values: vals,
pips: true,
range: true,
pipstep: 200,
first: false,
last: false,
float: true,
formatter: formatter
}
});
slider.$on('change', slide);
slider.$on('stop', stop);
setTimeout(() => {
document.querySelector("#PriceGradient .rangeHandle").focus()
}, 1000 );
Also see: Tab Triggers