The abstract is as follow:We attempt to understand the origin of the near-ultraviolet (NUV) and optical colour gradientsin star-forming galaxies (SFGs) at 0.5 < z < 2 by finding which galaxy properties (stellar mass, size, central mass surface density Sigma_{1 kpc}, total color, and dust extinction are closely correlated with their color gradients, and investigate how galaxies shut down and build up in this redshift rangeby studying the color gradients of transitional galaxies in green valley.Our entire sample contains ~6400 galaxies with M* >10^9 solar mass at 0.5 < z < 2 built from the CANDELS/GOODS-S and UDS fields. We show that generally more massive, larger, redder, more bulge-dominated, and more dusty SFGs tend to have negative color gradients at all redshifts, while low-mass (M* <10^10 solar mass) SFGs usually have random, almost flat color gradients. This implies that both bulge growth and dust reddening can be the drivers of negative color gradients in massive SFGs at intermediate and high redshifts. We find, in the M_*-(NUV-B)_{dc} green valley, high-mass (M* > 10^10 solar mass) galaxies in the whole redshift range of 0.5 < z < 2 mostly have negative color gradients, while low-mass (M* <10^10 solar mass) galaxies at 0.5 < z < 1.2 usually have slightly positive or flat color gradients. It indicates that high-mass galaxies at intermediate and high redshiftsshut down and thus grow mainly from the inside out, while low-mass galaxies at intermediate redshiftsshut down and grow mainly from the outside in.