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.
<main class="solar-system">
<article class="solar-system__sun"></article>
<section class="solar-system__mercury-trajectory">
<article class="solar-system__mercury-trajectory__mercury"></article>
</section>
<section class="solar-system__venus-trajectory">
<article class="solar-system__venus-trajectory__venus"></article>
</section>
<section class="solar-system__earth-trajectory">
<article class="solar-system__earth-trajectory__earth"></article>
</section>
<section class="solar-system__mars-trajectory">
<article class="solar-system__mars-trajectory__mars"></article>
</section>
<!-- [♃,♄,⛢,♆] are too far for my little starship. 🚀🪐-->
</main>
<footer>
<a target="_blank" rel="noopener noreferrer" href="https://linktr.ee/delvignefred" aria-label="All my social media links">
<svg id="logo" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 400 400" aria-hidden="true">
<circle cx="200" cy="200" r="196.6"></circle>
<path d="M302.9,84.4H170.5h-8.1c-23.3,0-34.9,9.1-45,29.4l-26.2,52.3c-6,12.2-8.9,20.8-8.9,34.5 c0,11.9,3.3,22,8.6,32.8l27.1,54.3c10.4,21.2,23.9,28,47.1,28h20.3c0,0,0,0,0,0c0,0,0,0,0,0h29.2c7.8,0,14.9-3.5,14.9-14.2 c0-10.7-7.2-14.2-14.9-14.2h-15.3v-96.6h74.3c7.8,0,14.9-4.6,14.9-15.4c0-10.7-7.2-15.4-14.9-15.4h-74.3v-45.2h103.6 c7.8,0,14.9-4.3,14.9-15.1C317.8,88.8,310.6,84.4,302.9,84.4z M170.3,287.1h-5.5c-12.5,0-15.5-2.2-20.9-13.2l-26.2-53.4 c-3.3-6.9-5.7-12.1-5.7-19.6c0-10.1,3.3-15.9,7.5-24.5l24.8-49.8c6.3-12.8,8.9-12,22.7-12h3.4V287.1z">
</path>
</svg>
</a>
</footer>
:root {
/** color system **/
--system-color-dark: oklch(0% 0 0);
--system-color-light: oklch(100% 0 0);
--system-color-logo: oklch(60.07% 0.241 28.73 / 80%);
--system-color-red-100: oklch(60.07% 0.241 28.73 / 25%);
--system-color-red-200: oklch(60.07% 0.241 28.73 / 50%);
--system-color-red-300: oklch(60.07% 0.241 28.73 / 100%);
/** color themes **/
--system-color-theme-paths: var(--system-color-red-100)
var(--system-color-red-300);
--system-color-theme-planets: var(--system-color-red-200)
var(--system-color-red-200) var(--system-color-red-200)
var(--system-color-red-300);
/** planet's radius **/
/* ♂ Mars real radius ≈ 3389.5km. */
--planet-radius-mars: 33.895px;
/* 🜨 Earth real radius ≈ 6371km. */
--planet-radius-earth: 63.71px;
/* ♀ Venus real radius ≈ 6051.8km. */
--planet-radius-venus: 60.518px;
/* ☿ Mercury real radius ≈ 2439.7km. */
--planet-radius-mercury: 24.397px;
/* ☉ Sun real radius ≈ 696340km (40 times smaller compared to the planet's dimensions values). */
--star-radius-sun: 174.085px;
/** planet's trajectories **/
--planet-trajectory-mars: 446.085px;
--planet-trajectory-earth: 332.085px;
--planet-trajectory-venus: 257.085px;
--planet-trajectory-mercury: 203.085px;
/** units **/
--system-margin-mars: 292px;
--system-margin-earth: 35px;
--system-margin-venus: 15px;
--system-margin-mercury: 38px;
--system-border-width: min(2px, 0.4dvmin);
}
*,
*::after,
*::before {
-webkit-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
font-size: 16px;
}
body {
overflow: hidden;
inline-size: 100dvw;
block-size: 100dvh;
background-color: var(--system-color-dark);
/* ☛ ⚠ The distances between the planets and the Sun are not respected because of the diameter of it.
Also note that for aesthetic reasons, the planet's trajectories are not elliptical and are not oriented as they should be. */
& .solar-system {
display: flex;
justify-content: center;
align-items: center;
inline-size: 100%;
block-size: 100%;
transform: skewX(-45deg);
-webkit-transform: skewX(-45deg);
& .solar-system__sun {
z-index: 100;
/* ☛ ⚠ Size of the Sun is not respected here. */
aspect-ratio: 1;
inline-size: var(--star-radius-sun);
border-radius: 50%;
background-color: var(--system-color-red-300);
background: linear-gradient(
135deg,
var(--system-color-red-300) 20%,
transparent
);
filter: drop-shadow(0px 0px 2px var(--system-color-red-300)) blur(1px);
-webkit-filter: drop-shadow(0px 0px 2px var(--system-color-red-300))
blur(1px);
transform: skewX(45deg);
-webkit-transform: skewX(45deg);
}
& article:not(.solar-system__sun) {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
z-index: 99;
aspect-ratio: 1;
border-radius: 50%;
background: transparent;
border-width: var(--system-border-planets-width);
border-style: solid;
border-color: var(--system-color-theme-planets);
&::after {
content: "";
aspect-ratio: 1;
inline-size: 40%;
border-radius: 50%;
background: var(--system-color-red-300);
-webkit-filter: drop-shadow(0px 0px 4.8px var(--system-color-red-200))
blur(0.5px);
filter: drop-shadow(0px 0px 4.8px var(--system-color-red-200))
blur(0.5px);
}
}
& section {
position: absolute;
z-index: 98;
aspect-ratio: 1;
border-radius: 50%;
border-width: var(--system-border-width);
border-style: solid;
border-color: var(--system-color-theme-paths);
}
& .solar-system__mercury-trajectory {
inline-size: var(--planet-trajectory-mercury);
/* ☿ Mercury revolution duration ≈ 87.969 days. */
-webkit-animation: revolution 43.9845s linear infinite;
animation: revolution 43.9845s linear infinite;
& .solar-system__mercury-trajectory__mercury {
inline-size: var(--planet-radius-mercury);
top: var(--system-margin-mercury);
/* ☿ Mercury rotation period ≈ 58.645 days. */
-webkit-animation: revolution 29.3225s linear infinite;
animation: revolution 29.3225s linear infinite;
}
}
& .solar-system__venus-trajectory {
inline-size: var(--planet-trajectory-venus);
/* ♀ Venus revolution duration ≈ 224.667 days. */
-webkit-animation: revolution 112.3335s linear infinite;
animation: revolution 112.3335s linear infinite;
& .solar-system__venus-trajectory__venus {
inline-size: var(--planet-radius-venus);
top: var(--system-margin-venus);
/* ♀ Venus rotation period ≈ 243.023 days. */
-webkit-animation: revolution 121.513s linear infinite;
animation: revolution 121.513s linear infinite;
}
}
& .solar-system__earth-trajectory {
inline-size: var(--planet-trajectory-earth);
/* 🜨 Earth revolution duration ≈ 365.2422 days. */
-webkit-animation: revolution 182.6211s linear infinite;
animation: revolution 182.6211s linear infinite;
& .solar-system__earth-trajectory__earth {
inline-size: var(--planet-radius-earth);
top: var(--system-margin-earth);
/* ✑ animation-duration: .5s ≈ 24 hours on Earth. */
-webkit-animation: revolution 0.4874s linear infinite;
animation: revolution 0.4874s linear infinite;
&::after {
-webkit-animation: blink 2s linear infinite;
animation: blink 2s linear infinite;
}
}
}
& .solar-system__mars-trajectory {
inline-size: var(--planet-trajectory-mars);
/* ♂ Mars revolution duration ≈ 686.885 days. */
-webkit-animation: revolution 343.4425s linear infinite;
animation: revolution 343.4425s linear infinite;
& .solar-system__mars-trajectory__mars {
inline-size: var(--planet-radius-mars);
top: var(--system-margin-mars);
/* ✑ animation-duration: .5s ≈ 24 hours on Earth. */
-webkit-animation: revolution 0.5128s linear infinite;
animation: revolution 0.5128s linear infinite;
}
}
}
& #logo {
inline-size: 8dvmin;
aspect-ratio: 1;
position: fixed;
inset: auto 1.6dvmin 1.6dvmin auto;
opacity: 0.3;
-webkit-filter: saturate(60%);
filter: saturate(60%);
transition: opacity 0.7s linear, filter 0.7s linear;
& circle {
-webkit-fill: var(--system-color-logo);
fill: var(--system-color-logo);
}
& path {
-webkit-fill: var(--system-color-dark);
fill: var(--system-color-dark);
}
&:hover {
opacity: 1;
-webkit-filter: saturate(100%);
filter: saturate(100%);
}
}
}
/*
▀▄▀▄▀▄▀▄▀▄▀▄ ANIMATIONS ▀▄▀▄▀▄▀▄▀▄▀▄
*/
@keyframes revolution {
to {
transform: rotateZ(1turn);
}
}
@keyframes blink {
to {
background-color: var(--system-color-dark);
filter: drop-shadow(0 0 0 var(--system-color-red-200)) blur(0);
}
}
/*** ◰ media queries ***/
/** smartphone **/
@media screen and (width < 768px) {
body {
& .solar-system {
& .solar-system__sun {
inline-size: calc(var(--star-radius-sun) / 2);
}
& .solar-system__mercury-trajectory {
inline-size: calc(var(--planet-trajectory-mercury) / 2);
& .solar-system__mercury-trajectory__mercury {
inline-size: calc(var(--planet-radius-mercury) / 2);
top: calc(var(--system-margin-mercury) - 20px);
}
}
& .solar-system__venus-trajectory {
inline-size: calc(var(--planet-trajectory-venus) / 2);
& .solar-system__venus-trajectory__venus {
inline-size: calc(var(--planet-radius-venus) / 2);
top: calc(var(--system-margin-venus) - 9px);
}
}
& .solar-system__earth-trajectory {
inline-size: calc(var(--planet-trajectory-earth) / 2);
& .solar-system__earth-trajectory__earth {
inline-size: calc(var(--planet-radius-earth) / 2);
top: calc(var(--system-margin-earth) - 19px);
}
}
& .solar-system__mars-trajectory {
inline-size: calc(var(--planet-trajectory-mars) / 2);
& .solar-system__mars-trajectory__mars {
inline-size: calc(var(--planet-radius-mars) / 2);
top: calc(var(--system-margin-mars) - 234px);
}
}
}
}
}
/** 4K and 8K Ultra HD **/
/*
@media screen and (width > 1920px) {
& .solar-system__sun {
inline-size: calc(var(--star-radius-sun) * 2);
}
}
@media screen and (width > 3840px) {
& .solar-system__sun {
inline-size: calc(var(--star-radius-sun) * 4);
}
}*/
Also see: Tab Triggers