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.
<main>
<svg viewBox="0 0 700 700">
<defs>
<g id="circles">
<symbol id="dot">
<circle cx="30" cy="30" r="30" />
</symbol>
<!--
We need two moving circles in order to pull off this effect:
one for the gooey effect and another for the glow. By
animating this circle and using it in the two aforementioned
scenarios, we guarantee that the two dots we end up using
will remain moving in sync. This would not be the case if
we assigned our animation to the two dots separately. Note
the coordinates that we assign to the circle.
-->
<symbol id="moving-dot">
<circle class="scanner" cx="175" cy="175" r="28" />
</symbol>
</g>
<g id="filters">
<!-- Our gooey effect filter. -->
<filter id="goo">
<feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" />
<feColorMatrix in="blur"
mode="matrix"
values="1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 19 -9"
result="goo" />
<feComposite in="SourceGraphic" in2="goo" operator="atop" />
</filter>
<!--
This softens the edges of the moving dot by adding a
subtle glowing effect. We increase the height and the
width, and adjust the coordinates to avoid clipping.
These values are arbitrary, as I didn't want to get
super math-y about it.
-->
<filter id="glow" filterUnits="userSpaceOnUse" x="-20%" y="-20%" height="140%" width="140%">
<feGaussianBlur in="SourceGraphic" stdDeviation="12" />
</filter>
<!--
A larger, yet more subtle glow effect meant for the
second moving circle. Again, the dimension and position
attributes are arbitrary but large enough to prevent
any clipping.
-->
<filter id="outer-glow" filterUnits="userSpaceOnUse" x="-50%" y="-50%" height="220%" width="220%">
<feGaussianBlur in="SourceGraphic" stdDeviation="30" result="outer-glow"/>
</filter>
</g>
</defs>
<svg aria-labelledby="title"
aria-describedby="desc"
aria-busy="true"
role="progressbar"
aria-valuemin="0"
aria-valuemax="100">
<title id="title">Circular Loader with Gooey Effect</title>
<desc id="desc">
A soft cyan glowing dot moving in a circular path defined by eight light blue circles, creating a
gooey effect as it passes over them.
</desc>
<!--
For the effect to work, the "#goo" filter should be applied
to a container, which this <g> is. The moving dot uses the
"#glow" filter to replace the hard edges of the dot with a
soft glow effect.
We derive the location of the eight circles by converting
polar to Cartesian coordinates using the following
equations:
x = r cos ϕ
y = r sin ϕ
Here, `r` stands for the radius of the circle defining
the circular path. This is 150 in our case. `ϕ` is
multiples of 45° (360 divided by 8).
-->
<g class="circles centered">
<use class="dot" href="#dot" x="106" y="106"/>
<use class="dot" href="#dot" x="0" y="150"/>
<use class="dot" href="#dot" x="-106" y="106"/>
<use class="dot" href="#dot" x="-150" y="0"/>
<use class="dot" href="#dot" x="-106" y="-106"/>
<use class="dot" href="#dot" x="0" y="-150"/>
<use class="dot" href="#dot" x="106" y="-106"/>
<use class="dot" href="#dot" x="150" y="0"/>
<!-- Position the glowing dot by the topmost center dot. -->
<use class="dot--light" href="#moving-dot" x="-150" y="-150" />
</g>
<!--
This extra dot represents the larger and softer glow around
the moving dot. We can't include this in the group above
because the "#goo" filter renders the "#outer-glow" filter
useless. It causes clipping, in addition, due to it missing
the filter attributes from "#outer-glow".
Note that we need to wrap the dot in a <g> due to having
to apply a translation twice: one for centering the dot and
another for the animation. If we were to apply the
`centered` class to the dot, the value of the translation
from the animation would override it, messing up the
effect. Alternatively, we could define another `@keyframes`
rule but with the appropriate `translateY` value.
-->
<g class="centered">
<use class="dot--glowing" href="#moving-dot" x="-150" y="-150" />
</g>
</svg>
</svg>
<p class="credits">
Based on the design by
<a target="_blank" href="https://dribbble.com/shots/2177533-Spinner-Loader-Gooey-light-Effect">
<b>Christophe Kerebel</b>
</a>
</p>
</main>
:root {
--dot-radius: 30px;
--path-radius: 150px;
--vp-width: 700px;
--vp-height: 700px;
--static-dot-color: hsl(204, 100%, 65%);
--moving-dot-color: hsl(178, 94%, 65%);
}
/* --------------------------------------------------
Elements
-------------------------------------------------- */
html,
body,
main {
height: 100vh;
width: 100vw;
margin: 0;
}
body {
background-color: hsl(204, 100%, 9%);
font-family: sans-serif;
}
main {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
p {
color: var(--static-dot-color);
font-size: 0.7rem;
letter-spacing: 0.1rem;
}
a {
color: var(--moving-dot-color);
text-decoration: none;
}
/* --------------------------------------------------
Classes
-------------------------------------------------- */
.dot {
fill: var(--static-dot-color);
}
.dot--light {
fill: var(--moving-dot-color);
filter: url('#glow');
}
.dot--glowing {
fill: var(--moving-dot-color);
filter: url('#outer-glow');
}
.scanner {
will-change: transform;
animation: 3s scan 0s infinite linear both;
}
.circles {
filter: url("#goo");
}
.centered {
/* FF lets us use percentages, but Chrome doesn't like that. That
* means we have to hard-code the dimensions of the viewport.
*/
transform:
translate(
calc((var(--vp-width) * 0.5) - var(--dot-radius)),
calc((var(--vp-height) * 0.5) - var(--dot-radius))
);
}
.credits {
margin-bottom: calc(1.5rem * 2);
}
/* --------------------------------------------------
Animations
-------------------------------------------------- */
/* Defines the circular path our dots will take. We use 2 `rotate`
* functions to contrain the plane containing our dots. Without
* this, the dots will go out of orbit. See this brilliant post for
* a much better explanation:
* http://www.useragentman.com/blog/2013/03/03/animating-circular-paths-using-css3-transitions/
*/
@keyframes scan {
from {
transform: rotate(0deg) translateY(calc(var(--path-radius) * -1)) rotate(0deg);
}
to {
transform: rotate(360deg) translateY(calc(var(--path-radius) * -1)) rotate(-360deg);
}
}
Also see: Tab Triggers