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.
mixin structure()
each val in [1, 2, 3, 4, 5, 6]
div(class="planet__structure planet__structure--" + val)
mixin planet(planetname)
div(class=planetname + "-orbit sun-orbit")
div(class="ascending-node ascending-node--" + planetname)
div(class="inclination inclination--" + planetname)
.orbit__visual
div(class="orbit__shape orbit__shape--" + planetname)
div(class="planet " + planetname)
+structure
block
input(type="radio" id="correct-orbit-size" name="orbit-size")
input(type="radio" id="ideal-orbit-size" name="orbit-size" checked)
input(type="radio" id="real-time" name="velocity")
input(type="radio" id="one-year-per-minute" name="velocity" checked)
input(type="radio" id="one-year-per-second" name="velocity")
input(type="radio" id="topview" name="perspective")
input(type="radio" id="isometric" name="perspective")
input(type="radio" id="threedee" name="perspective" checked)
.universe
.solarsystem
.sun
+structure
+planet("mercury")
+planet("venus")
+planet("earth")
+planet("mars")
+planet("jupiter")
+planet("saturn")
.planet-orbit.planet-orbit--saturn
.rings-of-saturn
+planet("uranus")
+planet("neptun")
.content
h1 The Solar System
.controls
.controls__group
span Orbit Size:
label(for="correct-orbit-size" class="button correct-size") Correct
label(for="ideal-orbit-size" class="button ideal-size") Idealized
.controls__group
span Velocity:
label(for="real-time" class="button real-time") Realtime
label(for="one-year-per-minute" class="button one-year-per-minute") 1 Year / Min
label(for="one-year-per-second" class="button one-year-per-second") 1 Year / Sec
.controls__group
span Perspective:
label(for="threedee" class="button threedee") 3d
label(for="topview" class="button topview") Top
label(for="isometric" class="button isometric") Isometric
@import url('https://fonts.googleapis.com/css?family=Montserrat:300,400')
html
font-size 16px
background-color black
#ideal-orbit-size ~ .universe
--planet-size-factor 0.01
--sun-size-factor 0.001
#ideal-orbit-size:checked ~ .universe
@media (max-width: 649px)
--planet-size-factor 0.075
--sun-size-factor 0.0175
@media (min-width: 650px)
--planet-size-factor 0.15
--sun-size-factor 0.025
#real-time:checked ~ .universe
--speed-of-animation 1
#one-year-per-minute:checked ~ .universe
--speed-of-animation 518400
#one-year-per-second:checked ~ .universe
--speed-of-animation 31104000
#topview ~ .universe
--topview -65deg
--angle-sun-glow 65deg
#topview:checked ~ .universe
--topview 0deg
--angle-sun-glow 0deg
#isometric ~ .universe
--perspective 750px
#isometric:checked ~ .universe
--perspective 10000px
.universe
--orbit-size-factor 1000000
position absolute
top 0
left 0
right 0
bottom 0
background radial-gradient(#020311 0%, black 100%)
display flex
justify-content center
align-items center
overflow hidden
perspective var(--perspective)
transition perspective 2s
.solarsystem
position relative
width 90%
max-width 100vh
display flex
justify-content center
align-items center
transform rotateZ(90deg) rotateY(var(--topview))
transform-style preserve-3d
transition transform 2s
&::after
display block
content ""
width 100%
padding-top 100%
border-radius 50%
.sun
position absolute
width calc(1391px * var(--sun-size-factor))
height calc(1391px * var(--sun-size-factor))
background-color #ffe493
border-radius 50%
transform-style preserve-3d
transition width 2s, height 2s
&::before
display block
content ""
height 600%
width 600%
background radial-gradient(rgba(255, 228, 147, 0.4), rgba(255, 228, 147, 0.1) 40%, rgba(255,255,255,0) 70%)
border-radius 50%
transform-origin center center
transform translateY(-40%) translateX(-40%) rotateY(var(--angle-sun-glow))
transition transform 2s
#ideal-orbit-size:checked ~ .universe .sun
transition-delay 0.6s
// ORBITS
.sun-orbit
transform-style preserve-3d
border-radius 50%
transition width 2s, height 2s
.mercury-orbit
position absolute
width 1.29%
height 1.29%
transform rotateZ(-224deg)
transition-delay 0s
z-index 9
#ideal-orbit-size:checked ~ .universe .mercury-orbit
width 12.5%
height 12.5%
transition-delay 0.6s
.venus-orbit
position absolute
width 2.4%
height 2.4%
transform rotateZ(-144deg)
transition-delay 0.1s
z-index 8
#ideal-orbit-size:checked ~ .universe .venus-orbit
width 25%
height 25%
transition-delay 0.5s
.earth-orbit
position absolute
width 3.33%
height 3.33%
transform rotateZ(-101deg)
transition-delay 0.2s
z-index 7
#ideal-orbit-size:checked ~ .universe .earth-orbit
width 37.5%
height 37.5%
transition-delay 0.4s
.mars-orbit
position absolute
width 5.06%
height 5.06%
transform rotateZ(-39deg)
transition-delay 0.3s
z-index 6
#ideal-orbit-size:checked ~ .universe .mars-orbit
width 50%
height 50%
transition-delay 0.3s
.jupiter-orbit
position absolute
width 17.25%
height 17.25%
transform rotateZ(-245deg)
transition-delay 0.4s
z-index 5
#ideal-orbit-size:checked ~ .universe .jupiter-orbit
width 62.5%
height 62.5%
transition-delay 0.2s
.saturn-orbit
position absolute
width 31.65%
height 31.65%
transform rotateZ(-282deg)
transition-delay 0.5s
z-index 4
#ideal-orbit-size:checked ~ .universe .saturn-orbit
width 75%
height 75%
transition-delay 0.1s
.uranus-orbit
position absolute
width 63.96%
height 63.96%
transform rotateZ(-29deg)
transition-delay 0.6s
z-index 3
#ideal-orbit-size:checked ~ .universe .uranus-orbit
width 87.5%
height 87.5%
transition-delay 0s
.neptun-orbit
position absolute
width 100%
height 100%
transform rotateZ(-347deg)
z-index 2
.orbit__visual
position absolute
border 1px solid rgba(255,255,255,0.13)
width 100%
height 100%
border-radius 50%
transform translate3d(-1px, -1px, 0)
transform-style preserve-3d
.orbit__shape
position absolute
width calc(100% + 1px)
height calc(100% + 1px)
animation orbit infinite
animation-timing-function linear
animation-delay calc((var(--seconds-left) * -1) / var(--speed-of-animation))
transform-style preserve-3d
&--mercury
animation-duration calc(7603200s / var(--speed-of-animation))
&--venus
animation-duration calc(19414166s / var(--speed-of-animation))
&--earth
animation-duration calc(31553280s / var(--speed-of-animation))
&--mars
animation-duration calc(59356800s / var(--speed-of-animation))
&--jupiter
animation-duration calc(374025600s / var(--speed-of-animation))
&--saturn
animation-duration calc(928886400s / var(--speed-of-animation))
&--uranus
animation-duration calc(2649369600s / var(--speed-of-animation))
&--neptun
animation-duration calc(5196787200s / var(--speed-of-animation))
// PLANETS
.planet
position relative
border-radius 50%
min-width 1px
min-height 1px
margin 0 auto
left 0
right 0
transform-style preserve-3d
transition width 2s, height 2s, top 2s
&::before
position relative
display none
content ""
height 500%
transform translateY(-100%)
width 100%
background linear-gradient(to top, rgba(1,2,13,0.8), rgba(1,2,13,0) 100%)
clip-path: polygon(50% 0%, 100% 100%, 100% 100%, 0% 100%);
&__structure
position absolute
top 0
left 0
width 100%
height 100%
background-color inherit
border-radius 50%
transform-style preserve-3d
&--1
transform rotateZ(30deg)
&--2
transform rotateZ(-30deg)
&--3
transform rotateX(30deg) rotateY(90deg)
&--4
transform rotateX(-30deg) rotateY(90deg)
&--5
transform rotateZ(90deg) rotateY(30deg)
&--6
transform rotateZ(90deg) rotateY(-30deg)
&::before
position absolute
top 0
content ""
display block
width 100%
height 100%
transform rotateX(45deg)
background-color inherit
border-radius 50%
&::after
position absolute
top 0
content ""
display block
width 100%
height 100%
transform rotateX(-45deg)
background-color inherit
border-radius 50%
.mercury
width calc(4.87px * var(--planet-size-factor))
height calc(4.87px * var(--planet-size-factor))
background-color #68696D
top calc(-2.435px * var(--planet-size-factor))
.venus
width calc(12.10px * var(--planet-size-factor))
height calc(12.10px * var(--planet-size-factor))
background-color #d3a567
top calc(-6.05px * var(--planet-size-factor))
.earth
width calc(12.70px * var(--planet-size-factor))
height calc(12.70px * var(--planet-size-factor))
background-color blue
top calc(-6.35px * var(--planet-size-factor))
.mars
width calc(6.70px * var(--planet-size-factor))
height calc(6.70px * var(--planet-size-factor))
background-color #C1440E
top calc(-3.45px * var(--planet-size-factor))
.jupiter
width calc(139.822px * var(--planet-size-factor))
height calc(139.822px * var(--planet-size-factor))
background-color #d8ca9d
top calc(-69.911px * var(--planet-size-factor))
.saturn
width calc(116.464px * var(--planet-size-factor))
height calc(116.464px * var(--planet-size-factor))
background-color #D2C0A5
top calc(-58.232px * var(--planet-size-factor))
.uranus
width calc(50.724px * var(--planet-size-factor))
height calc(50.724px * var(--planet-size-factor))
background-color #d1e7e7
top calc(-25.362px * var(--planet-size-factor))
.neptun
width calc(49.244px * var(--planet-size-factor))
height calc(49.244px * var(--planet-size-factor))
background-color #3f54ba
top calc(-24.622px * var(--planet-size-factor))
.planet-orbit
animation orbit infinite
animation-timing-function linear
transform-style preserve-3d
top 0
left 0
right 0
position absolute
&--saturn
animation-duration calc(933465600s / var(--speed-of-animation))
animation-delay calc(((var(--seconds-left) + 433366400) * -1) / var(--speed-of-animation))
.rings-of-saturn
transform rotateX(0deg) rotateY(27deg)
position absolute
width calc(280px * var(--planet-size-factor) + 3px)
height calc(280px * var(--planet-size-factor) + 3px)
background radial-gradient(rgba(0,0,0,0), rgba(0,0,0,0) 45%, #c1b199 48%, #c1b199 65%, rgba(0,0,0,0) 66%, #c1b199 68%, #c1b199 100%)
top calc(-140px * var(--planet-size-factor) - 1.5px)
border-radius 50%
margin 0 auto
left 0
right 0
transition width 2s, height 2s, top 2s
// ASTROMECHANICS
.ascending-node
position relative
height 100%
transform-style preserve-3d
/*&--mercury
transform rotateZ(48.33deg)
&--venus
transform rotateZ(76.68deg)
&--earth
transform rotateZ(-11.26deg)
&--mars
transform rotateZ(49.58deg)
&--jupiter
transform rotateZ(100.55deg)
&--saturn
transform rotateZ(113.72deg)
&--uranus
transform rotateZ(74.23deg)
&--neptun
transform rotateZ(131.72deg)*/
.inclination
position relative
height 100%
transform-style preserve-3d
/*&--mercury
transform rotateX(-7deg)
&--venus
transform rotateX(-3.5deg)
&--earth
transform rotateX(0deg)
&--mars
transform rotateX(-1.9deg)
&--jupiter
transform rotateX(-1.3deg)
&--saturn
transform rotateX(-2.5deg)
&--uranus
transform rotateX(-0.8deg)
&--neptun
transform rotateX(-1.8deg)*/
@keyframes orbit {
from {
transform rotate(360deg)
}
to {
transform rotate(0deg)
}
}
.content
color white
width 100%
height 100%
font-size 16px
top 0
left 0
position absolute
font-family Open Sans, sans-serif
text-align center
h1
font-weight 300
text-transform uppercase
font-family: 'Montserrat', sans-serif;
letter-spacing 15px
.controls
@media (max-width: 649px)
position absolute
bottom 0
@media (min-width: 650px)
display inline-block
justify-content center
font-weight 300
letter-spacing 1px
font-size 13px
max-width 600px
width 100%
span
width 120px
&__group
border-radius 10px
border 1px solid rgba(255, 255, 255, 0.7)
display flex
flex 1
margin-bottom 15px
> *
padding 10px
display block
.button
flex 1
transition background-color 0.4s
text-transform uppercase
user-select none
&:hover
background-color rgba(255, 255, 255, 0.2)
&:first-of-type
border-radius 9px 0 0 9px
&:last-child
border-radius 0 9px 9px 0
#ideal-orbit-size:checked ~ .content .button.ideal-size
#correct-orbit-size:checked ~ .content .button.correct-size
#real-time:checked ~ .content .button.real-time
#one-year-per-minute:checked ~ .content .button.one-year-per-minute
#one-year-per-second:checked ~ .content .button.one-year-per-second
#topview:checked ~ .content .button.topview
#isometric:checked ~ .content .button.isometric
#threedee:checked ~ .content .button.threedee
background-color rgba(255, 255, 255, 0.3)
//For those who wonder why Javascript is here, a short explanation. This script only ensures that the initial position, the planetary position is calculated correctly by setting the seconds left since 1-1-2019 to a css custom variable. No hidden Magic 🤷
let timestamp_start = new Date("2019-01-01").getTime();
let timestamp_now = new Date().getTime();
let secondsLeft = (timestamp_now - timestamp_start) / 1000;
let root = document.documentElement;
root.style.setProperty('--seconds-left', `${secondsLeft}s`);
Also see: Tab Triggers