Context. We investigate the grain opacity κ gr in the atmosphere (outer radiative zone) of forming planets. This is important for the observed planetary mass-radius relationship since κ gr affects the primordial H/He envelope mass of low-mass planets and the critical core mass of giant planets. Aims. The goal of this study is to derive a simple analytical model for κ gr and to explore its implications for the atmospheric structure and resulting gas accretion rate. Methods. Our model is based on the comparison of the timescales of the most important microphysical processes. We consider grain settling in the Stokes and Epstein drag regime, growth by Brownian motion coagulation and differential settling, grain evaporation in hot layers, and grain advection due to the contraction of the envelope. With these timescales and the assumption of a radially constant grain flux, we derive the typical grain size, abundance, and opacity. Results. We find that the dominating growth process is differential settling. In this regime, κ gr has a simple functional form; it is given as 27Q/8Hρ in the Epstein regime in the outer atmosphere and as 2Q/Hρ for Stokes drag in the deeper layers. Grain growth leads to a typical radial structure of κ gr with high ISM-like values in the outer layers but a strong decrease towards the deeper parts where κ gr becomes so low that the grain-free molecular opacities take over. Conclusions. In agreement with earlier results, we find that κ gr is typically much lower than in the ISM. In retrospect, this suggests that classical giant planet formation models should have considered the grain-free case to be as equally meaningful as the full ISM opacity case. The equations also show that a higher dust input in the top layers does not strongly increase κ gr . This has two important implications. First, for the formation of giant planet cores via pebbles, there could be the adverse effect that pebbles tend to increase the grain input high in the atmosphere because of ablation. This could in principle increase the opacity, making giant planet formation difficult. Our study indicates that this potentially adverse effect is not important. Second, it means that a higher stellar [Fe/H] which presumably leads to a higher surface density of planetesimals only favors giant planet formation without being detrimental to it because of an increased κ gr . This corroborates the result that core accretion can explain the observed increase of the giant planet frequency with stellar [Fe/H].