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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<div class="slider-container">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M13.7 2.30021C12.7 1.80021 11.6 2.00021 10.7 2.70021C8.6 4.40021 6.3 6.00021 3.8 7.30021C2.1 8.20021 1 10.0002 1 12.0002C1 13.9002 2.1 15.7002 3.8 16.7002C6.1 17.9002 8.4 19.5002 10.7 21.4002C11.2 21.8002 11.8 22.0002 12.5 22.0002C12.9 22.0002 13.3 21.9002 13.7 21.7002C14.7 21.2002 15.3 20.3002 15.3 19.2002V4.80021C15.3 3.70021 14.7 2.70021 13.7 2.30021Z" fill="currentColor" />
<path d="M17.3 14.8002C17.5 15.0002 17.8 15.1002 18 15.1002C18.2 15.1002 18.5 15.0002 18.7 14.8002C19.5 14.1002 19.9 13.0002 19.9 11.9002C19.9 10.8002 19.5 9.8002 18.7 9.0002C18.3 8.6002 17.7 8.6002 17.3 9.0002C16.9 9.4002 16.9 10.0002 17.3 10.4002C17.7 10.8002 17.9 11.3002 17.9 11.8002C17.9 12.3002 17.7 12.8002 17.3 13.2002C16.9 13.8002 16.9 14.4002 17.3 14.8002Z" fill="currentColor" />
<path d="M18.5001 5.10008C18.0001 4.90008 17.4001 5.10008 17.2001 5.60008C17.0001 6.10008 17.2001 6.70008 17.7001 6.90008C19.7001 7.80008 21.0001 9.80008 21.0001 11.9001C21.0001 14.1001 19.7001 16.1001 17.6001 17.0001C17.1001 17.2001 16.9001 17.8001 17.1001 18.3001C17.3001 18.7001 17.6001 18.9001 18.0001 18.9001C18.1001 18.9001 18.3001 18.9001 18.4001 18.8001C21.2001 17.7001 23.0001 15.0001 23.0001 12.0001C23.0001 9.00008 21.2001 6.30008 18.5001 5.10008Z" fill="currentColor" />
</svg>
<input id="slider" type="range" min="0" max="1000" value="1000">
</div>
:root {
--fill-bar-width: var(--slider-max-width);
--slider-max-width: 150px;
}
body {
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100vh;
min-height: 400px;
background-color: #faf9fd;
.slider-container {
display: flex;
align-items: center;
transform: rotateZ(-90deg);
input[type="range"] {
position: relative;
-webkit-appearance: none;
z-index: 1;
width: var(--slider-max-width);
height: 6px;
background: #ebeaf8;
outline: none;
border-radius: 6px;
transition: 250ms;
&:hover {
cursor: grab;
}
&:active {
cursor: grabbing;
}
&::before {
content: "";
position: absolute;
top: 0;
left: 0;
z-index: -1;
width: var(--fill-bar-width);
height: 6px;
color: #ffffff00;
background: #4832ff;
border-radius: 6px;
}
&::-webkit-slider-thumb {
position: relative;
-webkit-appearance: none;
appearance: none;
width: 14px;
height: 14px;
background: #4832ff;
border-radius: 50%;
box-shadow: -4px 0 0 -1px #17161e22;
z-index: 2;
transition: 100ms;
&:hover {
width: 18px;
height: 18px;
}
}
&::-moz-range-thumb {
appearance: none;
width: 12px;
height: 12px;
background: #4832ff;
border-radius: 50%;
}
}
svg {
margin-right: 20px;
transform: rotateZ(90deg);
color: #4832ff;
}
}
}
const body = document.body
const root = document.querySelector(':root');
const slider = document.querySelector('#slider')
let maxValue = slider.max
let minValue = slider.min
let maxWidth = parseInt(getComputedStyle(root).getPropertyValue('--slider-max-width').slice(0, -2))
let isFalling = false
let width
const smallg = 9.8
function setWidth() {
width = maxWidth * (slider.value - minValue) / (maxValue - minValue)
root.style.setProperty('--fill-bar-width', `${width}px`)
}
window.onload = init()
function init() {
setWidth()
falling() // If you want a normal range slider, just remove this
}
slider.addEventListener('input', setWidth)
// If you want a normal range slider, just remove this
slider.addEventListener('change', () => {
if (!isFalling) {
falling()
}
})
// If you want a normal range slider, just remove this
function falling() {
isFalling = true
let velocity = 0
let precision = 64
let speed = 16
let restitution = 0.5
let isbounced = false
let fall = setInterval(() => {
if (slider.value > minValue && isbounced === false) {
velocity += smallg / (precision / speed)
slider.value -= velocity
setWidth()
} else {
isbounced = true
if (velocity > 0) {
velocity -= smallg / (precision / speed)
slider.value = +slider.value + velocity * restitution
setWidth()
} else if (slider.value > minValue) {
clearInterval(fall);
falling()
} else {
clearInterval(fall);
isFalling = false
}
}
}, 1000 / precision)
}
Also see: Tab Triggers