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.
<!-- It's kinda heavy on the browser, sorry about that -->
<div id="canvasContainer"><div id="filterContainer"><canvas id="mainstage"></canvas></div></div>
<svg id="weirdFilter">
<filter id="svgFilter">
<feTurbulence id="turbulence" type="turbulence" baseFrequency="0.05"
numOctaves="15" />
<feDisplacementMap id="displacement" in="SourceGraphic" scale="25" />
</filter>
<filter id="skyFilter">
<feTurbulence id="turbulence1" type="turbulence" baseFrequency="0.009" numOctaves="15" />
<feDisplacementMap id="displacement1" in="SourceGraphic" scale="200" />
</filter>
<filter id="earthFilter">
<feTurbulence id="turbulence2" type="fractalNoise" baseFrequency="0.2" numOctaves="50" />
<feTurbulence id="turbulence1" type="turbulence" baseFrequency="0.05" numOctaves="5" />
<feColorMatrix
type = "matrix"
values="1 1 0 0 0
1 1 1 0 0
0 0 1 0 0
0 0 0 1 0 "/>
</filter>
</svg>
<!--<div id="backdrop"></div>
<div id="backdrop2"></div>
-->
<div id="earthGravity">
<div id="earth">
<div id="earthFilterContainer"></div>
</div>
</div>
<div id="earthOrbit">
<svg height="120" width="700">
<linearGradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" stop-color="rgba(255,255,255,0)" />
<stop offset="100%" stop-color="rgba(255,255,255,0.3)" />
</linearGradient>
<ellipse cx="350" cy="60" rx="350" ry="60"
fill="none" stroke="url(#gradient)" stroke-width="1" />
</svg>
</div>
body {
margin:0px;
height:100vh;
padding:0px;
overflow:hidden;
background: radial-gradient(ellipse at center, rgba(15,20,25,1) 19%,rgba(10,7,15,1) 100%);
}
#canvasContainer {
position:absolute;
z-index:-2;
background: radial-gradient(ellipse at center, rgba(255,34,0,1) 0%, rgba(219,190,3,1) 67%, rgba(255,255,255,1) 70%, rgba(247,255,3,1) 100%);
margin-left:calc(50% - 100px);
margin-top:calc(50vh - 100px);
display:inline-block;
width:200px;
height:200px;
border-radius:180px;
box-sizing: border-box;
border:0px solid white;
box-shadow: 0px 0px 15px 5px rgba(255,233,145,1);
}
#mainstage {
opacity:1;
left:10%;
top:10%;
width:80%;
height:80%;
position:relative;
overflow:hidden;
margin:0px;
padding:0px;
background-color:transparent;
border-radius:180px;
animation: planetRotation 30s infinite;
animation-timing-function: linear;
}
#filterContainer {
overflow:hidden;
position:relative;
width:130%;
height:130%;
left: -17%;
top: -17%;
filter:blur(4px) url(#svgFilter);
}
@keyframes planetRotation {
0% {transform:rotate(0deg);}
50% {transform:rotate(180deg);}
100% {transform:rotate(360deg);}
}
/* #backdrop, #backdrop2 {
position:absolute;
width:100%;
height:100vh;
background: rgba(76,76,76,1);
background: linear-gradient(to bottom, rgba(149,149,149,1) 0%,rgba(13,13,13,1) 46%,rgba(1,1,1,1) 50%,rgba(10,10,10,1) 53%,rgba(78,78,78,1) 76%,rgba(56,56,56,1) 87%,rgba(27,27,27,1) 100%);
top:0px;
left:0px;
z-index: -2;
opacity:0.1;
filter:blur(25px) url(#skyFilter);
animation: skyFlow 20s infinite;
animation-timing-function: linear;
}
@keyframes skyFlow {
0% {transform:scale(1,1);opacity:0.0;}
25% {transform:scale(1.3,1.3);opacity:0.02}
50% {transform:scale(1.5,1.5);opacity:0.04}
75% {transform:scale(1.8,1.8);opacity:0.015}
100% {transform:scale(2,2);opacity:0.0}
}
#backdrop2 {
opacity:0;
animation-delay: 10s;
} */
@keyframes starShine {
0% {opacity:0.5}
25% {opacity:0.2}
50% {opacity:0.8}
75% {opacity:0.1}
100% {opacity:0.5}
}
#earth {
position:absolute;
background: radial-gradient(ellipse at center, rgba(125,185,232,1) 0%,rgba(37,186,42,1) 12%,rgba(43,136,217,1) 29%,rgba(255,232,153,1) 51%,rgba(66,183,53,1) 63%,rgba(32,124,202,1) 77%,rgba(32,124,202,1) 77%,rgba(226,255,183,1) 86%,rgba(125,185,232,1) 100%);
z-index: 4;
width:50px;
height:50px;
border-radius:180px;
overflow:hidden;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
border:0px solid white;
box-shadow: 0px 0px 10px 5px rgba(119,216,255,0.4);
background-size:600px 600px;
background-position: 10px 10px;
animation: earthMovement 14s infinite, gravityRotationY 20s infinite;
animation-timing-function: linear;
}
#earthGravity {
position:absolute;
height:50px;
width:50px;
background-color:transparent;
top:calc(50% - 25px);
left:calc(50% - 25px);
animation: gravityRotationX 20s infinite;
animation-timing-function: linear;
z-index:0;
}
#earthFilterContainer {
width:100%;
height:100%;
filter:url(#earthFilter);
}
#earth:after {
content:'';
display:block;
position:relative;
top:-105%;
left:0px;
width:110%;
height:110%;
z-index:100;
animation: shadowMovement 20s infinite;
animation-timing-function: linear;
background: linear-gradient(90deg, rgba(0,0,0,1) 0%,rgba(0,0,0,0) 100%);
}
@keyframes earthMovement {
0% {transform:rotate(0deg);background-position:10px 10px;}
100% {transform:rotate(-360deg);background-position:10px 610px;}
}
@keyframes shadowMovement {
0% {transform:rotate(0deg);}
100% {transform:rotate(360deg);}
}
@keyframes gravityRotationX {
0% {
z-index:400;
transform:translateX(-350px);
animation-timing-function: ease-in;
}
25% {
transform:translateX(0px);
animation-timing-function: ease-out;
}
34% {
z-index:-1000;
}
34.1% {
z-index:4;
}
50% {
transform:translateX(350px);
animation-timing-function: ease-in;
}
75% {
transform:translateX(0px);
animation-timing-function: ease-out;
}
100% {
transform:translateX(-350px);
animation-timing-function: ease-in;
}
}
@keyframes gravityRotationY {
0% {
transform:translateY(-0px) scale(1,1) ;
animation-timing-function: ease-out;
transform-origin: top top;
}
25% {
transform:translateY(-60px) scale(.7,.7) ;
animation-timing-function: ease-in;
}
50% {
transform:translateY(0px) scale(1,1);
animation-timing-function: ease-out;
}
75% {
transform:translateY(60px) scale(1.3,1.3);
animation-timing-function: ease-in;
}
100% {
transform:translateY(0px) scale(1,1);
animation-timing-function: ease-out;
}
}
#earthOrbit {
position:fixed;
top:calc(50% - 60px);
left:calc(50% - 350px);
z-index:-1;
}
.starSpearhead {
box-sizing: border-box;
box-shadow: 0px 0px 3px 1px rgba(143,135,255,0.3);
width:5px;
height:1px;
background-color:white;
left:-2px;
position:relative;
animation: starRotation 3s infinite;
animation-timing-function: linear;
}
.starSpearhead:after {
box-sizing: border-box;
box-shadow: 0px 0px 3px 1px rgba(143,135,255,0.3);
content:'';
display:block;
width:1px;
position: absolute;
height: 5px;
background-color: white;
left: 2px;
top: -2px;
}
.starTail {
transform-origin: top center;
position: absolute;
}
@keyframes starRotation {
0% {transform:rotate(0deg);}
100% {transform:rotate(360deg);}
}
@keyframes shootingStarAnimation1 {
0% {
opacity:0;
transform:translate(100px,100px);
}
50% {
opacity:1;
transform:translate(200px,200px);
}
100% {
opacity:0;
transform:translate(300px,300px);
}
}
@keyframes shootingStarAnimation2 {
0% {
transform:translate(-100px,100px);
opacity:0;
}
50% {
transform:translate(-200px,200px);
opacity:1;
}
100% {
transform:translate(-300px,300px);
opaicty:0;
}
}
@keyframes shootingStarAnimation3 {
0% {
transform:translate(-100px,-100px);
opacity:0;
}
50% {
transform:translate(-200px,-200px);
opacity:1;
}
100% {
transform:translate(-300px,-300px);
opaicty:0;
}
}
@keyframes shootingStarAnimation4 {
0% {
transform:translate(100px,-100px);
opacity:0;
}
50% {
transform:translate(200px,-200px);
opacity:1;
}
100% {
transform:translate(300px,-300px);
opaicty:0;
}
}
function initiate() {
var TO_RADIANS = Math.PI/180;
var canvas = document.getElementById("mainstage");
var context = canvas.getContext("2d");
canvas.width = document.getElementById("canvasContainer").clientWidth;
canvas.height = document.getElementById("canvasContainer").clientHeight;
var bubbleArray = [];
setUpArray(bubbleArray);
main();
var then = Date.now();
function main() {
var now = Date.now();
var delta = now - then;
update();
render();
then = now;
requestAnimationFrame(main);
};
function setUpArray(array) {
let startColors = [
"rgba(218,104,11,1)", // orange
//"rgba(45,0,0,1)", // deep deep red
//"rgba(226,13,23,1)", // red
//"rgba(143,7,7,1)", // deep red
"rgba(255,246,76,1)", // yellow
"rgba(255,246,76,1)", // yellow
//"rgba(255,255,255,1)", // white
];
let endColors = [
"rgba(218,104,11,0)", // orange
//"rgba(45,0,0,0)", // deep deep red
//"rgba(226,13,23,0)", // red
//"rgba(143,7,7,0)", // deep red
"rgba(255,246,76,0)", // yellow
"rgba(255,246,76,0)", // yellow
//"rgba(255,255,255,0)", // white
]
for(y=0;y<150;y++) {
var angle = Math.round(Math.random() * 360);
var targetAngle = Math.round(Math.random() * 360);
var init = new Date();
var colorPick = Math.floor(Math.random() * startColors.length);
var object = {
id:y,
initiation:0,
speed:Math.random(),
angle:angle,
targetAngle: targetAngle,
innerSize:Math.random() + 1,
outerSize:Math.random() * 20 + 2,
x:Math.floor(Math.random() * canvas.width),
y:Math.floor(Math.random() *canvas.height),
color:startColors[colorPick],
endColor:endColors[colorPick],
}
array.push(object);
}
}
function update() {
for(y=0;y<bubbleArray.length;y++) {
if(bubbleArray[y].x < -25 || bubbleArray[y].x > canvas.width + 25 ||
bubbleArray[y].y < -25 || bubbleArray[y].y > canvas.height + 25)
{
bubbleArray[y].x = Math.floor(Math.random() * canvas.width);
bubbleArray[y].y = Math.floor(Math.random() * canvas.height);
bubbleArray[y].innerSize = Math.random() + 1,
bubbleArray[y].outerSize = Math.random() * 20 + 3,
bubbleArray[y].initiation = 0.20;
bubbleArray[y].angle = Math.round(Math.random() * 360);
bubbleArray[y].targetAngle = Math.round(Math.random() * 360);
}
else {
bubbleArray[y].angle += Math.random() * .50 - 0.25;
}
bubbleArray[y].x -= bubbleArray[y].speed * Math.cos(bubbleArray[y].angle * TO_RADIANS);
bubbleArray[y].y += bubbleArray[y].speed * Math.sin(bubbleArray[y].angle * TO_RADIANS);
if(bubbleArray[y].initiation > 0.15) {
bubbleArray[y].initiation -= 0.03;
}
else {
bubbleArray[y].initiation -= 0.0001;
}
}
}
function render() {
context.clearRect(0,0,canvas.width,canvas.height);
for(y=0;y<bubbleArray.length;y++) {
renderEntity(bubbleArray[y]);
}
}
function renderEntity(object) {
context.strokeStyle="transparent";
context.beginPath();
var opacity = object.initiation;
var gradient = context.createRadialGradient(object.x, object.y, object.innerSize, object.x, object.y, object.outerSize);
gradient.addColorStop(0.000, object.color);
gradient.addColorStop(1.000, object.endColor);
context.fillStyle = gradient;
context.arc(object.x,object.y, 25, 0, 2 * Math.PI);
context.fill();
context.stroke();
}
}
initiate();
doStars();
function doStars() {
let width = document.body.clientWidth;
let height = document.body.clientHeight;
for(y=0;y<200;y++) {
var star = document.createElement('div');
star.style.width = "2px";
star.style.height = "2px";
star.style.zIndex = "-1";
star.style.backgroundColor = "rgba(255,255,255,1)";
star.style.borderRadius = "180px";
star.style.position = "absolute";
star.style.opacity = 0.5;
star.style.zIndex = -10000;
star.style.left = Math.floor(Math.random() * width) + 'px';
star.style.top = Math.floor(Math.random() * height) + 'px';
if( y < 100 ) {
star.style.animation = "starShine";
star.style.animationIterationCount = "infinite"
star.style.animationTimingFunction = "linear";
star.style.animationDuration = Math.floor(Math.random() * 5 + 5) + "s";
}
document.body.append(star);
}
}
document.body.addEventListener("click", function(){shootingStar()});
function shootingStar() {
let width = document.body.clientWidth;
let height = document.body.clientHeight;
let star = document.createElement('div');
let starId = "star" + new Date().getTime();
star.id = starId;
let starSparkle = document.createElement('div');
let starTail = document.createElement('div');
starTail.className = "starTail";
starSparkle.className = "starSpearhead";
starTail.style.width = "1px";
starTail.style.height = "35px";
starTail.style.zIndex = "-1";
starTail.style.background = "radial-gradient(circle at top center, rgba(255,255,255,1) 0%, rgba(2,0,36,0) 85%)";
starTail.style.borderRadius = "180px";
star.style.position = "absolute";
star.style.opacity = 0;
star.style.zIndex = -10000;
star.style.left = Math.floor(Math.random() * width) + 'px';
star.style.top = Math.floor(Math.random() * height) + 'px';
let rotation = Math.floor(Math.random() * 4) + 1;
starTail.style.transform = "rotate(" + (45 + ((rotation * 90))) + "deg)";
star.style.animation = "shootingStarAnimation" + rotation;
star.style.animationIterationCount = 1; //"infinite";
star.style.animationTimingFunction = "linear";
star.style.animationDuration = Math.floor(Math.random() * 2 + 1) + "s";
document.body.append(star);
document.getElementById(starId).append(starSparkle);
document.getElementById(starId).append(starTail);
};
function shootingStarsFire() {
setTimeout(function(){ shootingStar(); shootingStarsFire() }, (Math.random() * 500) + 1000 );
}
shootingStarsFire();
Also see: Tab Triggers