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.
<h1>Animated Graphs</h1>
<h2>Scroll Triggered, Responsive, Data-driven</h2>
<p> </p>
<div class="chartBarsWrap">
<div class="chartBars chartBars1">
<ul class="numbers">
<li><span>100%</span></li>
<li><span>80%</span></li>
<li><span>60%</span></li>
<li><span>40%</span></li>
<li><span>20%</span></li>
<li><span>0%</span></li>
</ul>
<ul class="bars">
<li>
<span class="tooltip">
<span class="tooltipContent">Very important info that you should read!</span>
<div data-percentage="52" class="bar greenBar trigger"></div>
</span>
<b>Alpha</b>
</li>
<li>
<span class="tooltip">
<span class="tooltipContent">This one is trending well.</span>
<div data-percentage="83" class="bar blueBar trigger"></div>
</span>
<b>Beta</b>
</li>
<li>
<span class="tooltip">
<span class="tooltipContent">I like cheese!</span>
<div data-percentage="94" class="bar orangeBar trigger"></div>
</span>
<b>Gamma</b>
</li>
<li>
<span class="tooltip">
<span class="tooltipContent">Monkey's are funny!</span>
<div data-percentage="64" class="bar purpleBar trigger"></div>
</span>
<b>Delta</b>
</li>
</ul>
</div>
</div>
<p>Bacon ipsum do lor amet porchetta jowl jerky short loin, tri-tip flank c ow. Strip steak meat ball picanha t-bone pork loin filet mignon, pancetta jerky kielba sa sirloin ball t ip hamburger turkey pork belly ham hock. Chicken swine tail s pa re ribs,pork loin tongue picanha strip steak ribeye pancetta bresaola landjaeger flank ham shank. Picanha t-bone meatball, corned beef tail tri-tip flank capicola alcatra spare ribs. Flank tail pork loin pork belly sirloin tri-tip.</p>
<h3>Responsive? Yep.</h3>
<div class="chartBarsWrap">
<div class="chartBars chartBars2">
<ul class="numbers">
<li><span>100%</span></li>
<li><span>80%</span></li>
<li><span>60%</span></li>
<li><span>40%</span></li>
<li><span>20%</span></li>
<li><span>0%</span></li>
</ul>
<ul class="bars">
<li>
<div data-percentage="92" class="bar greenBar trigger"></div><b>Alpha</b></li><li>
<div data-percentage="33" class="bar orangeBar trigger"></div><b>Beta</b></li>
<li>
<div data-percentage="64" class="bar blueBar trigger"></div><b>Gamma</b></li>
<li>
<div data-percentage="44" class="bar purpleBar trigger"></div>
<b>Delta</b></li>
</ul>
</div>
</div>
<p>Bacon ipsum do lor amet porchetta jowl jerky short loin, tri-tip flank c ow. Strip steak meat ball picanha t-bone pork loin filet mignon, pancetta jerky kielba sa sirloin ball t ip hamburger turkey pork belly ham hock. Chicken swine tail s pa re ribs, pork loin tongue picanha strip steak ribeye pancetta bresaola landjaeger flank ham shank. Picanha t-bone meatball, corned beef tail tri-tip flank capicola alcatra spare ribs. Flank tail pork loin pork belly sirloin tri-tip. Bresaola salmi.</p>
<h3>Radial Graphs</h3>
<div class="box-piesite">
<ul>
<li class="design">
<div class="piesite" id="pie_0" data-pie="82"></div>
</li>
<li class="usability">
<div class="piesite" id="pie_2" data-pie="55"></div>
</li>
<li class="creativity">
<div class="piesite" id="pie_1" data-pie="33"></div>
</li>
</ul>
</div>
<p>Bacon ipsum do lor amet porchetta jowl jerky short loin, tri-tip flank c ow. Strip steak meat ball picanha t-bone pork loin filet mignon, pancetta jerky kielba sa sirloin ball t ip hamburger turkey pork belly ham hock. Chicken swine tail s pa re ribs,pork loin tongue picanha strip steak ribeye pancetta bresaola landjaeger flank ham shank. Picanha t-bone meatball, corned beef tail tri-tip flank capicola alcatra spare ribs. Flank tail pork loin pork belly sirloin tri-tip..</p>
<!-- <p> </p> -->
<h3>Horizontal</h3>
<div class="chartBarsWrap chartBarsHorizontal">
<div class="chartBars">
<ul class="bars">
<li>
<div data-percentage="92" class="bar greenBarFlat"></div><b>Alpha</b></li>
<li>
<div data-percentage="33" class="bar orangeBarFlat"></div><b>Beta</b></li>
<li>
<div data-percentage="64" class="bar blueBarFlat"></div><b>Gamma</b></li>
<li>
<div data-percentage="44" class="bar purpleBarFlat"></div><b>Delta</b></li>
</ul>
</div>
</div>
<p>Bacon ipsum do lor amet porchetta jowl jerky short loin, tri-tip flank c ow. Strip steak meat ball picanha t-bone pork loin filet mignon, pancetta jerky kielba sa sirloin ball t ip hamburger turkey pork belly ham hock. Chicken swine tail s pa re ribs,pork loin tongue picanha strip steak ribeye pancetta bresaola landjaeger flank ham shank.</p>
<h3>Just add more bars, they sqeeze in. Sweet!</h3>
<div class="chartBarsWrap">
<div class="chartBars chartBars3">
<ul class="numbers">
<li><span>100%</span></li>
<li><span>80%</span></li>
<li><span>60%</span></li>
<li><span>40%</span></li>
<li><span>20%</span></li>
<li><span>0%</span></li>
</ul>
<ul class="bars">
<li><div data-percentage="92" class="bar greenBar trigger"></div><b>Alpha</b></li>
<li><div data-percentage="33" class="bar blueBar trigger"></div><b>Beta</b></li>
<li><div data-percentage="64" class="bar orangeBar trigger"></div><b>Gamma</b></li>
<li><div data-percentage="41" class="bar purpleBar trigger"></div><b>Delta</b></li>
<li><div data-percentage="52" class="bar greenBar trigger"></div><b>Epsilon</b></li>
<li><div data-percentage="58" class="bar blueBar trigger"></div><b>Zeta</b></li>
<li><div data-percentage="65" class="bar orangeBar trigger"></div><b>Eta</b></li>
<li><div data-percentage="91" class="bar purpleBar trigger"></div><b>Theta</b></li>
<li><div data-percentage="32" class="bar greenBar trigger"></div><b>Iota</b></li>
<li><div data-percentage="68" class="bar blueBar trigger"></div><b>Kappa</b></li>
</ul>
</div>
</div>
<p>Bacon ipsum do lor amet porchetta jowl jerky short loin, tri-tip flank c ow. Strip steak meat ball picanha t-bone pork loin filet mignon, pancetta jerky kielba sa sirloin ball t ip hamburger turkey pork belly ham hock. Chicken swine tail s pa re ribs,pork loin tongue picanha strip steak ribeye pancetta bresaola landjaeger flank ham shank.</p>
////////////////////////////////////////////////////
// The Bar Graphs
////////////////////////////////////////////////////
.chartBarsWrap {
// This wrapper is for padding the leftside numbers *mobile*
padding-left: 40px;
margin: 0 30px 0 20px;
}
.chartBars {
position: relative;
max-width: 600px;
height: 300px;
margin: 50px auto 100px;
.bars {
display: flex;
justify-content: space-around;
border-left: 1px solid #bbb;
border-bottom: 1px solid #bbb;
width: 100%;
height: 100%;
padding: 0;
padding: 0 1%;
margin: 0;
li {
display: inline-block;
flex: 0 1 24%;
height: 100%;
margin: 0;
text-align: center;
position: relative;
font-size: 16px;
.bar {
width: 100%;
background: #49E;
position: absolute;
font-size: 1.5em;
color: #fff;
padding-top: 18px;
bottom: 0;
height: 0;
overflow: hidden;
font-weight: bold;
outline: 2px solid transparent;
-webkit-transition: 1.5s height cubic-bezier(.6, .4, .4, 1.1);
transition: 1.5s height cubic-bezier(.6, .4, .4, 1.1);
&:after {
content: '%';
font-size: 22px !important;
vertical-align: top;
color: rgba(255, 255, 255, .8);
margin-right: -8px;
}
&:hover {
}
}
b {
color: #eee;
width: 100%;
position: absolute;
bottom: -2em;
left: 0;
text-align: center;
}
}
}
.numbers {
width: 50px;
height: 100%;
margin: 0;
padding: 0;
display: inline-block;
position: absolute;
left: -50px;
li {
text-align: right;
padding-right: 1em;
list-style: none;
height: 59px;
position: relative;
font-size: 13px;
bottom: 11px;
right: -9px;
color: #eee;
&:after {
content: "\00af";
position: relative;
right: -5px;
font-size: 20px;
top: 7px;
color: rgba(255, 255, 255, 0.34);
}
&:first-of-type {
height: 63px;
margin-top: -1px;
}
}
}
}
////////////////////////////////////
// Individual Chart Styles
.chartBars1 .bar {
border-top-right-radius: 30px;
}
.chartBars2 {
max-width: 350px;
.bars {
padding: 0;
li {
flex: 0 1 25%;
.bar {
box-shadow: 0 0 20px #222;
}
}
}
}
.chartBars3 {
background: rgba(255, 255, 255, .1);
border-top: 1px solid #666;
border-right: 1px solid #666;
.bars {
border-color: #666;
padding: 0;
li .bar {
border-top-right-radius: 3px;
border-top-left-radius: 3px;
font-size: 22px !important;
&:after {
font-size: .6em !important;
}
}
}
}
.chartBarsWrap.chartBarsHorizontal {
flex-direction: column;
padding-left: 70px;
.bars b {
color: #eee;
width: 100%;
position: absolute;
bottom: initial;
top: 1em;
left: -102%;
text-align: right;
}
.chartBars {
height: 200px;
}
.chartBars .bars {
border: 0;
.bar {
width: 0;
padding-top: 10px;
height: 100% !important;
text-align: right;
font-size: 1.5em;
-webkit-transition: 2s width cubic-bezier(0.6, 0.4, 0.4, 1.1);
transition: 2s width cubic-bezier(0.6, 0.4, 0.4, 1.1);
&:after {
font-size: .6em !important;
margin-right: 20px;
}
}
}
}
////////////////////////////////////////////////////
// Colors
////////////////////////////////////////////////////
@lighten-percentage: 15%;
@green: #6B8E23;
@lightgreen: lighten(@green, @lighten-percentage);
@blue: #49E;
@lightblue: lighten(@blue, @lighten-percentage);
@orange: #FFA500;
@lightorange: lighten(@orange, @lighten-percentage);
@purple: #6e46af;
@lightpurple: lighten(@purple, @lighten-percentage);
.bars li .bar.greenBar {
background-color: #6B8E23;
background: radial-gradient(@lightgreen, @green);
}
.bars li .bar.greenBarFlat {
background-color: #6B8E23;
}
.bars li .bar.blueBar {
background-color: #49E;
background: radial-gradient(@lightblue, @blue);
}
.bars li .bar.blueBarFlat {
background-color: #49E;
}
.bars li .bar.orangeBar {
background-color: orange;
background: radial-gradient(@lightorange, @orange);
}
.bars li .bar.orangeBarFlat {
background-color: orange;
}
.bars li .bar.purpleBar {
background-color: #6e46af;
background: radial-gradient(@lightpurple, @purple);
}
.bars li .bar.purpleBarFlat {
background-color: #6e46af;
}
////////////////////////////////////////////////////
// Pie Charts
////////////////////////////////////////////////////
// https://codepen.io/StephenScaff/pen/VYaQGB
// by Stephen Scaff
.box-piesite {
text-align: center;
font-size: 22px;
}
.piesite {
position: relative;
width: 1em;
height: 1em;
font-size: 10em;
cursor: default;
}
.piesite .percent {
position: absolute;
top: 1.1em;
left: .1em;
width: 100%;
font-size: .3em;
text-align: center;
z-index: 2;
.symbol {
font-size: .5em;
vertical-align: top;
opacity: .5;
}
}
.piesite > #slice {
position: absolute;
width: 1em;
height: 1em;
clip: rect(0px, 1em, 1em, 0.5em);
}
.piesite > #slice.gt50 {
clip: rect(auto, auto, auto, auto);
}
.piesite > #slice > .pie {
position: absolute;
border: .1em solid #444;
width: 1em;
height: 1em;
clip: rect(0em, 0.5em, 1em, 0em);
border-radius: 0.5em;
}
li.design .piesite > #slice > .pie {
border-color: #49E;
}
li.usability .piesite > #slice > .pie {
border-color: #FFA500;
}
li.creativity .piesite > #slice > .pie {
border-color: #6B8E23;
}
.piesite > #slice > .pie.fill {
-webkit-transform: rotate(180deg) !important;
transform: rotate(180deg) !important;
}
.piesite.fill > .percent {
display: none;
}
.piesite:after {
content: '';
display: block;
position: absolute;
top: .1em;
left: .1em;
width: .8em;
height: .8em;
background: #30303A;
border-radius: 100%;
z-index: 1;
}
.piesite:before {
content: '';
display: block;
position: absolute;
width: 1em;
height: 1em;
border-radius: .5em;
opacity: .5;
z-index: 0;
}
.piesite:before {
background: rgba(255, 255, 255, 0.1);
}
.box-piesite ul {
padding: 0;
li {
display: inline-block;
margin: 10px 20px;
}
}
.chartBarsHorizontal .chartBars .bars {
flex-direction: column;
}
////////////////////////////////////////////////////
// Media Queries
////////////////////////////////////////////////////
@media screen and (min-width: 600px) {
.bar:before {
font-size: 2em !important;
}
.chartBars3 .bar:before {
font-size: 1.5em !important;
}
}
////////////////////////////////////////////////////
// Tooltips
////////////////////////////////////////////////////
.tooltip {
// position: relative;
& > .tooltipContent {
display: block;
position: absolute;
background: none repeat scroll 0 0 #222;
color: #F0B015;
font-family: 'Helvetica';
font-size: 0.8em;
font-weight: normal;
line-height: 1.5em;
padding: 16px 15px;
min-width: 200px;
max-width: 500px;
top: 0;
left: 50%;
transform: translate(-50%, -110%);
margin-left: 0;
opacity: 0;
filter: alpha(opacity=0);
text-align: center;
z-index: 2;
text-transform: none;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease;
transition: all 0.3s ease-in-out;
}
&:hover > .tooltipContent {
opacity: 1;
filter: alpha(opacity=100);
z-index: 99;
transform: translate(-50%, -130%);
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
transition: all 0.2s ease;
}
& .tooltipContent:after {
border-color: #222 rgba(0, 0, 0, 0);
border-style: solid;
border-width: 15px 15px 0;
bottom: -15px;
content: "";
display: block;
left: 50%;
transform: translate(-50%, 0);
position: absolute;
width: 0;
}
}
////////////////////////////////////////////////////
// layout extras
////////////////////////////////////////////////////
* {
box-sizing: border-box;
}
body {
background: #30303A;
font-family: 'Quicksand', sans-serif;
color: #ddd;
}
h1, h2, h3 {
text-align: center;
}
h1 {
margin: 100px auto 0;
color: #F0B015;
}
h2 {
margin: 20px auto 0;
font-size: 1.2em;
}
p {
margin: 5vw auto;
padding: 0 5vw;
line-height: 2em;
max-width: 60em;
}
var piesiteFired = 0;
$(document).ready(function() {
var $win = $(window),
$win_height = $(window).height(),
// - A multiple of viewport height - The higher this number the sooner triggered.
windowPercentage = $(window).height() * 0.9;
$win.on("scroll", scrollReveal);
function scrollReveal() {
var scrolled = $win.scrollTop();
///////////////////////////////////////
// Bar Charts scroll activate, looking for .trigger class to fire.
$(".trigger").each(function() {
var $this = $(this),
offsetTop = $this.offset().top;
if (
scrolled + windowPercentage > offsetTop ||
$win_height > offsetTop
) {
$(this).each(function(key, bar) {
var percentage = $(this).data("percentage");
$(this).css("height", percentage + "%");
///////////////////////////////////////
// Animated numbers
$(this).prop("Counter", 0).animate(
{
Counter: $(this).data("percentage")
},
{
duration: 2000,
easing: "swing",
step: function(now) {
$(this).text(Math.ceil(now));
}
}
);
// Animated numbers
///////////////////////////////////////
});
} else {
///////////////////////////////////////
// To keep them triggered, lose this block.
$(this).each(function(key, bar) {
$(this).css("height", 0);
});
}
});
///////////////////////////////////////
// Horizontal Chart
$(".chartBarsHorizontal .bar").each(function() {
var $this = $(this),
offsetTop = $this.offset().top;
if (
scrolled + windowPercentage > offsetTop ||
$win_height > offsetTop
) {
$(this).each(function(key, bar) {
var percentage = $(this).data("percentage");
$(this).css("width", percentage + "%");
///////////////////////////////////////
// Animated numbers
$(this).prop("Counter", 0).animate(
{
Counter: $(this).data("percentage")
},
{
duration: 2000,
easing: "swing",
step: function(now) {
$(this).text(Math.ceil(now));
}
}
);
// Animated numbers
///////////////////////////////////////
});
} else {
///////////////////////////////////////
// To keep them triggered, lose this block.
$(this).each(function(key, bar) {
$(this).css("width", 0);
});
}
});
///////////////////////////////////////
// Radial Graphs - scroll activate
$(".piesite").each(function() {
var $this = $(this),
offsetTop = $this.offset().top;
if (
scrolled + windowPercentage > offsetTop ||
$win_height > offsetTop
) {
if (piesiteFired == 0) {
timerSeconds = 3;
timerFinish = new Date().getTime() + timerSeconds * 1000;
$(".piesite").each(function(a) {
pie = $("#pie_" + a).data("pie");
timer = setInterval(
"stoppie(" + a + ", " + pie + ")",
0
);
});
piesiteFired = 1;
}
} else {
// To keep them triggered, lose this block.
$(".piesite").each(function() {
piesiteFired = 0;
});
}
});
}
scrollReveal();
});
///////////////////////////////////////
// The Radial Graphs
///////////////////////////////////////
// The following code is originally from the excellent pen:
// https://codepen.io/StephenScaff/pen/VYaQGB by Stephen Scaff
var timer;
var timerFinish;
var timerSeconds;
function drawTimer(c, a) {
$("#pie_" + c).html(
'<div class="percent"></div><div id="slice"' +
(a > 50 ? ' class="gt50"' : "") +
'><div class="pie"></div>' +
(a > 50 ? '<div class="pie fill"></div>' : "") +
"</div>"
);
var b = 360 / 100 * a;
$("#pie_" + c + " #slice .pie").css({
"-moz-transform": "rotate(" + b + "deg)",
"-webkit-transform": "rotate(" + b + "deg)",
"-o-transform": "rotate(" + b + "deg)",
transform: "rotate(" + b + "deg)"
});
a = Math.floor(a * 100) / 100;
arr = a.toString().split(".");
intPart = arr[0];
$("#pie_" + c + " .percent").html(
'<span class="int">' +
intPart +
"</span>" +
'<span class="symbol">%</span>'
);
}
function stoppie(d, b) {
var c = (timerFinish - new Date().getTime()) / 1000;
var a = 100 - c / timerSeconds * 100;
a = Math.floor(a * 100) / 100;
if (a <= b) {
drawTimer(d, a);
} else {
b = $("#pie_" + d).data("pie");
arr = b.toString().split(".");
$("#pie_" + d + " .percent .int").html(arr[0]);
}
}
Also see: Tab Triggers