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="content">
<div class="system">
<div class="star"></div>
<div class="planet"></div>
<div class="planet"></div>
<div class="planet"></div>
<div class="planet double-moon"></div>
<div class="planet ring"></div>
<div class="planet moon"></div>
<div class="asteroid">
<div class="belt"></div>
</div>
</div>
<button id="random-planets" onclick="randomPlanets()">Randomize</button>
</div>
/* ... IN PROGRESS ... */
/* Improving surfaces */
/* Add more planets */
body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
background:
repeating-conic-gradient(#0003 0.00001%, #fff0 .00005%, #fff0 .00035%, #fff0 .00005%),
repeating-conic-gradient(#fff2 0.00002%, #fff0 .00008%, #fff0 .0009%, #fff0 .008%),
radial-gradient(circle at 50% 50%, hsla(var(--s2), 50%, 50%, 0.25) -25%, #0000 50%),
radial-gradient(circle at 50% 50%, #222, #000);
--star-color: hsl(calc(var(--s2) * 1deg) 100% 50%);
--star-crater: hsl(calc(var(--s2) * 0.95deg) 90% 50%);
}
body:before {
content: "";
position: absolute;
width: 200%;
height: 200%;
background: repeating-conic-gradient(#fff4 0.00002%, #fff0 .00008%, #fff0 .0009%, #fff0 .008%);
animation: orbit 300s linear 0s infinite;
opacity: 0.5;
filter: drop-shadow(0 0 0 5px #fff8);
}
.content {
width: 100vmin;
height: 100vmin;
border-radius: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.system {
position: absolute;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.star {
width: var(--s1);
height: var(--s1);
background:
radial-gradient(circle at 25% 50%, var(--star-crater) 0 10%, #fff0 20% 100%),
radial-gradient(circle at 65% 30%, var(--star-crater) 0 7%, #fff0 17% 100%),
radial-gradient(circle at 85% 75%, var(--star-crater) 0 3%, #fff0 10% 100%),
var(--star-color);
box-shadow: 0 0 calc(var(--s1) / 2) calc(var(--s1) / 10) var(--star-color), 0 0 calc(var(--s1) / 75) calc(var(--s1) / 10) var(--star-color), 0 0 calc(var(--s1) * 1.5) 0 var(--star-color);
border-radius: 100%;
animation: orbit 10s linear 0s infinite;
}
.star:before, .star:after {
content: "";
position: absolute;
width: 130%;
height: 130%;
left: -15%;
top: -15%;
border-radius: 100%;
border: calc(var(--s1) / 10) dotted hsl(calc(var(--s2) * 1deg) 100% 50%);
box-sizing: border-box;
filter: blur(7px);
}
.star:after {
filter: blur(18px);
animation: orbit 5s linear 0s infinite;
}
@keyframes orbit {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.planet {
position: absolute;
width: var(--p1);
height: var(--p1);
border-radius: 100%;
border: 2px dashed #ffffff0a;
animation: orbit var(--sp) linear 0s infinite;
display: flex; align-items: center;
justify-content: center;
}
.planet:nth-child(3) {
width: var(--p2);
height: var(--p2);
animation-duration: calc(var(--sp) * 0.5);
animation-delay: -10s;
}
.planet:nth-child(4) {
width: var(--p3);
height: var(--p3);
animation-duration: calc(var(--sp) * 1.5);
animation-delay: -25s;
}
.planet:nth-child(5) {
width: var(--p4);
height: var(--p4);
animation-duration: calc(var(--sp) * 2);
animation-delay: -2s;
}
.planet:nth-child(6) {
width: var(--p5);
height: var(--p5);
animation-duration: calc(var(--sp) * 2.5);
animation-delay: -50s;
}
.planet:nth-child(7) {
width: var(--p6);
height: var(--p6);
animation-duration: calc(var(--sp) * 3);
animation-delay: -15s;
}
@keyframes ring {
0% { transform: rotate(0deg) scale(2); }
100% { transform: rotate(360deg) scale(2); }
}
.planet:before,
.planet:after {
--planet-color: hsl(var(--c1) 50% 50%);
content: "";
position: absolute;
width: calc(var(--p1) / 12);
height: calc(var(--p1) / 12);
background: radial-gradient(circle at 50% 110%, var(--planet-color) 0 50%, #0008 75% 100%), var(--planet-color);
border-radius: 100%;
left: calc(50% - calc(calc(var(--p1) / 12) * -0.5));
top: calc(calc(var(--p1) / 12) * -0.5);
box-shadow: 0 0 1vmin 0 hsl(var(--c1) 50% 50%);
}
.planet:nth-child(3):before,
.planet:nth-child(3):after {
--planet-color: hsl(var(--c2) 50% 50%);
width: calc(var(--p2) / 10);
height: calc(var(--p2) / 10);
left: calc(50% - calc(calc(var(--p2) / 10) * -0.5));
top: calc(calc(var(--p2) / 10) * -0.5);
box-shadow: 0 0 1vmin 0 hsl(var(--c2) 50% 50%);
}
.planet:nth-child(4):before,
.planet:nth-child(4):after {
--planet-color: hsl(var(--c3) 50% 50%);
width: calc(var(--p3) / 9);
height: calc(var(--p3) / 9);
left: calc(50% - calc(calc(var(--p3) / 9) * -0.5));
top: calc(calc(var(--p3) / 9) * -0.5);
box-shadow: 0 0 1vmin 0 hsl(var(--c3) 50% 50%);
}
.planet:nth-child(5):before,
.planet:nth-child(5):after {
--planet-color: hsl(var(--c4) 50% 50%);
width: calc(var(--p4) / 13);
height: calc(var(--p4) / 13);
left: calc(50% - calc(calc(var(--p4) / 13) * -0.5));
top: calc(calc(var(--p4) / 13) * -0.5);
box-shadow: 0 0 1vmin 0 hsl(var(--c4) 50% 50%);
}
.planet:nth-child(6):before,
.planet:nth-child(6):after {
--planet-color: hsl(var(--c5) 50% 50%);
width: calc(var(--p5) / 15);
height: calc(var(--p5) / 15);
left: calc(50% - calc(calc(var(--p5) / 15) * -0.5));
top: calc(calc(var(--p5) / 15) * -0.5);
box-shadow: 0 0 1vmin 0 hsl(var(--c5) 50% 50%);
}
.planet:nth-child(7):before,
.planet:nth-child(7):after {
--planet-color: hsl(var(--c6) 50% 50%);
width: calc(var(--p6) / 18);
height: calc(var(--p6) / 18);
left: calc(50% - calc(calc(var(--p5) / 18) * -0.5));
top: calc(calc(var(--p5) / 18) * -0.5);
box-shadow: 0 0 1vmin 0 hsl(var(--c6) 50% 50%);
}
.planet:after {
display: none;
}
.planet.ring:after {
display: block;
background:
radial-gradient(circle at 50% 6%, hsl(var(--c6) 50% 90%) 0 4%, #fff0 calc(4% + 1px)),
repeating-radial-gradient(#fff0 0 2%, hsl(var(--c2) 50% 50%) calc(2% + 1px) 4%, hsl(var(--c4) 50% 50%) calc(4% + 1px) 6%, #fff0 calc(6% + 1px) 8%) !important;
z-index: -1;
animation: ring 5s linear 0s infinite;
opacity: 0.15;
}
.planet.ring ~ .planet.ring:after {
background:
radial-gradient(circle at 50% 6%, hsl(var(--c1) 50% 90%) 0 4%, #fff0 calc(4% + 1px)),
repeating-radial-gradient(#fff0 0 2%, hsl(var(--c3) 50% 50%) calc(2% + 1px) 4%, hsl(var(--c5) 50% 50%) calc(4% + 1px) 5%, #fff0 calc(5% + 1px) 8%) !important;
z-index: -1;
animation: ring 15s linear 0s infinite;
opacity: 0.125;
}
.planet.moon:after {
display: block;
background:
radial-gradient(circle at calc(20% + 1px) calc(20% + 1px), hsl(var(--c1) 10% 20%) 0 5%, #fff0 calc(5% + 1px)),
radial-gradient(circle at 50% 50%, #fff0 0 55%, #ffffff08 calc(55% + 1px) 56%, #fff0 calc(56% + 1px)) !important;
box-shadow: none !important;
animation: ring calc(var(--sp) / 10) linear 0s infinite;
opacity: 0.85;
}
.planet.double-moon:after {
display: block;
background:
radial-gradient(circle at calc(20% + 1px) calc(20% + 1px), hsl(var(--c2) 10% 20%) 0 3%, #fff0 calc(3% + 1px)), radial-gradient(circle at calc(80% + 1px) calc(80% + 1px), hsl(var(--c3) 10% 20%) 0 2%, #fff0 calc(2% + 1px)), radial-gradient(circle at 50% 50%, #fff0 0 40%, #ffffff10 50%, #fff0 60%), radial-gradient(circle at 50% 50%, #fff0 0 50%, #ffffff10 55%, #fff0 65%), radial-gradient(circle at 50% 50%, #fff0 0 60%, #ffffff08 calc(60% + 1px) 61%, #fff0 calc(73% + 1px)) !important;
box-shadow: none !important;
animation: ring calc(var(--sp) / 5) linear 0s infinite;
opacity: 0.75;
}
button#random-planets {
position: absolute;
bottom: 5vmin;
border: 0;
background: hsla(var(--c1), 50%, 50%, 0.125);
text-transform: uppercase;
font-family: Arial, Helvetica, serif;
font-weight: bold;
padding: 10px 20px 10px 22px;
font-size: 15px;
border-radius: 1px;
cursor: pointer;
border: 2px solid #fff8;
box-sizing: border-box;
color: #fffc;
border-radius: 100px;
animation: satellite 5s ease -2s infinite alternate;
}
button#random-planets:hover {
background: hsla(var(--c1), 50%, 50%, 0.25);
border-color: #fffc;
box-shadow: 0 0 1vmin 0 hsla(var(--c1), 50%, 50%, 0.75), 0 0 2vmin 0 #000c inset;
}
button#random-planets:before, button#random-planets:after {
content: "";
position: absolute;
left: calc(calc(var(--p1) / 12) / -2);
top: calc(calc(var(--p1) / 12) / -50);
width: calc(var(--p1) / 12);
height: calc(var(--p1) / 12);
background: radial-gradient(circle at 50% -10%, hsl(var(--s2) 50% 50%) 0 50%, #0008 75% 100%), hsl(var(--c2) 50% 50%);
border-radius: 100%;
border: 2px solid #fff6;
animation: satellite 3s ease 0s infinite alternate;
}
@keyframes satellite {
0% { transform: translateY(-6px); }
100% { transform: translateY(12px); }
}
button#random-planets:after {
left: inherit;
right: calc(calc(var(--p1) / 20) / -2);
top: calc(calc(var(--p1) / 20) / 1.25);
width: calc(var(--p1) / 20);
height: calc(var(--p1) / 20);
box-sizing: border-box;
background: radial-gradient(circle at 50% -10%, hsl(var(--c4) 50% 50%) 0 50%, #0008 75% 100%), hsl(var(--c4) 50% 50%);
animation-delay: -1s;
animation-duration: 4s;
}
.asteroid {
--brown: #251914;
width: var(--a1);
height: var(--a1);
position: absolute;
border-radius: 100%;
z-index: -2;
display: flex;
align-items: center;
justify-content: center;
animation: orbit calc(var(--sp) * 5) linear 0s infinite;
opacity: 0.75;
}
.asteroid:before, .asteroid:after {
--brown: #562716;
content: "";
width: 90%;
height: 90%;
position: absolute;
border-radius: 100%;
box-sizing: border-box;
margin-left: -3px;
filter: blur(3px);
--ast1: var(--brown) 0.15vmin , #fff0 calc(0.15vmin + 1px);
--ast2: var(--brown) 0.25vmin , #fff0 calc(0.25vmin + 1px);
--ast3: var(--brown) 0.5vmin , #fff0 calc(0.5vmin + 1px);
--ast4: var(--brown) 0.75vmin , #fff0 calc(0.75vmin + 1px);
--ast5: var(--brown) 1vmin , #fff0 calc(1vmin + 1px);
background:
radial-gradient(circle at 50% 4%, var(--ast1)),
radial-gradient(circle at 55% 4%, var(--ast1)),
radial-gradient(circle at 45% 5%, var(--ast1)),
radial-gradient(circle at 53% 5%, var(--ast1)),
radial-gradient(circle at 47% 3%, var(--ast1)),
radial-gradient(circle at 42% 7%, var(--ast2)),
radial-gradient(circle at 48% 2%, var(--ast2)),
radial-gradient(circle at 56% 7%, var(--ast2)),
radial-gradient(circle at 59% 6%, var(--ast2)),
radial-gradient(circle at 38% 7%, var(--ast2)),
radial-gradient(circle at 60% 8%, var(--ast3)),
radial-gradient(circle at 65% 6%, var(--ast3)),
radial-gradient(circle at 49% 6%, var(--ast3)),
radial-gradient(circle at 70% 10%, var(--ast3)),
radial-gradient(circle at 27% 13%, var(--ast3)),
radial-gradient(circle at 40% 5%, var(--ast4)),
radial-gradient(circle at 63% 7%, var(--ast4)),
radial-gradient(circle at 34% 9%, var(--ast4)),
radial-gradient(circle at 22% 14%, var(--ast4)),
radial-gradient(circle at 72% 13%, var(--ast4)),
radial-gradient(circle at 25% 12%, var(--ast5)),
radial-gradient(circle at 37% 5%, var(--ast5)),
radial-gradient(circle at 30% 11%, var(--ast5)),
radial-gradient(circle at 4% 45%, var(--ast5)),
radial-gradient(circle at 3% 59%, var(--ast5)),
radial-gradient(circle at 3% 41%, var(--ast1)),
radial-gradient(circle at 30% 8%, var(--ast1)),
radial-gradient(circle at 27% 9%, var(--ast1)),
radial-gradient(circle at 19% 19%, var(--ast1)),
radial-gradient(circle at 16% 16%, var(--ast1)),
radial-gradient(circle at 7% 29%, var(--ast2)),
radial-gradient(circle at 24% 15%, var(--ast2)),
radial-gradient(circle at 18% 17%, var(--ast2)),
radial-gradient(circle at 13% 22%, var(--ast2)),
radial-gradient(circle at 16% 21%, var(--ast2)),
radial-gradient(circle at 20% 16%, var(--ast3)),
radial-gradient(circle at 32% 7%, var(--ast3)),
radial-gradient(circle at 17% 19%, var(--ast3)),
radial-gradient(circle at 6% 33%, var(--ast3)),
radial-gradient(circle at 11% 29%, var(--ast3)),
radial-gradient(circle at 14% 19%, var(--ast4)),
radial-gradient(circle at 6% 40%, var(--ast4)),
radial-gradient(circle at 8% 27%, var(--ast4)),
radial-gradient(circle at 3% 49%, var(--ast4)),
radial-gradient(circle at 5% 56%, var(--ast4)),
radial-gradient(circle at 7% 67%, var(--ast5)),
radial-gradient(circle at 15% 23%, var(--ast5)),
radial-gradient(circle at 12% 25%, var(--ast5)),
radial-gradient(circle at 9% 31%, var(--ast5)),
radial-gradient(circle at 6% 36%, var(--ast5)),
radial-gradient(circle at 12% 72%, var(--ast1)),
radial-gradient(circle at 77% 14%, var(--ast1)),
radial-gradient(circle at 84% 22%, var(--ast1)),
radial-gradient(circle at 96% 36%, var(--ast1)),
radial-gradient(circle at 97% 46%, var(--ast1)),
radial-gradient(circle at 8% 36%, var(--ast2)),
radial-gradient(circle at 10% 26%, var(--ast2)),
radial-gradient(circle at 10% 71%, var(--ast2)),
radial-gradient(circle at 20% 82%, var(--ast2)),
radial-gradient(circle at 33% 91%, var(--ast2)),
radial-gradient(circle at 78% 16%, var(--ast3)),
radial-gradient(circle at 87% 24%, var(--ast3)),
radial-gradient(circle at 93% 37%, var(--ast3)),
radial-gradient(circle at 93% 30%, var(--ast3)),
radial-gradient(circle at 95% 49%, var(--ast3)),
radial-gradient(circle at 52% 3%, var(--ast4)),
radial-gradient(circle at 84% 19%, var(--ast4)),
radial-gradient(circle at 91% 28%, var(--ast4)),
radial-gradient(circle at 96% 38%, var(--ast4)),
radial-gradient(circle at 81% 16%, var(--ast4)),
radial-gradient(circle at 14% 78%, var(--ast5)),
radial-gradient(circle at 25% 87%, var(--ast5)),
radial-gradient(circle at 55% 95%, var(--ast5)),
radial-gradient(circle at 42% 96%, var(--ast5)),
radial-gradient(circle at 35% 91%, var(--ast5));
}
.asteroid:after {
transform: rotate(180deg);
}
.belt {
position: absolute;
width: 110%;
height: 110%;
background: radial-gradient(#fff0 35%, var(--brown) 53%, #fff0 67%);
border-radius: 100%;
z-index: 2;
}
function randomNumber(max, min) {
return Math.floor(Math.random() * max) + min;
}
function setProp(p, n) {
document.body.style.setProperty(p, n);
}
function getProp(name) {
return document.body.style.getPropertyValue(name);
}
function randomPlanets() {
var delRings = document.querySelectorAll(".ring");
for (var i=0; i<delRings.length; i++){
delRings[i].classList.remove('ring');
}
document.querySelector(".moon").classList.remove('moon');
document.querySelector(".double-moon").classList.remove('double-moon');
/*colors*/
setProp("--c1", randomNumber(359, 1));
setProp("--c2", parseInt(getProp("--c1")) + 45);
setProp("--c3", parseInt(getProp("--c1")) + 90);
setProp("--c4", parseInt(getProp("--c1")) + 135);
setProp("--c5", parseInt(getProp("--c1")) + 180);
setProp("--c6", parseInt(getProp("--c1")) + 225);
/*saturation*/
setProp("--sat", randomNumber(70, 20) + "%");
/*star size*/
setProp("--s1", randomNumber(10, 5) + "vmin");
/*star color*/
setProp("--s2", randomNumber(90, 0));
/*planet size*/
setProp("--p1", randomNumber(8, 20) + "vmin");
setProp("--p2", randomNumber(10, 30) + "vmin");
setProp("--p3", randomNumber(9, 45) + "vmin");
setProp("--p4", randomNumber(17, 58) + "vmin");
setProp("--p5", randomNumber(20, 85) + "vmin");
setProp("--p6", randomNumber(8, 110) + "vmin");
//planet speed
setProp("--sp", randomNumber(20, 20) + "s");
/*asteroid size*/
setProp("--a1", randomNumber(111, 28) + "vmin");
//target
var setTarget = document.querySelectorAll(".system > div");
//ring
var setRing = randomNumber(6, 1);
setTarget[setRing].classList.add('ring');
var setRing2;
if(setRing<4) setRing2=setRing+2; else setRing2=setRing-2;
setTarget[setRing2].classList.add('ring');
//moon
var setMoon = randomNumber(6, 1);
setTarget[setMoon].classList.add('moon');
//double moon
var setDoubleMoon = randomNumber(6, 1);
setTarget[setDoubleMoon].classList.add('double-moon');
}
randomPlanets();
Also see: Tab Triggers