Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="scene">
  <p class="info">Size and speed is not to scale.</p>
  <div class="settings">
    <label>
      Axial Tilt:
      <input
        type="range"
        id="axial-tilt"
        min="0"
        max="90"
        step="0.05"
        value="23.45" />
      <span id="axial-tilt-value">23.45°</span>
    </label>
    <label>
      Show Guides?
      <input
        type="checkbox"
        id="show-guides"
        checked />
    </label>
  </div>
  <div class="sky">
    <div class="sun"></div>
    <div class="earth-container">
      <div class="earth">
        <div class="line polars"></div>
        <div class="line tropics"></div>
        <div class="equator"></div>
      </div>
      <div class="longitudes">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
      <div class="night-container">
        <div class="night"></div>
      </div>
      <div class="axis"></div>
    </div>
    <div class="guide ecliptic"></div>
    <div class="guide date june-solstice"></div>
    <div class="guide date december-solstice"></div>
    <div class="guide date equinox"></div>
  </div>
</div>
              
            
!

CSS

              
                /*
 * --axial-tilt has to be defined separately.
 * Otherwise the other ones are becoming undefined for some reason :/
 * I noticed this started happening in Dec 2020 (~2 years after creating the Pen).
*/
:root {
  --axial-tilt: 23.45deg;
}

:root {
  --size: 18vmin;
  --sun-size: 25vmin;
  --orbit-speed: 15s;
  --june: -42vmin;
  --december: 42vmin;
  --equinox: 0;
  --guide-color: #e4cab4;
}

body {
  background: #343454;
  font: 100 normal 14px/1.2 menlo, monaco, monospace;
  overflow: hidden;
}

