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="ptr">
<div class="trigger"></div>
<div class="ptr__container">
<!-- <svg class="cog cog--small" fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80">
<path fill-rule="evenodd" clip-rule="evenodd" d="m68.001 10.593-8.587-6.107-6.59 6.458a32.084 32.084 0 0 0-6.063-1.93L45.307 0H34.693l-1.456 9.022a32.435 32.435 0 0 0-6.06 1.923l-6.591-6.458-8.587 6.106 4.24 8.135a31.65 31.65 0 0 0-3.745 5.044L3.28 22.34 0 32.22l8.312 4.141a30.607 30.607 0 0 0 .005 6.236L0 46.74l3.28 9.881 9.208-1.432a30.966 30.966 0 0 0 3.748 5.047l-4.238 8.131 8.588 6.107 6.59-6.457a32.083 32.083 0 0 0 5.89 1.892L34.692 80h10.614l1.63-10.099a32.441 32.441 0 0 0 5.722-1.816l7.38 7.23 8.586-6.107-4.745-9.106a31.655 31.655 0 0 0 3.626-4.914l9.214 1.433 3.28-9.88-8.312-4.142c.212-2.079.208-4.169-.005-6.235L80 32.22l-3.28-9.881-9.208 1.432a30.972 30.972 0 0 0-3.748-5.048l4.237-8.13ZM40 51c6.075 0 11-4.925 11-11s-4.925-11-11-11-11 4.925-11 11 4.925 11 11 11Z" fill="currentColor"/>
</svg> -->
<div class="cog cog--big">
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 146 146">
<path fill-rule="evenodd" clip-rule="evenodd" d="m0 68 13.306-1.094a59.756 59.756 0 0 1 2.202-11.126L3.643 49.683l3.827-9.238 12.705 4.079a60.097 60.097 0 0 1 6.308-9.424l-8.637-10.183 7.07-7.071 10.185 8.637a60.15 60.15 0 0 1 7.65-5.311L38.597 8.236l9.239-3.827 6.018 11.71a59.682 59.682 0 0 1 13.052-2.813L68 0h10l1.094 13.306a59.683 59.683 0 0 1 13.052 2.813l6.018-11.71 9.239 3.827-4.154 12.936a59.613 59.613 0 0 1 3.728 2.368 60.13 60.13 0 0 1 3.922 2.943l10.184-8.637 7.071 7.07-8.637 10.185a60.086 60.086 0 0 1 6.308 9.423l12.705-4.08 3.827 9.24-11.864 6.096a59.682 59.682 0 0 1 2.201 11.126L146 68v10l-13.306 1.094a59.762 59.762 0 0 1-2.201 11.126l11.864 6.097-3.827 9.238-12.705-4.079a60.134 60.134 0 0 1-6.18 9.267l-.051.063-.077.093 8.637 10.184-7.071 7.071-10.184-8.637a60.158 60.158 0 0 1-7.42 5.176l-.152.09-.078.045 4.154 12.936-9.239 3.827-6.018-11.71a59.67 59.67 0 0 1-13.052 2.813L78 146H68l-1.094-13.306a59.67 59.67 0 0 1-13.052-2.813l-6.018 11.71-9.239-3.827 4.154-12.936a60.132 60.132 0 0 1-7.65-5.311l-10.184 8.637-7.071-7.071 8.637-10.184a60.072 60.072 0 0 1-6.308-9.423L7.47 105.555l-3.827-9.238 11.864-6.097a59.733 59.733 0 0 1-2.201-11.126L0 78V68Zm73 23c9.941 0 18-8.059 18-18s-8.059-18-18-18-18 8.059-18 18 8.059 18 18 18Z" fill="currentColor"/>
</svg>
</div>
<div class="cog cog--big">
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 146 146">
<path fill-rule="evenodd" clip-rule="evenodd" d="m0 68 13.306-1.094a59.756 59.756 0 0 1 2.202-11.126L3.643 49.683l3.827-9.238 12.705 4.079a60.097 60.097 0 0 1 6.308-9.424l-8.637-10.183 7.07-7.071 10.185 8.637a60.15 60.15 0 0 1 7.65-5.311L38.597 8.236l9.239-3.827 6.018 11.71a59.682 59.682 0 0 1 13.052-2.813L68 0h10l1.094 13.306a59.683 59.683 0 0 1 13.052 2.813l6.018-11.71 9.239 3.827-4.154 12.936a59.613 59.613 0 0 1 3.728 2.368 60.13 60.13 0 0 1 3.922 2.943l10.184-8.637 7.071 7.07-8.637 10.185a60.086 60.086 0 0 1 6.308 9.423l12.705-4.08 3.827 9.24-11.864 6.096a59.682 59.682 0 0 1 2.201 11.126L146 68v10l-13.306 1.094a59.762 59.762 0 0 1-2.201 11.126l11.864 6.097-3.827 9.238-12.705-4.079a60.134 60.134 0 0 1-6.18 9.267l-.051.063-.077.093 8.637 10.184-7.071 7.071-10.184-8.637a60.158 60.158 0 0 1-7.42 5.176l-.152.09-.078.045 4.154 12.936-9.239 3.827-6.018-11.71a59.67 59.67 0 0 1-13.052 2.813L78 146H68l-1.094-13.306a59.67 59.67 0 0 1-13.052-2.813l-6.018 11.71-9.239-3.827 4.154-12.936a60.132 60.132 0 0 1-7.65-5.311l-10.184 8.637-7.071-7.071 8.637-10.184a60.072 60.072 0 0 1-6.308-9.423L7.47 105.555l-3.827-9.238 11.864-6.097a59.733 59.733 0 0 1-2.201-11.126L0 78V68Zm73 23c9.941 0 18-8.059 18-18s-8.059-18-18-18-18 8.059-18 18 8.059 18 18 18Z" fill="currentColor"/>
</svg>
</div>
<div class="cog cog--big">
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 146 146">
<path fill-rule="evenodd" clip-rule="evenodd" d="m0 68 13.306-1.094a59.756 59.756 0 0 1 2.202-11.126L3.643 49.683l3.827-9.238 12.705 4.079a60.097 60.097 0 0 1 6.308-9.424l-8.637-10.183 7.07-7.071 10.185 8.637a60.15 60.15 0 0 1 7.65-5.311L38.597 8.236l9.239-3.827 6.018 11.71a59.682 59.682 0 0 1 13.052-2.813L68 0h10l1.094 13.306a59.683 59.683 0 0 1 13.052 2.813l6.018-11.71 9.239 3.827-4.154 12.936a59.613 59.613 0 0 1 3.728 2.368 60.13 60.13 0 0 1 3.922 2.943l10.184-8.637 7.071 7.07-8.637 10.185a60.086 60.086 0 0 1 6.308 9.423l12.705-4.08 3.827 9.24-11.864 6.096a59.682 59.682 0 0 1 2.201 11.126L146 68v10l-13.306 1.094a59.762 59.762 0 0 1-2.201 11.126l11.864 6.097-3.827 9.238-12.705-4.079a60.134 60.134 0 0 1-6.18 9.267l-.051.063-.077.093 8.637 10.184-7.071 7.071-10.184-8.637a60.158 60.158 0 0 1-7.42 5.176l-.152.09-.078.045 4.154 12.936-9.239 3.827-6.018-11.71a59.67 59.67 0 0 1-13.052 2.813L78 146H68l-1.094-13.306a59.67 59.67 0 0 1-13.052-2.813l-6.018 11.71-9.239-3.827 4.154-12.936a60.132 60.132 0 0 1-7.65-5.311l-10.184 8.637-7.071-7.071 8.637-10.184a60.072 60.072 0 0 1-6.308-9.423L7.47 105.555l-3.827-9.238 11.864-6.097a59.733 59.733 0 0 1-2.201-11.126L0 78V68Zm73 23c9.941 0 18-8.059 18-18s-8.059-18-18-18-18 8.059-18 18 8.059 18 18 18Z" fill="currentColor"/>
</svg>
</div>
<div class="cog cog--big">
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 146 146">
<path fill-rule="evenodd" clip-rule="evenodd" d="m0 68 13.306-1.094a59.756 59.756 0 0 1 2.202-11.126L3.643 49.683l3.827-9.238 12.705 4.079a60.097 60.097 0 0 1 6.308-9.424l-8.637-10.183 7.07-7.071 10.185 8.637a60.15 60.15 0 0 1 7.65-5.311L38.597 8.236l9.239-3.827 6.018 11.71a59.682 59.682 0 0 1 13.052-2.813L68 0h10l1.094 13.306a59.683 59.683 0 0 1 13.052 2.813l6.018-11.71 9.239 3.827-4.154 12.936a59.613 59.613 0 0 1 3.728 2.368 60.13 60.13 0 0 1 3.922 2.943l10.184-8.637 7.071 7.07-8.637 10.185a60.086 60.086 0 0 1 6.308 9.423l12.705-4.08 3.827 9.24-11.864 6.096a59.682 59.682 0 0 1 2.201 11.126L146 68v10l-13.306 1.094a59.762 59.762 0 0 1-2.201 11.126l11.864 6.097-3.827 9.238-12.705-4.079a60.134 60.134 0 0 1-6.18 9.267l-.051.063-.077.093 8.637 10.184-7.071 7.071-10.184-8.637a60.158 60.158 0 0 1-7.42 5.176l-.152.09-.078.045 4.154 12.936-9.239 3.827-6.018-11.71a59.67 59.67 0 0 1-13.052 2.813L78 146H68l-1.094-13.306a59.67 59.67 0 0 1-13.052-2.813l-6.018 11.71-9.239-3.827 4.154-12.936a60.132 60.132 0 0 1-7.65-5.311l-10.184 8.637-7.071-7.071 8.637-10.184a60.072 60.072 0 0 1-6.308-9.423L7.47 105.555l-3.827-9.238 11.864-6.097a59.733 59.733 0 0 1-2.201-11.126L0 78V68Zm73 23c9.941 0 18-8.059 18-18s-8.059-18-18-18-18 8.059-18 18 8.059 18 18 18Z" fill="currentColor"/>
</svg>
</div>
</div>
</div>
<div class="cog-container">
<svg class="cog cog--small" fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80">
<path fill-rule="evenodd" clip-rule="evenodd" d="m68.001 10.593-8.587-6.107-6.59 6.458a32.084 32.084 0 0 0-6.063-1.93L45.307 0H34.693l-1.456 9.022a32.435 32.435 0 0 0-6.06 1.923l-6.591-6.458-8.587 6.106 4.24 8.135a31.65 31.65 0 0 0-3.745 5.044L3.28 22.34 0 32.22l8.312 4.141a30.607 30.607 0 0 0 .005 6.236L0 46.74l3.28 9.881 9.208-1.432a30.966 30.966 0 0 0 3.748 5.047l-4.238 8.131 8.588 6.107 6.59-6.457a32.083 32.083 0 0 0 5.89 1.892L34.692 80h10.614l1.63-10.099a32.441 32.441 0 0 0 5.722-1.816l7.38 7.23 8.586-6.107-4.745-9.106a31.655 31.655 0 0 0 3.626-4.914l9.214 1.433 3.28-9.88-8.312-4.142c.212-2.079.208-4.169-.005-6.235L80 32.22l-3.28-9.881-9.208 1.432a30.972 30.972 0 0 0-3.748-5.048l4.237-8.13ZM40 51c6.075 0 11-4.925 11-11s-4.925-11-11-11-11 4.925-11 11 4.925 11 11 11Z" fill="currentColor"/>
</svg>
</div>
<main>
<div class="instruction">Scroll to Refresh.</div>
<article>
<div class="quote">
<blockquote></blockquote>
<span>– James Clear.</span>
</div>
</article>
</main>
* {
box-sizing: border-box;
}
:root {
--speed: 10s;
--ptr: 20vh;
--multiplier: 0.45;
view-transition-name: none;
}
.quote {
view-transition-name: quote;
position: relative;
display: none;
}
blockquote {
margin: 0;
margin: 0 auto;
font-size: clamp(1.44rem, calc(1.26rem + .89vw), 1.95rem);
width: calc(100% - 2rem);
max-width: 600px;
border-left: 6px solid hsl(250 80% 80%);
padding: 1rem;
font-weight: 300;
}
.quote span {
position: absolute;
top: 100%;
right: 0;
font-weight: bold;
color: hsl(250 80% 40%);
}
article {
display: grid;
place-items: center;
}
.instruction {
position: fixed;
bottom: 2rem;
right: 2rem;
font-weight: bold;
font-size: 1.35rem;
color: hsl(250 80% 40%);
}
body {
display: grid;
min-height: 100vh;
scroll-padding: 2rem;
background: hsl(0 0% 98%);
font-family: sans-serif, system-ui;
}
html {
scroll-snap-type: y mandatory;
scroll-padding-top: 0;
transition: scroll-padding-top 1s;
}
.ptr {
background: hsl(250 80% 20%);
height: var(--ptr);
width: 100%;
}
.ptr__container {
overflow: hidden;
}
.ptr__container .cog {
position: absolute;
top: 50%;
left: 50%;
transition: opacity 0.2s 0.2s, transform 0.4s;
}
.ptr__container .cog svg {
animation: cog both linear reverse;
animation-timeline: scroll(root);
animation-range: 0 var(--ptr);
}
[data-refreshing=true] .ptr__container .cog {
opacity: 0;
transform: translate(var(--x), var(--y));
}
@keyframes cog {
0% {
transform: rotate(var(--start, 0deg));
}
100% {
transform: rotate(var(--destination, 0deg));
}
}
.ptr__container .cog:nth-of-type(1) {
--destination: -237deg;
--start: -12deg;
--x: 100%;
--y: -100%;
color: hsl(250 80% 72%);
width: calc(var(--ptr) * var(--multiplier));
translate: 70% -134%;
scale: 2;
}
.ptr__container .cog:nth-of-type(2) {
--destination: -238deg;
--start: -16deg;
--x: -100%;
--y: 100%;
color: hsl(250 80% 82%);
width: calc(var(--ptr) * var(--multiplier));
translate: -136% 54%;
scale: 1.8;
}
.ptr__container .cog:nth-of-type(3) {
--destination: 200deg;
--start: -20deg;
--x: -100%;
--y: -100%;
color: hsl(250 80% 80%);
width: calc(var(--ptr) * var(--multiplier));
translate: -294% -96%;
scale: 2.6;
}
.ptr__container .cog:nth-of-type(4) {
--destination: 194deg;
--start: -24deg;
--x: 100%;
--y: 100%;
color: hsl(250 80% 74%);
width: calc(var(--ptr) * var(--multiplier));
translate: 252% 22%;
scale: 2.8;
}
.cog-container {
color: hsl(250 80% 68%);
width: calc(var(--ptr) * var(--multiplier));
height: calc(var(--ptr) * var(--multiplier));
position: fixed;
top: calc(var(--ptr) * -0.5);
left: 50%;
translate: -50% -50%;
animation: drop both linear reverse;
animation-timeline: scroll();
animation-range: 0 var(--ptr);
z-index: 10;
}
@keyframes drop {
to {
translate: -50% calc(var(--ptr) - 50%);
rotate: 360deg;
}
}
[data-refreshing=true] .cog-container {
translate: -50% calc(var(--ptr) - 50%);
animation: spin 1s infinite linear;
}
[data-refreshing=false] .cog-container {
translate: -50% -50%;
animation: unload 1s forwards;
}
@keyframes spin {
100% {
transform: rotate(360deg);
}
}
@keyframes unload {
from {
translate: -50% calc(var(--ptr) - 50%);
}
}
.ptr__container {
height: var(--ptr);
width: 100%;
position: fixed;
top: 0;
translate: 0 -100%;
animation: cogs both linear reverse;
animation-timeline: scroll();
animation-range: 0 var(--ptr);
}
.ptr__container::after {
content: "";
position: absolute;
inset: -2rem -2rem 0 -2rem;
box-shadow: 0 0 4rem 1rem hsl(0 0% 0% / 0.5) inset;
}
@keyframes cogs {
to {
translate: 0 0;
}
}
.trigger {
height: 2px;
width: 100%;
animation: trigger both linear reverse;
animation-timeline: view();
}
@keyframes trigger {
to {
translate: 0 0;
}
}
main {
position: relative;
scroll-snap-align: start;
min-height: calc(100vh - var(--ptr));
}
/* Theming */
article h1 {
color: var(--gray-9);
}
article {
min-height: 100vh;
width: 100%;
}
// Show the island
const TRIGGER = document.querySelector('.trigger')
const MAIN = document.querySelector('main')
const COG = document.querySelector('.cog-container')
const QUOTE = document.querySelector('blockquote')
const QUOTE_CONTAINER = document.querySelector('.quote')
// let count = 0
const LOAD_TIME = 1000
let newQuote
const getQuote = async () => {
const data = await (await fetch('https://www.jcquotes.com/api/quotes/random')).json()
console.info({ data })
return data
}
const updateQuote = () => {
document.startViewTransition(() => {
QUOTE.innerText = newQuote.text
QUOTE.cite = newQuote.source
})
}
const bootstrap = async () => {
newQuote = await getQuote()
QUOTE.innerText = newQuote.text
QUOTE.cite = newQuote.source
QUOTE_CONTAINER.style.display = 'block'
}
bootstrap()
const RESET = event => {
if (event.animationName === 'unload') {
COG.removeEventListener('animationend', RESET)
delete document.documentElement.dataset.refreshing
}
}
const UNLOAD = () => {
updateQuote()
COG.addEventListener('animationend', RESET)
document.documentElement.dataset.refreshing = false
}
TRIGGER.addEventListener('animationstart', async () => {
if (document.documentElement.scrollTop <= 2) {
// Into the loading state...
document.documentElement.dataset.refreshing = true
newQuote = await getQuote()
setTimeout(UNLOAD, Math.random() * LOAD_TIME + 2000)
}
})
Also see: Tab Triggers