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 URL's 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 it's URL and the proper URL extention.
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.
svg.rainbow-cloud(xmlns='http://www.w3.org/2000/svg' viewbox='0 0 378.42 215.18')
defs
clipPath#rainbow-clip
rect(x="0" y="0" height="168" width="1500")
g.rainbow__wrapper.rainbow-cloud__rainbow(clip-path="url(#rainbow-clip)")
g.rainbow(stroke-linecap='round' stroke-linejoin='round')
path.rainbow__beam.rainbow__red(d='M188.33 37.15A132.3 132.3 0 0056.04 169.44h13.23A119.06 119.06 0 01188.33 50.38 119.06 119.06 0 01307.4 169.44h13.23a132.3 132.3 0 00-132.29-132.3z')
path.rainbow__beam.rainbow__orange(d='M188.33 43.76A125.68 125.68 0 0062.66 169.44h13.22A112.45 112.45 0 01188.33 56.99a112.45 112.45 0 01112.45 112.45h13.23A125.68 125.68 0 00188.33 43.76z')
path.rainbow__beam.rainbow__yellow(d='M188.33 50.38A119.06 119.06 0 0069.27 169.44H82.5A105.83 105.83 0 01188.33 63.6a105.83 105.83 0 01105.84 105.84h13.23A119.06 119.06 0 00188.33 50.38z')
path.rainbow__beam.rainbow__green(d='M188.33 56.99A112.45 112.45 0 0075.88 169.44h13.23a99.22 99.22 0 0199.22-99.22 99.22 99.22 0 0199.22 99.22h13.23A112.45 112.45 0 00188.33 56.99z')
path.rainbow__beam.rainbow__blue(d='M188.33 63.6A105.83 105.83 0 0082.5 169.44h13.23a92.6 92.6 0 0192.6-92.6 92.6 92.6 0 0192.6 92.6h13.24A105.83 105.83 0 00188.33 63.6z')
path.rainbow__beam.rainbow__indigo(d='M188.33 70.22a99.22 99.22 0 00-99.22 99.22h13.23a85.99 85.99 0 0186-86 85.99 85.99 0 0185.98 86h13.23a99.22 99.22 0 00-99.22-99.22z')
path.rainbow__beam.rainbow__violet(d='M188.33 76.83a92.6 92.6 0 00-92.6 92.6h6.61a85.99 85.99 0 0186-85.98 85.99 85.99 0 0185.98 85.99h6.62a92.6 92.6 0 00-92.6-92.6z')
g.cloud__wrapper.cloud__wrapper--baby
g.cloud.rainbow__cloud.cloud--baby
g.cloud__body
path(d='M75.05 132.24a15.74 15.74 0 00-15.03 11.07 15.74 15.74 0 00-11.53 15.07 15.74 15.74 0 00-10 14.65 15.74 15.74 0 0015.75 15.74 15.74 15.74 0 0012.6-6.35 15.74 15.74 0 0012.61 6.35 15.74 15.74 0 008.21-2.33 15.74 15.74 0 008.2 2.33 15.74 15.74 0 0015.26-11.97 15.74 15.74 0 008.44-13.93 15.74 15.74 0 00-15.74-15.73 15.74 15.74 0 00-2.61.22 15.74 15.74 0 00-11.51-5.13 15.74 15.74 0 00-14.65-9.99z' stroke='#000' stroke-linecap='round' stroke-linejoin='round')
g.cloud__face.cloud__face--thrilled
g.cloud__eyes.cloud__eyes--thrilled
path(fill="none" stroke="#000" stroke-linecap="round" stroke-width="1.5" stroke-linejoin="round" d='M63.8 164.67a2.26 2.26 0 012.25-2.22 2.26 2.26 0 012.26 2.22M94.16 165.12a2.26 2.26 0 012.26-2.23 2.26 2.26 0 012.26 2.23')
g.cloud__mouth.cloud__mouth--thrilled
path(d='M76.56 164.94a4.68 4.68 0 000 .05 4.68 4.68 0 004.68 4.68 4.68 4.68 0 004.68-4.68 4.68 4.68 0 000-.05z')
path(d='M81.24 166.2a3.8 3.57 0 00-3.42 1.99 4.68 4.68 0 003.42 1.48 4.68 4.68 0 003.4-1.48 3.8 3.57 0 00-3.4-2z' fill='red')
g.cloud__face(transform='translate(494.14 30.3)')
g.cloud__eye.cloud__eye--left
path(d='M-425.3 133.56a2.87 2.87 0 01-2.87 2.87 2.87 2.87 0 01-2.87-2.87 2.87 2.87 0 012.87-2.88 2.87 2.87 0 012.88 2.88z')
path(d='M-428.29 132.5a.94.94 0 01-.94.93.94.94 0 01-.93-.93.94.94 0 01.93-.94.94.94 0 01.94.94z' fill='#fff')
g.cloud__eye.cloud__eye--right
path(d='M-395.1 133.56a2.87 2.87 0 01-2.87 2.87 2.87 2.87 0 01-2.87-2.87 2.87 2.87 0 012.87-2.88 2.87 2.87 0 012.87 2.88z')
path(d='M-398.1 132.5a.94.94 0 01-.93.93.94.94 0 01-.94-.93.94.94 0 01.94-.94.94.94 0 01.94.94z' fill='#fff')
g.cloud__mouth.cloud__mouth--sad
path(d='M-417.09 138.7a4.02 3.28 0 010-.09 4.02 3.28 0 014.02-3.27 4.02 3.28 0 014.02 3.27h0a4.02 3.28 0 010 .09' fill='none' stroke-linecap='round' stroke-linejoin='round')
g.cloud__mouth.cloud__mouth--happy(style='display: none;')
path(d='M-409.05 135.35a4.02 3.28 0 010 .08 4.02 3.28 0 01-4.02 3.28 4.02 3.28 0 01-4.02-3.28h0a4.02 3.28 0 010-.08' fill='none' stroke-linecap='round' stroke-linejoin='round')
g.cloud__cheeks(transform='translate(494.14 30.3)')
g.cloud__cheek.cloud__cheek--left
circle(cx='-439.04' cy='136.66' r='2.71' fill='#faa' fill-opacity='.5')
g.cloud__cheek.cloud__cheek--right
circle(r='2.71' cy='136.66' cx='-387.1' fill='#faa' fill-opacity='.5')
g.cloud__wrapper
g.cloud.rainbow__cloud
g.cloud__body
path(d='M96.6 120.51a25.77 25.9 0 00-21.55 11.73 19.47 19.56 0 00-12.18-4.32 19.47 19.56 0 00-19.17 16.25 24.01 24.13 0 00-3.11-.22 24.01 24.13 0 00-24.02 24.13A24.01 24.13 0 0040.6 192.2a24.01 24.13 0 0010.3-2.37 19.47 19.56 0 0015.95 8.38 19.47 19.56 0 0013.42-5.41 19.47 19.56 0 0013.41 5.41 19.47 19.56 0 0014.94-7.03 19.47 19.56 0 0014.92 7.03A19.47 19.56 0 00143 178.66a19.47 19.56 0 00-8.18-15.91 19.47 19.56 0 002.13-8.85 19.47 19.56 0 00-17.5-19.46 25.77 25.9 0 00-22.85-13.93z' stroke='#000' stroke-linecap='round' stroke-linejoin='round')
g.cloud__face.cloud__face--thrilled(transform='translate(494.14 30.3)')
g.cloud__eyes.cloud__eyes--thrilled
path(d='M-430.34 134.37a2.26 2.26 0 012.26-2.23 2.26 2.26 0 012.25 2.23M-399.97 134.81a2.26 2.26 0 012.25-2.23 2.26 2.26 0 012.26 2.23' fill='none' stroke='#000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round')
g.cloud__mouth.cloud__mouth--thrilled
path(d='M-417.58 134.64a4.68 4.68 0 000 .05 4.68 4.68 0 004.68 4.68 4.68 4.68 0 004.68-4.68 4.68 4.68 0 000-.05z')
path(d='M-412.9 135.89a3.8 3.57 0 00-3.41 2 4.68 4.68 0 003.41 1.48 4.68 4.68 0 003.41-1.49 3.8 3.57 0 00-3.41-2z' fill='red')
g.cloud__face(transform='translate(494.14 30.3)')
g.cloud__eye.cloud__eye--left
path(d='M-425.3 133.56a2.87 2.87 0 01-2.87 2.87 2.87 2.87 0 01-2.87-2.87 2.87 2.87 0 012.87-2.88 2.87 2.87 0 012.88 2.88z')
path(d='M-428.29 132.5a.94.94 0 01-.94.93.94.94 0 01-.93-.93.94.94 0 01.93-.94.94.94 0 01.94.94z' fill='#fff')
g.cloud__eye.cloud__eye--right
path(d='M-395.1 133.56a2.87 2.87 0 01-2.87 2.87 2.87 2.87 0 01-2.87-2.87 2.87 2.87 0 012.87-2.88 2.87 2.87 0 012.87 2.88z')
path(d='M-398.1 132.5a.94.94 0 01-.93.93.94.94 0 01-.94-.93.94.94 0 01.94-.94.94.94 0 01.94.94z' fill='#fff')
g.cloud__mouth.cloud__mouth--sad
path(d='M-417.09 138.7a4.02 3.28 0 010-.09 4.02 3.28 0 014.02-3.27 4.02 3.28 0 014.02 3.27h0a4.02 3.28 0 010 .09' fill='none' stroke-linecap='round' stroke-linejoin='round')
g.cloud__mouth.cloud__mouth--happy(style='display: none;')
path(d='M-409.05 135.35a4.02 3.28 0 010 .08 4.02 3.28 0 01-4.02 3.28 4.02 3.28 0 01-4.02-3.28h0a4.02 3.28 0 010-.08' fill='none' stroke-linecap='round' stroke-linejoin='round')
g.cloud__cheeks(transform='translate(494.14 30.3)')
g.cloud__cheek.cloud__cheek--left
circle(cx='-439.04' cy='136.66' r='2.71' fill='#faa' fill-opacity='.5')
g.cloud__cheek.cloud__cheek--right
circle(r='2.71' cy='136.66' cx='-386.93' fill='#faa' fill-opacity='.5')
button
*
box-sizing border-box
:root
--lightness 50
--saturation 50
--rainbow-lightness 50
body
align-items center
background 'hsl(210, %s, %s)' % (calc(var(--saturation, 50) * 1%) calc(var(--lightness, 50) * 1%))
display flex
justify-content center
min-height 100vh
.rainbow-cloud
width 95vmin
.rainbow
stroke #000
stroke-width 0
&__beam
fill 'hsl(%s, 85%, %s)' % (var(--hue) calc(var(--rainbow-lightness, 100) * 1%))
&__red
--hue 2
&__orange
--hue 22
&__yellow
--hue 48
&__green
--hue 90
&__blue
--hue 200
&__indigo
--hue 235
&__violet
--hue 295
.cloud
&__body
fill 'hsl(0, 0%, %s)' % calc(var(--cloud-lightness, 65) * 1%)
stroke #000
stroke-width 2px
&__mouth
stroke #000
stroke-width 2px
&--thrilled path:nth-of-type(2)
stroke none
button
position absolute
top 0
left 0
height 100vh
width 100vw
opacity 0
const {
MorphSVGPlugin,
gsap: { to, timeline, set, registerPlugin }
} = window;
const CONFIG = {
SPEED: {
CLOUD: 0.25
},
COLORS: {
CLOUD: {
ON: 100,
OFF: 65
}
}
};
registerPlugin(MorphSVGPlugin);
const CLOUD_WRAPPER = document.querySelector(
".cloud__wrapper:not(.cloud__wrapper--baby)"
);
const CLOUD = document.querySelector(".cloud:not(.cloud--baby)");
const CLOUD_EYES = [
...document.querySelectorAll(".cloud:not(.cloud--baby) .cloud__eye")
];
const BABY_EYES = [...document.querySelectorAll(".cloud--baby .cloud__eye")];
const CLOUD_MOUTHS = [...document.querySelectorAll(".cloud__mouth--sad path")];
const HAPPY_CLOUD_MOUTH_PATHS = [
...document.querySelectorAll(".cloud__mouth--happy path")
];
const RAINBOW = document.querySelector(".rainbow");
const THRILLED_FACES = [...document.querySelectorAll(".cloud__face--thrilled")];
const FACES = [
...document.querySelectorAll(".cloud__face:not(.cloud__face--thrilled)")
];
set(THRILLED_FACES, { display: "none" });
set(CLOUD_WRAPPER, { transformOrigin: "135% 55%" });
set(CLOUD, {
transformOrigin: "50% 50%"
});
set(".cloud--baby .cloud__eye path:nth-of-type(2)", {
x: 2,
transformOrigin: "50% 50% "
});
set(CLOUD_MOUTHS, { morphSVG: (index) => CLOUD_MOUTHS[index] });
set(document.documentElement, {
"--saturation": 0,
"--lightness": 50,
"--cloud-lightness": CONFIG.COLORS.CLOUD.OFF
});
const CLOUD_TIMELINE = () =>
new timeline({
onStart: () => {
// Make them smile
set(CLOUD_MOUTHS, {
morphSVG: (index) => HAPPY_CLOUD_MOUTH_PATHS[index]
});
}
})
// Traveling over the arc
.add(
to(CLOUD_WRAPPER, {
duration: CONFIG.SPEED.CLOUD,
rotate: 180
})
)
// Counter rotating the cloud
.add(
to(CLOUD, {
duration: CONFIG.SPEED.CLOUD,
rotate: -180
}),
0
);
set(RAINBOW, { transformOrigin: "50% 100%", rotate: 180 });
const RAINBOW_TL = () =>
to(RAINBOW, {
duration: CONFIG.SPEED.CLOUD,
rotate: 360
});
const COLOR_TL = () =>
to(document.documentElement, {
duration: CONFIG.SPEED.CLOUD,
"--cloud-lightness": 100,
"--saturation": 80,
"--lightness": 70
});
const BREATHE_TL = () =>
new timeline().add(
to(".cloud__body", {
scale: 1.05,
repeat: -1,
yoyo: true,
transformOrigin: "50% 50%",
delay: "random(0, -1, 0.1)",
duration: "random(1, 3, 0.1)"
})
);
// Breathe timeline
BREATHE_TL();
// Blinking TL
const BLINK_TL = (eyes) => {
const delay = Math.random() * 10 + 2;
new timeline({
delay,
onComplete: () => BLINK_TL(eyes)
}).add(
to(eyes, {
duration: 0.1,
repeat: 1,
yoyo: true,
scaleY: 0,
transformOrigin: "50% 50%"
})
);
};
BLINK_TL(CLOUD_EYES);
BLINK_TL(BABY_EYES);
const THRILLED_TL = (faceIndex, onComplete) => {
const delay = Math.random() * 5 + 2;
return new timeline({
delay,
onComplete
})
.add(
to(FACES[faceIndex], {
duration: 0,
display: FACES[faceIndex].style.display === "none" ? "block" : "none"
}),
0
)
.add(
to(THRILLED_FACES[faceIndex], {
duration: 0,
display:
THRILLED_FACES[faceIndex].style.display === "block" ? "none" : "block"
}),
0
);
};
let THRILLER_ONE;
let THRILLER_TWO;
const AUDIO = {
SIGH: new Audio('https://assets.codepen.io/605876/sigh.mp3'),
CHEER: new Audio('https://assets.codepen.io/605876/kids-cheering.mp3'),
}
// This is the daddy
const TOGGLE_TL = new timeline({
paused: true,
onStart: () => {
AUDIO.SIGH.pause()
AUDIO.SIGH.currentTime = 0
AUDIO.CHEER.currentTime = 0
AUDIO.CHEER.play()
},
onComplete: () => {
THRILLER_ONE = THRILLED_TL(0, () => (THRILLER_ONE = THRILLED_TL(0)));
THRILLER_TWO = THRILLED_TL(1, () => (THRILLER_TWO = THRILLED_TL(1)));
}
});
// Add the cloud timeline
TOGGLE_TL.add(COLOR_TL(), 0).add(CLOUD_TIMELINE(), 0).add(RAINBOW_TL(), 0);
// GSDevTools.create()
// Now we need a button
const BUTTON = document.querySelector("button");
BUTTON.addEventListener("click", () => {
if (TOGGLE_TL.progress() !== 0 && TOGGLE_TL.reversed() !== true) {
set(CLOUD_MOUTHS, {
morphSVG: (index) => CLOUD_MOUTHS[index]
});
// Kill all randomized thrilled face timelines
set(FACES, { display: "block" });
set(THRILLED_FACES, { display: "none" });
THRILLER_ONE.pause();
THRILLER_ONE.seek(0);
THRILLER_TWO.pause();
THRILLER_TWO.seek(0);
// Empty the Array
AUDIO.CHEER.pause()
AUDIO.CHEER.currentTime = 0
AUDIO.SIGH.currentTime = 0
AUDIO.SIGH.play()
TOGGLE_TL.reverse();
} else {
TOGGLE_TL.play();
}
});
to(
[...document.querySelectorAll(".rainbow__beam")].sort(
() => Math.random() > 0.5 ? -1 : 1
),
{
duration: 0.05,
"--rainbow-lightness": 60,
repeat: -1,
stagger: 0.05,
yoyo: true
}
);
Also see: Tab Triggers