What is the correct capitalization of the words earth and moon?
Solution 1:
According to Garner's Modern American Usage, when referring to the planet we live on, when used with the definite article, it is "the earth", lower case. However, when it is used as a name for the planet without an article, like "Mars is smaller than Earth", you capitalize it. It says sun and moon are treated the same way.
Solution 2:
The bottom line is that there is little consensus in all usage cases, but guidelines exist.
Typically, we capitalize the names of astronomical bodies, except when there's a preceding article ("Earth" or "the earth"). Earth is never capitalized when referring to soil or land—only when referring to the planet as a whole.
NASA and ESA (among others) prefer to capitalize Moon when referring to Earth's moon as a special case. My guess is that nobody says "Moon is out tonight!", as they would with Jupiter or Venus. We always add "the" to the Moon. It's as if we give it special consideration because doesn't have its own, standalone name. (Some may disagree on this point, preferring to always refer to it always as "the moon", following the rule mentioned above.)
- Correct: "The sun is far from the earth."
- Correct: "The sun is far from Earth."
- Correct: "Jupiter has several moons."
- Correct: "The Moon is right next to the horizon."
- Incorrect: "The Earth is far from the Sun."
- Incorrect: "The Sun gives light to our moon."
- Incorrect (debatable): "The moon is bright tonight."
There are a number of excellent examples on the MLA page here: https://style.mla.org/2016/11/07/capitalizing-earth-sun-moon/
Note also that the name of our host star, the sun, is "Sol". We can say "Sol is larger than Earth", or "The Sun is larger than Earth" or "The sun is out today", but we would say "Sol is larger than Earth" rather than "Sun is larger than Earth".