The cosmological formation of massive galaxies In a hierarchically organised universe massive galaxies are built up from stars that are formed from gas close to the center of the galaxy (in-situ) and from accreted stellar matter formed in external galaxies (ex-situ). From analysing a sample of high-resolution cosmological simulations of the formation of individual massive galaxies, we find these two phases of star formation to be a useful distinction in understanding the rapid size evolution of elliptical galaxies and the origin of their fundamental scaling relations.