.scene {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.info {
  padding: 2vh;
  font: 100 italic 1em/1 "operator mono", menlo, monaco, monospace;
  color: #fff;
  text-align: center;
}

.settings {
  width: 80vmin;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2vh;
  border-radius: 3px;
  background: rgba(#000, .3);
  box-shadow: inset 0 -5px 5vh rgba(#020212, .25);
  font-size: clamp(10px, 2vmin, 1em);

  label {
    color: #fff;
  }

  label + label {
    padding-left: 2vmin;
    margin-left: 2vmin;
    border-left: 1px solid rgba(#fff, .25);
  }

  input {
    margin: 0;
    vertical-align: middle;
  }
}

.sky {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 70vh;
}

.sun {
  position: absolute;
  width: var(--sun-size);
  height: var(--sun-size);
  z-index: 2;
  border-radius: 50%;
  background: gold;
  animation:
    radiate
    calc( var(--orbit-speed) / 1.2)
    infinite;
}

.earth-container {
  position: relative;
  z-index: 2;
  width: var(--size);
  height: var(--size);
  animation:
    orbit
    ease-in-out
    infinite
    var(--orbit-speed)
    calc( var(--orbit-speed) / -1.35 );
}

.earth {
  width: var(--size);
  height: var(--size);
  position: relative;
  border-radius: 100%;
  overflow: hidden;
  background: #f4dab4;
  transform: rotate(var(--axial-tilt));

  .equator {
    width: 100%;
    height: 1px;
    position: absolute;
    top: 50%;
    left: 50%;
    background: #111;
    transform: translate(-50%, -50%);
  }

  @mixin line($angle, $size) {
    width: 1px;
    height: 100%;
    position: absolute;
    top: 0%;
    left: 50%;
    transform:
      translateX(-50%)
      rotate($angle);

    &::before, &::after {
      content: "";
      display: block;
      width: $size;
      height: 1px;
      background: #666;
    }

    &::before {
      transform-origin: bottom right;
      transform:
        translateX(-100%)
        rotate(calc(#{$angle} * -1))
    }

    &::after {
      position: absolute;
      bottom: 0;
      transform-origin: top left;
      transform:
        rotate(calc(#{$angle} * -1))
    }
  }

  .polars {
    @include line(var(--axial-tilt), var(--size));
  }

  .tropics {
    @include line( calc(90deg - var(--axial-tilt)), var(--size) );
  }
}

.longitudes {
  $longitudes: 12;
  position: absolute;
  top: 0;
  left: 0;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  transform: rotate(var(--axial-tilt));
  color: rgba(#431, .4);
  animation:
    longitudes-visibility
    ease-in-out
    infinite
    var(--orbit-speed);

  div {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    box-sizing: border-box;

    @for $i from 1 through $longitudes / 2 {
      &:nth-child(#{$i}) {
        border-left: 1px solid;
      }

      &:nth-child(#{$i + $longitudes / 2}) {
        border-right: 1px solid;
      }
    }

    @for $i from 1 through $longitudes {
      @keyframes longitude-rotate-#{$i} {
        $slice: 360deg / $longitudes;
        from {
          transform: rotateY($slice * ($i - 1));
        }
        100% {
          transform: rotateY($slice * $i);
        }
      }

      &:nth-child(#{$i}) {
        animation:
          longitude-rotate-#{$i}
          linear
          calc( var(--orbit-speed) / 60 )
          infinite;
      }
    }
  }
}

.night-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  overflow: hidden;
}

.night {
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  left: 0;
  background: rgba(#545474, .75);
  transform: translateX(-100%);
  animation:
    night-move linear infinite var(--orbit-speed),
    night-shape linear infinite var(--orbit-speed);

  &::before, &::after {
    content: "";
    position: absolute;
    top: 0;
    display: block;
    width: 100%;
    height: 100%;
    opacity: 0;
    box-shadow: .5vw 0 0 var(--size) rgba(#545474, .75);
  }

  &::before {
    left: 0;
    transform: translateX(-100%);
    animation: night-before linear infinite var(--orbit-speed);
  }

  &::after {
    right: 0;
    transform: translateX(100%);
    animation: night-after linear infinite var(--orbit-speed);
  }
}

.axis {
  width: 1px;
  height: 100%;
  position: absolute;
  top: 0;
  left: 50%;
  color: springgreen;
  background: currentColor;
  transform:
    translateX(-50%)
    rotate(var(--axial-tilt))
    scaleY(1.5);

  &::after {
    position: absolute;
    content: "";
    display: block;
    width: 14px;
    height: 14px;
    border-style: solid;
    border-width: 3px 2px 1px 0;
    box-sizing: border-box;
    border-radius: 100%;
    animation:
      axis-rotate
      linear
      calc( var(--orbit-speed) / 10 )
      infinite;
  }
}

.guide {
  position: absolute;
  opacity: 1;
  transition: opacity .5s;
  color: var(--guide-color);
  background: currentColor;

  &.hidden {
    opacity: 0;
  }

  &::after {
    position: absolute;
    font-size: .9em;
  }
}

.ecliptic {
  width: 100%;
  height: 1px;

  &::after {
    content: "Ecliptic";
    right: 1vmin;
    top: 1vmin;
  }
}

.date {
  width: 1px;
  height: 25%;

  &::after {
    top: -1vmin;
    left: 50%;
    transform: translate(-50%, -100%);
  }
}

.june-solstice {
  transform:
    translate(var(--june), -50%);

  &::after {
    content: "June Solstice";

    @media (min-width: 710px) {
      width: 15ch;
    }

    @media (max-width: 709px) {
      text-align: center;
    }
  }
}

.december-solstice {
  transform:
    translate(var(--december), -50%);

  &::after {
    content: "December Solstice";

    @media (min-width: 710px) {
      width: 17ch;
    }

    @media (max-width: 709px) {
      text-align: center;
    }
  }
}

.equinox {
  transform:
    translate(var(--equinox), -50%);

  &::after {
    content: "Equinox";
    width: 7ch;
  }
}

@keyframes night-move {
  to {
    transform: translateX(100%)
  }
}

@keyframes night-shape {
  from, 25% {
    background: transparent;
  }
  25% {
    border-radius: 50% 0 0 50% / calc(var(--size) / 2);
  }
  25.01% {
    background: rgba(#545474, .75);
  }
  50% {
    border-radius: 50%;
  }
  75% {
    border-radius: 0% 50% 50% 0% / calc(var(--size) / 2);
    background: rgba(#545474, .75);
  }
  75.01%, to {
    background: transparent;
  }
}

@keyframes night-before {
  75% {
    opacity: 0;
    border-radius: 0;
  }
  75.01% {
    opacity: 1;
  }
  to {
    opacity: 1;
    border-radius: 50% / calc(var(--size) / 1.5);
  }
}

@keyframes night-after {
  from {
    opacity: 1;
    border-radius: 50% / calc(var(--size) / 1.5);
  }
  25% {
    opacity: 1;
  }
  25.01% {
    opacity: 0;
    border-radius: 0;
  }
}

@keyframes orbit {
  from, to {
    transform: translateX(var(--june));
  }
  50% {
    z-index: 2;
    transform: translateX(var(--december));
  }
  51% {
    z-index: 1;
  }
  to {
    z-index: 1;
  }
}

@keyframes axis-rotate {
  from {
    transform:
      translate(-50%, 25%)
      rotateX(75deg)
      rotate(360deg);
  }
  to {
    transform:
      translate(-50%, 25%)
      rotateX(75deg)
      rotate(-360deg);
  }
}

@keyframes radiate {
  from, to { box-shadow: 0 0 10vmin rgba(gold, .5); }
  15% { box-shadow: 0 0 8vmin rgba(gold, .5); }
  25% { box-shadow: 0 0 11vmin rgba(gold, .5); }
  36% { box-shadow: 0 0 9vmin rgba(gold, .5); }
  53% { box-shadow: 0 0 6vmin rgba(gold, .5); }
  65% { box-shadow: 0 0 3vmin rgba(gold, .5); }
  72% { box-shadow: 0 0 12vmin rgba(gold, .5); }
  80% { box-shadow: 0 0 12vmin rgba(gold, .5); }
  90% { box-shadow: 0 0 8vmin rgba(gold, .5); }
}

/*
 * Drop opacity when the earth is passing
 * in front of sun. Otherwise longitudes on
 * the left edge will look a little ugly.
 */
@keyframes longitudes-visibility {
  48%, 58% { opacity: 1; }
  50%, 56% { opacity: .6; }
}
              
            
!

JS

              
                const DOM = document.documentElement

const setCSSProperty = (key, value) =>
  DOM.style.setProperty(key, value) 

const query = selector =>
  selector[0] === '#'
    ? document.getElementById(selector.slice(1))
    : document.querySelectorAll(selector)

const formatTiltValue = value =>
  `0${value.toFixed(2)}`.slice(-5)

const axialTilt = query('#axial-tilt')
const axialTiltValue = query('#axial-tilt-value')
axialTilt.addEventListener('input', event => {
  const value = formatTiltValue(+event.target.value)
  axialTiltValue.innerText = `${value}°`
  setCSSProperty('--axial-tilt', `${value}deg`)
})

const showGuides = query('#show-guides')
const guides = query('.guide')
showGuides.addEventListener('change', event => {
  guides.forEach(guide => {
    guide.classList.toggle('hidden')
  })
})
              
            
!
999px

Console