Context. CHROMIS, a new imaging spectrometer at the Swedish 1-m Solar Telescope (SST), can observe the chromosphere in the H and K lines of Ca ii at high spatial and spectral resolution. Accurate modeling as well as an understanding of the formation of these lines are needed to interpret the SST/CHROMIS observations. Such modeling is computationally challenging because these lines are influenced by strong departures from local thermodynamic equilibrium, three-dimensional radiative transfer, and partially coherent resonance scattering of photons. Aims. We aim to model the Ca ii H&K lines in 3D model atmospheres to understand their formation and to investigate their diagnostic potential for probing the chromosphere. Methods. We model the synthetic spectrum of Ca ii using the radiative transfer code Multi3D in three different radiationmagnetohydrodynamic model atmospheres computed with the Bifrost code. We classify synthetic intensity profiles according to their shapes and study how their features are related to the physical properties in the model atmospheres. We investigate whether the synthetic data reproduce the observed spatially-averaged line shapes, center-to-limb variation and compare with SST/CHROMIS images.Results. The spatially-averaged synthetic line profiles show too low central emission peaks, and too small separation between the peaks. The trends of the observed center-to-limb variation of the profiles properties are reproduced by the models. The Ca ii H&K line profiles provide a temperature diagnostic of the temperature minimum and the temperature at the formation height of the emission peaks. The Doppler shift of the central depression is an excellent probe of the velocity in the upper chromosphere.