Why do the sun & the gas giant planets have similar compositions? Why are the terrestrial planets different?
The sun and gas giants are mostly hydrogen and helium because that’s mostly what the nebula was made of that collapsed to form the solar system. Before the planets formed, the sun ignited and light pressure blew most of the H, He, and H20 vapor out of the inner solar system, leaving behind solid particles, which had already begun to stick to each other. Solid particles a have much greater mass to surface area ratio than individual atoms and molecules, so they are more resistant to such transport. The particles kept sticking to each other until they were massive enough for gravity to cause them to clump even faster, forming the inner planets. As for water (H20), it could condense into particle far from the sun and form comets. Comet out there would frequently get bumped into the inner solar system and supply the earth would water. Meanwhile, the gas giants formed by gravitational collapse directly or onto rocky cores (which is controversial).