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.
<h1>Ebike Estimated Battery Lifetime</h1>
<p>This estimation is based on the assumption of using the bike on weekdays to and from work.</p>
<div id="hint">Note that actual battery life is affected by many factors, mainly how you charge it: Try to not charge and discharge it fully - </br> charge it to ~80-90% and discharge it to ~20% before charging again. If you want to store the battery / not use it for a while, charge it to ~50%. </br> The battery lifetime does not mean that it will be completely unusable after X years, just that it will have lost a considerable amount of capacity (~20%),</br> meaning the range in one charge is decreased, and potentially lower voltage (which means slightly lower top speed).</div>
<input type="checkbox" id="useimperical" onclick="onunitsclicked()">
<label for="useimperical">Use imperial units</label><br>
<div class="slidercontainer">
<span>Distance to work:</span>
<input type="range" min="1" max="50" value="10" class="slider" id="workdistance">
<span id="workdistancevalue" class="value"></span>
</div>
<br/>
<div class="slidercontainer">
<span>Range per charge:</span>
<input type="range" min="10" max="200" value="50" class="slider" id="range">
<span id="rangevalue" class="value"></span>
</div>
<br/>
<div class="slidercontainer">
<span>Number of charge cycles:</span>
<input type="range" min="100" max="1000" value="600" class="slider" id="cycles">
<span id="cyclesvalue" class="value"></span>
</div>
<br/>
<p>Estimated lifetime: <span id="lifetime"></span> years</p>
<br/>
<h2>Cost estimation</h2>
<div class="slidercontainer">
<span>Battery cost:</span>
<input type="range" min="100" max="1000" value="500" class="slider" id="cost">
<span id="costvalue" class="value"></span>
</div>
<p>Estimated cost: <span id="costperyear"></span>/year</p>
* {
font-family: Arial;
}
body {
padding: 20px;
}
.slidercontainer {
display: flex;
height: 60px;
flex-direction: row;
align-items: center;
}
#useimperical {
margin-bottom: 20px;
}
#hint {
opacity: 0.7;
margin-bottom: 30px;
}
span {
font-size: 14pt;
}
p {
font-size: 16pt;
font-weight: bold;
margin-top: 20px;
margin-bottom: 30px;
}
.slider {
width: 800px;
margin: 20px;
}
.value {
font-weight: bold;
}
#lifetime, #costperyear {
font-size: 26pt;
}
var useimperical = false;
function calcLifetime(range, cycles, workdistance) {
var lifetime = cycles*range/(workdistance*2)/(365*(5/7));
return Math.round(lifetime * 10) / 10
}
function updateLifetime() {
var range = parseInt(rangeslider.value);
var cycles = parseInt(cyclesslider.value);
var workdistance = parseInt(workdistanceslider.value);
var lt = calcLifetime(range, cycles, workdistance);
document.getElementById("lifetime").innerHTML = lt;
return lt;
}
var rangeslider = document.getElementById("range");
rangeslider.step = "5"
var rangevalue = document.getElementById("rangevalue");
var cyclesslider = document.getElementById("cycles");
cyclesslider.step = "25";
var cyclesvalue = document.getElementById("cyclesvalue");
var workdistanceslider = document.getElementById("workdistance");
var workdistancevalue = document.getElementById("workdistancevalue");
var costslider = document.getElementById("cost");
costslider.step = "25";
var costvalue = document.getElementById("costvalue");
var costperyear = document.getElementById("costperyear");
function rendervalues(useimpericalunits) {
var distanceunit = useimperical ? " miles" : " km";
var monetaryunit = useimperical ? " USD" : " EUR";
rangevalue.innerHTML = rangeslider.value + distanceunit;
cyclesvalue.innerHTML = cyclesslider.value + " cycles";
workdistancevalue.innerHTML = workdistanceslider.value + distanceunit;
costvalue.innerHTML = costslider.value + monetaryunit;
costperyear.innerHTML = Math.round(parseInt(costslider.value) / updateLifetime()) + monetaryunit;
}
rendervalues(useimperical);
rangeslider.oninput = function() {
rangevalue.innerHTML = this.value + " km";
updateLifetime();
updatecostperyear()
}
cyclesslider.oninput = function() {
cyclesvalue.innerHTML = this.value + " cycles";
updateLifetime();
updatecostperyear()
}
workdistanceslider.oninput = function() {
workdistancevalue.innerHTML = this.value + " km";
updateLifetime();
updatecostperyear()
}
function onunitsclicked() {
var useimpericalcheck = document.getElementById("useimperical");
useimperical = useimpericalcheck.checked;
rendervalues(useimperical);
}
function updatecostperyear() {
var monetaryunit = useimperical ? " USD" : " EUR";
costperyear.innerHTML = Math.round(parseInt(costslider.value) / updateLifetime()) + monetaryunit;
}
costslider.oninput = function() {
var monetaryunit = useimperical ? " USD" : " EUR";
costvalue.innerHTML = this.value + monetaryunit;
updatecostperyear()
}
updateLifetime();
Also see: Tab Triggers