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.
<div class="container">
<!-- SVG shadow effect filter created with the 'PhotoShop DropShadows Using SVG Filters' tool created by Michael Mullany https://codepen.io/mullany/pen/xxPOoX -->
<svg width="278" height="89" viewBox="0 0 278 89" fill="none" xmlns="http://www.w3.org/2000/svg">
<defs>
<clipPath id="cutoff" width="278" height="89">
<path fill-rule="evenodd" clip-rule="evenodd" d="M138.667 8C81.866 8 32.5209 39.9483 7.63237 86.8742C6.59727 88.8259 4.17604 89.5688 2.22442 88.5337C0.272787 87.4986 -0.470204 85.0774 0.5649 83.1258C26.7857 33.688 78.7889 0 138.667 0C198.545 0 250.548 33.688 276.769 83.1258C277.804 85.0774 277.061 87.4986 275.109 88.5337C273.157 89.5688 270.736 88.8259 269.701 86.8742C244.812 39.9483 195.467 8 138.667 8Z"/>
</clipPath>
</defs>
<filter id="big-shadow">
<!-- Take source alpha, offset it by angle/distance and blur it by size -->
<feOffset id="offset" in="SourceAlpha" dx="0" dy="0" result="SA-offset" />
<feGaussianBlur id="blur" in="SA-offset" stdDeviation="40" result="SA-o-blur" />
<!-- Apply a contour by using a color curve transform on the alpha and clipping the result to the input -->
<feComponentTransfer in="SA-o-blur" result="SA-o-b-contIN">
<feFuncA id="contour" type="table" tableValues="0 40" />
</feComponentTransfer>
<feComposite operator="in" in="SA-o-blur" in2="SA-o-b-contIN" result="SA-o-b-cont" />
<!-- Adjust the spread by multiplying alpha by a constant factor -->
<feComponentTransfer in="SA-o-b-cont" result="SA-o-b-c-sprd">
<feFuncA id="spread-ctrl" type="linear" slope="11" />
</feComponentTransfer>
<!-- Adjust color and opacity by adding fixed offsets and an opacity multiplier -->
<feColorMatrix id="recolor" in="SA-o-b-c-sprd" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0" result="SA-o-b-c-s-recolor" />
<!-- Generate a reasonably grainy noise input with baseFrequency between approx .5 to 2.0. And add the noise with k1 and k2 multipliers that sum to 1 -->
<feTurbulence result="fNoise" type="fractalNoise" numOctaves="6" baseFrequency="1.98" />
<feColorMatrix in="fNoise" type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 7 -3" result="clipNoise" />
<feComposite id="noisemix" operator="arithmetic" in="SA-o-b-c-s-recolor" in2="clipNoise" k1="0" k2="1" result="SA-o-b-c-s-r-mix" />
<!-- Merge the shadow with the original -->
<feMerge>
<feMergeNode in="SA-o-b-c-s-r-mix" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
<path id="chart-path" d="M4.09863 85C29.6533 36.8181 80.3275 4 138.667 4C197.006 4 247.68 36.8181 273.235 85" stroke="#62676F" stroke-width="8" stroke-linecap="round" />
<path id="chart-progress" d="M4.09863 85C29.6533 36.8181 80.3275 4 138.667 4C197.006 4 247.68 36.8181 273.235 85" stroke="#FCBC2C" stroke-width="8" stroke-linecap="round" filter="url(#big-shadow)" clip-path="url(#cutoff)" />
</svg>
<div class="balance-container">
<span class="label">Available to spend</span>
<span class="amount">£<span class="countup" data-end-value="1000000" data-duration="1200"></span>
</span>
</div>
</div>
<div class="container">
<svg width="278" height="89" viewBox="0 0 278 89" fill="none" xmlns="http://www.w3.org/2000/svg">
<defs>
<clipPath id="cutoff" width="278" height="89">
<path fill-rule="evenodd" clip-rule="evenodd" d="M138.667 8C81.866 8 32.5209 39.9483 7.63237 86.8742C6.59727 88.8259 4.17604 89.5688 2.22442 88.5337C0.272787 87.4986 -0.470204 85.0774 0.5649 83.1258C26.7857 33.688 78.7889 0 138.667 0C198.545 0 250.548 33.688 276.769 83.1258C277.804 85.0774 277.061 87.4986 275.109 88.5337C273.157 89.5688 270.736 88.8259 269.701 86.8742C244.812 39.9483 195.467 8 138.667 8Z"/>
</clipPath>
</defs>
<filter id="big-shadow">
<!-- Take source alpha, offset it by angle/distance and blur it by size -->
<feOffset id="offset" in="SourceAlpha" dx="0" dy="0" result="SA-offset" />
<feGaussianBlur id="blur" in="SA-offset" stdDeviation="40" result="SA-o-blur" />
<!-- Apply a contour by using a color curve transform on the alpha and clipping the result to the input -->
<feComponentTransfer in="SA-o-blur" result="SA-o-b-contIN">
<feFuncA id="contour" type="table" tableValues="0 40" />
</feComponentTransfer>
<feComposite operator="in" in="SA-o-blur" in2="SA-o-b-contIN" result="SA-o-b-cont" />
<!-- Adjust the spread by multiplying alpha by a constant factor -->
<feComponentTransfer in="SA-o-b-cont" result="SA-o-b-c-sprd">
<feFuncA id="spread-ctrl" type="linear" slope="11" />
</feComponentTransfer>
<!-- Adjust color and opacity by adding fixed offsets and an opacity multiplier -->
<feColorMatrix id="recolor" in="SA-o-b-c-sprd" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0" result="SA-o-b-c-s-recolor" />
<!-- Generate a reasonably grainy noise input with baseFrequency between approx .5 to 2.0. And add the noise with k1 and k2 multipliers that sum to 1 -->
<feTurbulence result="fNoise" type="fractalNoise" numOctaves="6" baseFrequency="1.98" />
<feColorMatrix in="fNoise" type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 7 -3" result="clipNoise" />
<feComposite id="noisemix" operator="arithmetic" in="SA-o-b-c-s-recolor" in2="clipNoise" k1="0" k2="1" result="SA-o-b-c-s-r-mix" />
<!-- Merge the shadow with the original -->
<feMerge>
<feMergeNode in="SA-o-b-c-s-r-mix" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
<path id="chart-path" d="M4.09863 85C29.6533 36.8181 80.3275 4 138.667 4C197.006 4 247.68 36.8181 273.235 85" stroke="#62676F" stroke-width="8" stroke-linecap="round" />
<path id="chart-progress1" d="M4.09863 85C29.6533 36.8181 80.3275 4 138.667 4C197.006 4 247.68 36.8181 273.235 85" stroke="#2DB023" stroke-width="8" stroke-linecap="round" filter="url(#big-shadow)" clip-path="url(#cutoff)" />
<path id="chart-progress2" d="M4.09863 85C29.6533 36.8181 80.3275 4 138.667 4C197.006 4 247.68 36.8181 273.235 85" stroke="#FCBC2C" stroke-width="8" stroke-linecap="round" filter="url(#big-shadow)" clip-path="url(#cutoff)" />
</svg>
<div class="balance-container">
<span class="label">Available to spend</span>
<span class="amount2">£<span class="countup" data-end-value="1000000" data-duration="1200"></span>
</span>
</div>
</div>
<div class="toggle-switch">
<input type="checkbox" id="animation-toggle" name="animation-toggle" checked>
<label for="animation-toggle">Couting up animation</label>
</div>
<button id="restart-button" class="restart-btn">Restart Animations</button>
@import url('https://fonts.googleapis.com/css2?family=Epilogue:wght@500;700&family=Inter:wght@300;400;500&display=swap');
body {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
width: auto;
height: 100vh;
background-color: #000813;
}
.container {
display: flex;
align-items: center;
justify-content: center;
width: auto;
padding: 32px;
}
svg {
fill: none;
position: absolute;
z-index: -1;
}
.balance-container {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 64px;
}
.label {
font-family: "Inter", sans-serif;
font-style: normal;
font-weight: 400;
font-size: 14px;
line-height: 20px;
text-align: center;
color: #b3b5b9;
margin-bottom: 4px;
}
.amount,
.amount2 {
font-family: 'Epilogue', sans-serif;
font-weight: 700;
font-size: 18px;
line-height: 24px;
font-style: normal;
color: #fcbc2c;
transition: opacity 1.2s linear;
&.amount2 {
color: #fff;
}
.countup {
font-weight: 300;
font-size: 32px;
line-height: 40px;
}
.integer-part {
/* Inherit from the countup style */
}
.decimal-part {
font-weight: 500;
font-size: 18px;
line-height: 24px;
}
}
.restart-btn {
padding: 10px 20px;
margin-top: 20px;
background-color: #fff;
border: none;
border-radius: 999px;
color: #000814;
font-family: "Inter", sans-serif;
cursor: pointer;
}
.toggle-switch {
margin: 20px;
display: flex;
align-items: center;
color: #fff;
}
.toggle-switch input[type="checkbox"] {
margin-right: 10px;
}
// progressbar.js@1.0.0 version is used
// Docs: http://progressbarjs.readthedocs.org/en/1.0.0/
// Initialize Progress Bars
var path1 = new ProgressBar.Path(document.getElementById('chart-progress'), { duration: 3000, easing: 'easeInOut' });
var path2 = new ProgressBar.Path(document.getElementById('chart-progress1'), { duration: 3000, easing: 'easeInOut' });
var path3 = new ProgressBar.Path(document.getElementById('chart-progress2'), { duration: 3000, easing: 'easeInOut' });
// Set the percentage completeness for the progress bars
function initializeProgressBars() {
path1.set(0); path1.animate(0.8);
path2.set(0); path2.animate(1);
path3.set(0); path3.animate(0.3);
}
// Check if the countingup animation is to be applied
function applyCurrentAnimation() {
if (document.getElementById('animation-toggle').checked) {
restartCountUpAnimation();
} else {
restartFadeInAnimation();
}
}
// Restart the animations when called
function restartAnimations() {
initializeProgressBars();
if (document.getElementById('animation-toggle').checked) {
restartCountUpAnimation();
} else {
restartFadeInAnimation();
}
}
function restartCountUpAnimation() {
document.querySelectorAll('.countup').forEach(el => {
// Set the end value is 1000000, duration is 1200ms, and 2 decimal places
animateCountUp(el, 0, 150000, 3000, 2);
});
}
function restartFadeInAnimation() {
document.querySelectorAll('.amount, .amount2').forEach(el => {
el.style.opacity = 0;
setTimeout(() => {
el.style.opacity = 1;
}, 100); // The transition will apply here
});
}
// Listen for when the restart animation button is pressed
document.getElementById('restart-button').addEventListener('click', restartAnimations);
window.onload = function() {
initializeProgressBars();
if (document.getElementById('animation-toggle').checked) {
restartCountUpAnimation();
}
};
// Apply commas to large numbers to two decimal places
function numberWithCommas(x) {
return x.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
// Animate the amount to count up
// Animate the amount to count up with ease-in-out
function animateCountUp(el, start, end, duration, decimalPlaces = 2) {
let startTime = null;
// Ease-in-out cubic function
function easeInOutCubic(t) {
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function update(currentTime) {
if (!startTime) startTime = currentTime;
const elapsedTime = currentTime - startTime;
const progress = easeInOutCubic(elapsedTime / duration);
const current = start + (end - start) * progress;
const currentDisplay = Math.min(current, end);
// Update the element's content
let parts = numberWithCommas(Number(currentDisplay.toFixed(decimalPlaces))).split('.');
el.innerHTML = `<span class="integer-part">${parts[0]}</span>.<span class="decimal-part">${parts[1]}</span>`;
// Continue the animation as long as elapsedTime is less than duration
if (elapsedTime < duration) {
requestAnimationFrame(update);
}
}
requestAnimationFrame(update);
}
Also see: Tab Triggers