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.
<header>
<div class="spinner" data-options="large blue" style="background-color:#eee" role="progressbar" aria-valuetext="Loading…"></div>
<h1>Simple <br><code><paper-spinner></code></h1>
<p>Intrigued by Keanu Lee's brilliant <a href="//blog.keanulee.com/2014/10/20/the-tale-of-three-spinners.html">article</a> describing how he built the official <a href="//polymer.github.io/paper-spinner/components/paper-spinner/demo.html"><code><paper-spinner></code> Polymer element</a> seen in the <a href="//www.google.com/design/spec/components/progress-activity.html">Google Material Design spec</a>, I had to see if it was possible to simplify the spinner further by condensing it down to a single HTML element. My goal was to rebuild the paper-spinner in a way that was:</p>
<ul>
<li>Accessible ✓</li>
<li>Cross browser compatible (IE10+) ✓<a href="#note-1">*</a></li>
<li>A single HTML element ✓</li>
<li>HTML and CSS only ✓</li>
<li>Uses relative units for easy scalability ✓</li>
<li>Animated with strictly composite properties (<code>transform</code> and <code>opacity</code>) ✓<a href="#note-2">**</a></li>
</ul>
<p>Well…I got really close. Check it out. (Pull requests are more than welcome.)</p>
</header>
<main>
<h2>Default</h2>
<div class="spinner" role="progressbar" aria-valuetext="Loading…"></div>
<pre><code><mark><div class="spinner" role="progressbar" aria-valuetext="Loading…"></div></mark></code></pre>
<h2>Preset colors</h2>
<div class="spinner" data-options="blue" role="progressbar" aria-valuetext="Loading…"></div>
<div class="spinner" data-options="red" role="progressbar" aria-valuetext="Loading…"></div>
<div class="spinner" data-options="yellow" role="progressbar" aria-valuetext="Loading…"></div>
<div class="spinner" data-options="green" role="progressbar" aria-valuetext="Loading…"></div>
<pre><code><div class="spinner" <mark>data-options="blue"</mark> role="progressbar" aria-valuetext="Loading…"></div></code></pre>
<h2>Preset sizes</h2>
<div class="spinner" role="progressbar" aria-valuetext="Loading…"></div>
<br>
<div class="spinner" data-options="large" role="progressbar" aria-valuetext="Loading…"></div>
<br>
<div class="spinner" data-options="xlarge" role="progressbar" aria-valuetext="Loading…"></div>
<pre><code><div class="spinner" <mark>data-options="large"</mark> role="progressbar" aria-valuetext="Loading…"></div></code></pre>
<h2>Completely custom</h2>
<div class="spinner" data-options="blue" style="font-size:71px;box-shadow: inset 0 0 0 2px" role="progressbar" aria-valuetext="Loading…"></div>
<br>
<div class="spinner" data-options="red" style="box-shadow:inset 0 0 0 1px" role="progressbar" aria-valuetext="Loading…"></div>
<div class="spinner" data-options="yellow" style="box-shadow:inset 0 0 0 6px" role="progressbar" aria-valuetext="Loading…"></div>
<div class="spinner" style="color:#f06;background-color:#afa" role="progressbar" aria-valuetext="Loading…"></div>
<div class="spinner" data-options="blue" style="box-shadow:inset 0 0 0 .1875em,inset 0 0 0 .375em #db4437,inset 0 0 0 .5625em #f4b400,inset 0 0 0 .75em #0f9d58" role="progressbar" aria-valuetext="Loading…"></div>
<pre><code><div class="spinner" data-options="blue" <mark>style="font-size:71px;box-shadow:inset 0 0 0 2px"</mark> role="progressbar" aria-valuetext="Loading…"></div></code></pre>
<h2>Multicolor</h2>
<button class="toggle-multicolor">Toggle multicolor (invokes repaints)</button>
<br>
<div class="spinner is-active" data-options="multicolor" role="progressbar" aria-valuetext="Loading…"></div>
<pre><code><div class="spinner" <mark>data-options="multicolor"</mark> role="progressbar" aria-valuetext="Loading…"></div></code></pre>
<h2>How it's done</h2>
<div class="spinner" data-options="debug debug--1" role="progressbar" aria-valuetext="Loading…"></div>
<br>
<div class="spinner" data-options="debug debug--2" role="progressbar" aria-valuetext="Loading…"></div>
<div class="spinner" data-options="debug debug--3" role="progressbar" aria-valuetext="Loading…"></div>
<div class="spinner is-active" data-options="multicolor debug debug--4" role="progressbar" aria-valuetext="Loading…"></div>
<h2>Outstanding resources</h2>
<ul>
<li><a href="//csstriggers.com/">csstriggers.com</a></li>
<li><a href="//github.com/Polymer/paper-spinner">github.com (<paper-spinner>)</a></li>
<li><a href="//www.html5rocks.com/en/tutorials/speed/high-performance-animations/">html5rocks.com (high performance animations)</a></li>
<li><a href="//www.paulirish.com/2012/why-moving-elements-with-translate-is-better-than-posabs-topleft/">paulirish.com (translate animations)</a></li>
<li><a href="//developer.mozilla.org/en-US/docs/Web/CSS/transform">MDN (transform)</a></li>
<li><a href="//stackoverflow.com/questions/16234269/css-keyframed-animation-jumpy-in-ie10">stackoverflow.com (IE10 bug)</a></li>
</ul>
<hr>
<p id="note-1">*I use <code>clip-path: circle()</code>, which is not available in IE or Firefox, as a progressive enhancement only to remove small artifacts left over from the animations.</p>
<p id="note-2">**All spinners animate with composite properties except the multicolor spinner. The multicolor spinner unfortunately invokes repaints on color changes. :/ On the plus side, I haven't seen the frame rate dip below 60fps.</p>
</main>
<footer>
<small>Built by <a href="//twitter.com/chrisnager">@chrisnager</a> · <a href="//github.com/chrisnager/simple-paper-spinner">GitHub</a> · <a href="//codepen.io/chrisnager/pen/d9704e18e1d7a132c497fed2eb1d3847?editors=110">CodePen</a></small>
</footer>
/* Spinner rotation */
@keyframes spin { to { transform: rotate(1080deg) } }
.spinner {
width: 1.75em;
height: 1.75em;
border-radius: 50%;
display: inline-block;
position: relative;
overflow: hidden;
box-shadow: inset 0 0 0 .1875em;
will-change: transform;
animation: spin 2666ms linear infinite;
clip-path: circle(.875em at center);
/* Set background to same color as pseudo elements. Defaults to white */
background-color: #fff;
}
/* Preset colors */
.spinner[data-options*="blue"] { color: #4285f4 }
.spinner[data-options*="red"] { color: #db4437 }
.spinner[data-options*="yellow"] { color: #f4b400 }
.spinner[data-options*="green"] { color: #0f9d58 }
/* Preset sizes */
.spinner[data-options*="large"] { font-size: 2em }
.spinner[data-options*="xlarge"] { font-size: 3em }
/* Multicolor */
@keyframes color-shift {
/* Blue */
from { box-shadow: inset 0 0 0 .1875em #4285f4 }
22% { box-shadow: inset 0 0 0 .1875em #4285f4 }
/* Red */
23% { box-shadow: inset 0 0 0 .1875em #db4437 }
48% { box-shadow: inset 0 0 0 .1875em #db4437 }
/* Yellow */
49% { box-shadow: inset 0 0 0 .1875em #f4b400 }
73% { box-shadow: inset 0 0 0 .1875em #f4b400 }
/* Green */
74% { box-shadow: inset 0 0 0 .1875em #0f9d58 }
98% { box-shadow: inset 0 0 0 .1875em #0f9d58 }
/* Back to blue */
to { box-shadow: inset 0 0 0 .1875em #4285f4 }
}
/* Forced to duplicate `spin` keyframes for multicolor spinner.
* Otherwise, spinner continues to rotate without resetting to account for color changes */
@keyframes multicolor-spin { to { transform: rotate(1080deg) } }
.spinner[data-options*="multicolor"] { will-change: transform, box-shadow }
.spinner[data-options*="multicolor"].is-active { animation: multicolor-spin 2666ms linear infinite, color-shift 8531.2ms infinite linear }
.spinner::before,
.spinner::after {
content: "";
position: absolute;
width: 7em;
height: 1.75em;
background-color: inherit;
}
@keyframes shape-shift-before { to { transform: skewX(-45deg) translate(.875em, -.875em) } }
.spinner::before {
transform: skewX(80deg) translate(.875em, -.875em);
animation: shape-shift-before 1066.4ms cubic-bezier(.4, 0, .2, 1) infinite alternate;
}
@keyframes shape-shift-after { to { transform: skewX(45deg) translate(.875em, .875em) } }
.spinner::after {
transform: skewX(-80deg) translate(.875em, .875em);
animation: shape-shift-after 1066.4ms cubic-bezier(.4, 0, .2, 1) infinite alternate;
}
/* Debug */
.spinner[data-options*="debug"] {
margin-top: 1em;
margin-bottom: 1em;
}
.spinner[data-options*="debug"]::before { background-color: rgba(255, 0, 0, .75) }
.spinner[data-options*="debug"]::after { background-color: rgba(0, 0, 255, .75) }
.spinner[data-options*="debug--1"] {
margin-right: 7em;
overflow: visible;
clip-path: none;
}
.spinner[data-options*="debug--1"],
.spinner[data-options*="debug--2"] { animation: none }
/* Docs */
body{margin:0;font:300 1em/1.4 "Helvetica Neue",sans-serif;color:#114}header,main,footer{padding:2em}header,footer{background-color:#eee}h1,h2{font-weight:500}a{text-decoration:none;color:#0f9d58}a:hover,a:focus{text-decoration:underline}ul{padding-left:30px}@media(min-width:30em){br{display:none}}button{border:1px solid;border-radius:.25em;font-size:.75em;cursor:pointer;display:block;box-sizing:border-box;padding:1em;margin:1em 0;height:auto;vertical-align:middle;-webkit-appearance:none;color:#0f9d58;background-color:transparent}button:hover,button:focus{border-color:#0f9d58;color:#fff;background-color:#0f9d58}pre{border:2px solid;border-radius:3px;padding:1em;white-space:pre-wrap}mark{background-color:rgba(244,180,0,.3)}
document.querySelector('.toggle-multicolor').addEventListener('click', function() {
var multicolorSpinners = document.querySelectorAll('[data-options*="multicolor"]');
Array.prototype.forEach.call(multicolorSpinners, function(multicolorSpinner) {
multicolorSpinner.classList.toggle('is-active');
});
});
Also see: Tab Triggers