The sun is primarily composed of hydrogen and helium, with small amounts of other elements such as oxygen, carbon, and neon.