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 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.
<!-- Happy new Year! -->
<div id="container">
<div id="barcontainer">
<div id="title">Progress.</div>
<div id="yp">Year Progress: <span id="ypp"></span></div>
<div id="ygraph">
<div id="ybar"></div>
</div>
<div id="mp">Month Progress: <span id="mpp"></span></div>
<div id="mgraph">
<div id="mbar"></div>
</div>
<div id="dp">Day Progress: <span id="dpp"></span></div>
<div id="dgraph">
<div id="dbar"></div>
</div>
<div id="hp">Hour Progress: <span id="hpp"></span></div>
<div id="hgraph">
<div id="hbar"></div>
</div>
<div id="mip">Minute Progress: <span id="mipp"></span></div>
<div id="migraph">
<div id="mibar"></div>
</div>
</div>
<div id="abt">
<div id="dm">🌘</div>
<div id="txt">🎉 Happy 2020! 🎉<br>Made on the 31st of<br>Dezember 2019.<br><br>Previous years:<br><a href="https://codepen.io/nitnelav/pen/yGzxNv" target="_blank">2018</a><br><a href="https://codepen.io/nitnelav/pen/vpmQQq" target="_blank">2017</a></div>
</div>
<div id="settings">âš™</div>
</div>
/*Happy 2020! 🎉*/
:root {
--bright: #fff;
--dark: #000;
}
#container {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
font-family: "IBM Plex Mono", monospace;
font-size: 2vh;
color: var(--dark);
overflow: hidden;
background: var(--bright);
}
#settings {
position: absolute;
top: 1vh;
right: 30vh;
font-size: 3vh;
color: var(--bright);
cursor: pointer;
transition: right 0.2s;
}
#abt {
position: absolute;
top: -40vh;
left: calc(100vw - 40vh);
height: 60vh;
width: 60vh;
border-radius: 100%;
background: var(--dark);
transition: all 0.5s cubic-bezier(0.87, -0.2, 0.19, 1.2);
}
#txt {
position: absolute;
top: 42vh;
left: 12vh;
height: 22vh;
width: 25vh;
font-size: 1.5vh;
text-align: center;
color: var(--bright);
background: none;
}
#dm {
position: absolute;
top: 42vh;
right: -1vh;
width: 25vh;
font-size: 2.2vh;
cursor: pointer;
}
#barcontainer {
position: absolute;
top: 18vh;
left: 0;
right: 0;
height: 75vh;
overflow: hidden;
}
#title {
font-size: 7vh;
margin-left: 10vw;
margin-bottom: 7vh;
font-weight: 700;
}
#yp,
#mp,
#dp,
#hp,
#mip {
margin-left: 10vw;
margin-bottom: 1vh;
}
#ygraph,
#mgraph,
#dgraph,
#hgraph,
#migraph {
height: 3vh;
width: 80vw;
border: 1px solid var(--dark);
overflow: hidden;
margin-bottom: 5vh;
margin-left: 10vw;
}
#ybar,
#mbar,
#dbar,
#hbar,
#mibar {
height: 3vh;
width: 0vw;
background: var(--dark);
transition: width 0.5s;
}
a,
a:link,
a:visited {
color: var(--bright);
}
@media (prefers-color-scheme: dark) {
:root {
--dark: #fff;
--bright: #000;
}
}
//Happy 2020! 🎉
///////////////////////////
//Defaults and Vars
let def_with = 80;
let exp = true;
let dm;
let set_btn = document.getElementById("settings");
let dm_btn = document.getElementById("dm");
let root = document.documentElement;
///////////////////////////
//Main Interval
setInterval(() => {
//Set start of year
let d = new Date();
d.setMonth(0);
d.setDate(1);
d.setHours(0);
d.setMinutes(0);
d.setSeconds(0);
//calculate seconds since start of Year
let now = new Date();
let elapsedY = now - d;
//calculate percentage for year
let spy = secondsPerYear(now.getFullYear());
let yperc = elapsedY / 1000 / spy;
yperc = Math.round(yperc * 10000000) / 100000;
ypp.innerHTML = yperc + "%";
ybar.style.width = def_with * yperc / 100 + "vw";
//calculate percentage for month
let startOfMonth = new Date();
startOfMonth.setDate(1);
startOfMonth.setHours(0);
startOfMonth.setMinutes(0);
startOfMonth.setSeconds(0);
startOfMonth.setMilliseconds(0);
let elapsedM = now - startOfMonth;
let spm = secondsPerMonth(now.getFullYear(), now.getMonth() + 1);
let mperc = elapsedM / 1000 / spm;
mperc = Math.round(mperc * 1000000) / 10000;
mpp.innerHTML = mperc + "%";
mbar.style.width = def_with * mperc / 100 + "vw";
//calculate percentage for day
let startOfDay = new Date();
startOfDay.setHours(0);
startOfDay.setMinutes(0);
startOfDay.setSeconds(0);
startOfDay.setMilliseconds(0);
let elapsedD = now - startOfDay;
let dperc = elapsedD / 1000 / 86400;
dperc = Math.round(dperc * 100000) / 1000;
dpp.innerHTML = dperc + "%";
dbar.style.width = def_with * dperc / 100 + "vw";
//calculate percentage for hour
let startOfHour = new Date();
startOfHour.setMinutes(0);
startOfHour.setSeconds(0);
startOfHour.setMilliseconds(0);
let elapsedH = now - startOfHour;
let hperc = elapsedH / 1000 / 3600;
hperc = Math.round(hperc * 10000) / 100;
hpp.innerHTML = hperc + "%";
hbar.style.width = def_with * hperc / 100 + "vw";
//calculate percentage for minute
let startOfMinute = new Date();
startOfMinute.setSeconds(0);
startOfMinute.setMilliseconds(0);
let elapsedMi = now - startOfMinute;
let miperc = elapsedMi / 1000 / 60;
miperc = Math.round(miperc * 1000) / 10;
mipp.innerHTML = miperc + "%";
mibar.style.width = def_with * miperc / 100 + "vw";
}, 1000);
///////////////////////////
//Settings
set_btn.addEventListener("click", e => {
if (exp) {
set_btn.style.right = "1vh";
set_btn.style.color = "var(--dark)";
abt.style.left = "120vw";
abt.style.top = "-100vh";
exp = false;
} else {
set_btn.style.right = "30vh";
set_btn.style.color = "var(--bright)";
abt.style.left = "calc(100vw - 40vh)";
abt.style.top = "-40vh";
exp = true;
}
});
///////////////////////////
//Darkmode
if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
) {
root.style.setProperty("--bright", "#000");
root.style.setProperty("--dark", "#fff");
dm_btn.innerHTML = "🌖";
dm = false;
} else {
root.style.setProperty("--bright", "#fff");
root.style.setProperty("--dark", "#000");
dm_btn.innerHTML = "🌘";
dm = true;
}
dm_btn.addEventListener("click", e => {
if (dm) {
root.style.setProperty("--bright", "#000");
root.style.setProperty("--dark", "#fff");
dm_btn.innerHTML = "🌖";
dm = false;
} else {
root.style.setProperty("--bright", "#fff");
root.style.setProperty("--dark", "#000");
dm_btn.innerHTML = "🌘";
dm = true;
}
});
///////////////////////////
//Helper Functions
function secondsPerYear(year) {
if (leapYear(year)) {
return 31622400;
} else {
return 31536000;
}
}
function leapYear(year) {
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
function secondsPerMonth(y, m) {
let spm = new Date(y, m, 0).getDate() * 24 * 3600;
return spm;
}
Also see: Tab Triggers