Upcoming studies of extrasolar gas giants will give precise insights into the composition of planetary atmospheres, with the ultimate goal of linking it to the formation history of the planet. Here, we investigate how drifting and evaporating pebbles that enrich the gas phase of the disk influence the chemical composition of growing and migrating gas giants. To achieve this goal, we perform semi-analytical 1D models of protoplanetary disks, including viscous evolution, pebble drift, and evaporation, to simulate the growth of planets from planetary embryos to Jupiter-mass objects by the accretion of pebbles and gas while they migrate through the disk. The gas phase of the protoplanetary disk is enriched due to the evaporation of inward drifting pebbles crossing evaporation lines, leading to the accretion of large amounts of volatiles into the planetary atmosphere. As a consequence, gas-accreting planets are enriched in volatiles (C, O, N) compared to refractories (e.g., Mg, Si, Fe) by up to a factor of 100, depending on the chemical species, its exact abundance and volatility, and the disk’s viscosity. A simplified model for the formation of Jupiter reveals that its nitrogen content can be explained by inward diffusing nitrogen-rich vapor, implying that Jupiter did not need to form close to the N2 evaporation front as indicated by previous simulations. However, our model predicts an excessively low oxygen abundance for Jupiter, implying either Jupiter’s migration across the water ice line (as in the grand tack scenario) or an additional accretion of solids into the atmosphere (which can also increase Jupiter’s carbon abundance, ultimately changing the planetary C/O ratio). The accretion of solids, on the other hand, will increase the refractory-to-volatile ratio in planetary atmospheres substantially. We thus conclude that the volatile-to-refractory ratio in planetary atmospheres can place a strong constraint on planet formation theories (in addition to elemental ratios), especially on the amount of solids accreted into atmospheres, making it an important target for future observations.