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 id="root" class="root">
<div class="plane">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1240 880">
<path style="fill:#fafafa; stroke:none;" d="M22 490C35.3403 497.029 50.8846 501.101 65 506.425C98.9786 519.241 133.197 531.527 167 544.797C178.584 549.345 190.316 553.659 202 557.947C207.451 559.947 215.301 561.371 219.581 565.499C224.498 570.242 226.073 580.711 228.424 587C235.132 604.94 241.36 623.055 248.05 641C272.321 706.102 291.739 774.544 320 838C333.8 826.767 344.188 807.247 354.873 793L425.373 699L451.526 664C454.525 660.002 458.316 652.18 463.093 650.212C467.945 648.214 476.402 653.43 481 654.997C497.065 660.471 512.904 666.625 529 672C573.917 687.001 618.261 703.813 663 719.344C681.202 725.663 700.97 736.15 720 739L727.718 683L745.718 557L796.282 202L819 42L785 60.1396L722 95.5756L529 204.14L178 401.576L73 460.576L22 490z" />
<path style="fill:#d5d5d5; stroke:none;" d="M693 204C650.582 238.544 611.58 278.128 571 314.83C509.222 370.705 446.958 426.15 386 482.91C360.728 506.442 335.075 529.936 309 552.576C301.846 558.787 295.1 565.45 288 571.714C285.142 574.237 280.741 576.986 279.929 581C279.139 584.906 282.086 590.363 283.344 594L293.495 623C306.239 659.709 323.245 697.155 332 735L333 735L363.576 652L378.728 612L400.119 584L446.576 524L573.424 360L661.732 246L683.576 218L693 204z" />
</svg>
</div>
</div>
* {
box-sizing: border-box;
}
.root > svg {
display: inline-block;
position: absolute;
top: -1%;
left: 10%;
transform: translateX(2000px);
animation: float 8s linear infinite forwards;
opacity: 0.4;
}
html {
background-color: rgb(163, 163, 244);
}
body {
margin: 0;
position: relative;
}
html,
body {
overflow: hidden;
height: 100vh;
}
.root {
height: 100%;
width: 010%;
overflow: hidden;
.plane > svg {
top: 40%;
transform-origin: center right;
animation: fly 11s linear infinite;
position: absolute;
max-height: 200px;
z-index: 999999;
}
}
@keyframes fly {
0%,
100% {
transform: rotate(45deg) translateX(30%);
}
33% {
transform: rotate(25deg) translateX(50%);
}
66% {
transform: rotate(60deg) translateX(10%);
}
}
@keyframes float {
0%,
100% {
transform: translateY(10%) translateX(100%);
}
80% {
transform: translateY(10%) translateX(-100%);
}
90% {
transform: translateY(-500%) translateX(-100%);
}
95% {
transform: translateY(-500%) translateX(100%);
}
}
interface Circle {
cx: number;
cy: number;
r: number;
}
function* CircleGenerator(
pos: [number, number]
): Generator<{ left: Circle; right: Circle }> {
// Start with:
// Position = Center Position
const [cx, cy] = pos;
let [x, y] = [cx, cy];
// Radius = Max Radius
let radius = 48;
// Left Angle = 180
let leftAngle: number = 180;
// Right Angle = 0
let rightAngle: number = 0;
const rand = (min: number, max: number): number => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
};
while (true) {
// PICK TWO ANGLES: Left and Right
// Left should be between 155 and 205 degrees
leftAngle = rand(155, 205);
// Right should be between -35 and 35 degrees
rightAngle = rand(-25, 25);
// get next set of circle centers by:
// Generating a new, smaller radius for each angle
let nextRadius: number = radius * 0.8;
// calculate the distance from current center by adding current radius to this circles radius
const distanceToNextCenter = radius + nextRadius;
// use cos & sin to get next point
const rightPoint = [
Math.cos(rightAngle * (Math.PI / 180)) * distanceToNextCenter,
Math.sin(rightAngle * (Math.PI / 180)) * distanceToNextCenter
];
const leftPoint = [
Math.cos(leftAngle * (Math.PI / 180)) * distanceToNextCenter,
Math.sin(leftAngle * (Math.PI / 180)) * distanceToNextCenter
];
yield {
left: {
cx: leftPoint[0],
cy: leftPoint[1],
r: nextRadius
},
right: {
cx: rightPoint[0],
cy: rightPoint[1],
r: nextRadius
}
};
radius = nextRadius;
}
}
window.addEventListener("load", onLoad);
function createTestCanvas(parent: HTMLElement): CanvasRenderingContext2D {
const canvas = document.createElement("canvas");
canvas.width = 460;
canvas.height = 460 / 1.62;
parent.appendChild(canvas);
return canvas.getContext("2d") as CanvasRenderingContext2D;
}
function createCloud(): SVGElement {
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svg.setAttribute("viewBox", "0 0 400 164");
svg.style.top = Math.random() * 40 + "%";
const baseCircle = document.createElementNS(
"http://www.w3.org/2000/svg",
"circle"
);
baseCircle.setAttribute("cx", "200");
baseCircle.setAttribute("cy", "82");
baseCircle.setAttribute("r", "40");
baseCircle.setAttribute("fill", "white");
svg.appendChild(baseCircle);
const gen = CircleGenerator([400, 164]);
let current = gen.next();
for (let i = 0; i < 64; i += 1) {
const { left, right } = current.value;
const { cx: lx, cy: ly, r: lr } = left;
const { cx: rx, cy: ry, r: rr } = right;
const leftCircle = document.createElementNS(
"http://www.w3.org/2000/svg",
"circle"
);
const rightCircle = document.createElementNS(
"http://www.w3.org/2000/svg",
"circle"
);
leftCircle.setAttribute("cx", lx + 200);
leftCircle.setAttribute("cy", ly + 82);
leftCircle.setAttribute("r", lr);
leftCircle.setAttribute("fill", "white");
rightCircle.setAttribute("cx", rx + 200);
rightCircle.setAttribute("cy", ry + 82);
rightCircle.setAttribute("r", rr);
rightCircle.setAttribute("fill", "white");
svg.style.filter = `blur(6px)`;
svg.appendChild(leftCircle);
svg.appendChild(rightCircle);
current = gen.next();
}
return svg;
}
function onLoad(): void {
const root = document.getElementById("root") || document.body;
const ctx = createTestCanvas(root);
let i = 0;
root.appendChild(createCloud());
const interval = window.setInterval(() => {
if (i < 6) root.appendChild(createCloud());
else window.clearInterval(interval);
i += 1;
}, 2100);
}
Also see: Tab Triggers