Build a Moon Orbit - Build a Moon Orbit

Tell us what’s happening:

I followed the instructions already, and the moon is orbiting the earth.
However, I don’t understand some code snippets like:
how the rotation origin shifted to be the bottom right corner of the orbit
I want to clarify if that’s because of this rule: translate(-50%, -50%) in the @keyframes? If so, please explain how this works?

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Moon Orbit</title>
<link  rel="stylesheet" href="styles.css" />
</head>
<body>
    <div class="space">
        <div class="earth">

        </div>
        <div class="orbit">
            <div class="moon"></div>
        </div>
    </div>
</body>
<body>

</body>

</html>
/* file: styles.css */
body {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.space {
  background-color: black;
  width: 200px;
  height: 200px;
  position: relative;
}

.earth {
  width: 100px;
  height: 100px;
  background-color: #0000FF;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%)

}

.orbit {
  width: 200px;
  height: 200px;
  border: 1px solid lightgray;
  position: absolute;
  transform: translate(-50%, -50%);
  animation: orbit 5s linear infinite;
}

.moon {
  width: 30px;
  height: 30px;
  background-color: #808080;
  border-radius: 50%;
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  left: 50%;


}

@keyframes orbit {
  0% {
    transform: rotate(0deg) translate(-50%, -50%)
  }
  100% {
    transform: rotate(360deg) translate(-50%, -50%)
  }
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36 Edg/154.0.0.0

Challenge Information:

Build a Moon Orbit - Build a Moon Orbit

GitHub Link: https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/blocks/lab-moon-orbit/66a37f37ef5823a313de8c26.md

this moves something 50% to the right and 50% to the bottom

you can review this lesson https://www.freecodecamp.org/learn/responsive-web-design-v9/lecture-working-with-css-transforms-overflow-and-filters/what-is-the-css-transform-property

I know the functionality of transform: translate(X, Y)
What I wanted to say is: when we inserted it inside the @keyframes,

@keyframes orbit {
  0% {

    transform: rotate(0deg) translate(-50%, -50%);
  }
  100% {

    transform: rotate(360deg) translate(-50%, -50%);
  }
}

It actually did something more than moving the orbit by -50% right and -50% left; it actually made it rotate around its bottom right corner.

09.10.2026_11.21.43_REC

Or… might it be the case that the origin of rotation didn’t move with the orbit box, it just being kept at the center of the original place of the orbit?

That’s what came to my mind while writing this comment, and I need you to verify my thought

the order in which the transformations are applied also matter, the two transformations are applied one after the other to create this effect

You mean from right to left, translate() first, then rotate(). If we swapped them, it won’t work.
Thanks for the hint. :smiling_face:
I ended up asking Claud to clarify your hint, :sweat_smile:
here’s the question if anyone wants to read: