Jupiter is the largest planet in the Solar System. It has a mass of 2,5 times all the other planets combined. This enormous planet is fifth in line from the Sun following the four inner rock planets (Mercury, Venus, Earth and Mars).
Further out than Jupiter are the three remaining gas planets (Saturn Uranus and Neptune), all of which have larger distance to the Sun than Jupiter.

These few characteristics make Jupiter not only the largest planet in the Solar System, it also makes it the gas planet located closest to the Sun.
Is this pure coincidence, or is there a reason for why both 1st places go to the same planet?
The planets were created roughly 4 billion years ago
The Sun was created 4.6 billion years ago when a large cloud of gas and dust collapsed due to its own gravity. The central Sun grew in size by “eating” the surrounding gas and dust that were distributed in a disk around the newly born star.

Not all material in the surrounding disk was accreted by the Sun. Some of the material was “left over” after the Sun had grown large enough to initiate nuclear fusion in the core and hence become a “real” Hydrogen-burning star.
This left over material rotated around the Sun and as time passed density variations and dynamics in the disk would create the Solar System’s eight planets. Exactly the composition and dynamics of the planets hold information about the creation of rocky planets and gas giants.
The snow line separates gas giants from rocky planets
The temperature drops throughout the Solar System as the distance to the Sun increases. This is the case today and this was the case when the Sun was formed.
This temperature gradient accounts for how the rocky planets are located closest to the Sun: they are made from materials with high melting point, and this made them resistant to the high temperature near the new Sun.
When traveling further away from the Sun, in our case to near Jupiter, the temperature was low enough for water vapor to condense. This “limit” is called the snow line, because it is the line that separates water gas from water ice. Today, that line is found 5 astronomical units (AU) from the Sun, but during the formation of the Solar System, the distance was only 3 AU as the dust around the Sun would shield heat from the surroundings causing the temperature to drop faster throughout the Solar System.
At 5 AU is also where we find Jupiter. With a mass of 317 times that of the Earth, it is by far the heaviest planet in the Solar System.
Some astronomers believe that the reason why Jupiter is found exactly in this region, is because of this is where ice would “pile up” and become available to be caught by Jupiter’s gravity when the planet was growing to its current size.
The icy grains containing e.g. Hydrogen would stay trapped by Jupiter’s gravity, which allowed the planet to grow in size and have a composition of lighter elements that are not found in the inner planets.
Formation of planets is complex but their composition can reveal origin
While the formation of planets holds much complexity, there is one thing that planets have in common, when it comes to formation. A planet’s composition holds information about the condition which the planet was formed under.
We see this e.g. in the inner planets that are all made from rocky material with high melting points. This material was the only type that could survive the high temperature and solar winds near the Sun.
Similarly, further out we find gas giants that contain lighter elements (such as Hydrogen and Helium), which tells us that conditions in those regions were different compared to the inner regions.
Still much to be understood
Lastly, it should be mentioned that planet formation generally is complex, and the above description can not be applied generally to solar systems.
The varying dynamics and composition of the environment around any new forming star makes it possible to form planets in several different ways, and today there are still much to be understood in planet formation – even of those in our own Solar System.