All gold on Earth was created during a supernova explosion, (this is also true for the other non-radioactive elements with that highest molecular masses). Some of the remnants of supernovae explosions reached the Earth. It's possible that most of the gold on earth is buried to deep in the Earth's crust, mantle or core to ever be extracted. Many of the heavier elements 'sank' while the Earth was still forming. Their presence is rare near the surface.
In addition to its rarity and its pleasant appearance, gold is highly malleable and ductile, meaning that it can be molded into a number of different shapes, and it doesn't fracture from blunt force, as might a crystalline form of a different element, such as a diamond.
Gold does not react chemically with oxygen, so it doesn't 'rust'. It can also be pounded into a thin sheet only several molecules thick - in that form, it's used on the shield of astronaut's helmets to protect their eyes. They can easily see through the thin film, which also deflects certain wavelengths and intensities of light.
Gold is also resistant to most acids, and it's an excellent conductor of electricity.
All of these factors contribute to its high purchase cost and its value as a commodity which will always be in demand for industrial use in addition to public displays of wealth/ status, or for objects with religious or cultural value.
It's been estimated that the entire amount of gold produced in the entire history of mankind might only fill the volume of a US football field, ten feet deep. That would be about 405,000 cubic feet. It seems like there should be more gold, but most of the gold in use wasn't recently mined. It's the same 'old gold', re-melted and used for different purposes.