We discuss the formal basis and general advantages of magnetic-field-and-density functional theory (BDFT) for the ground-state magnetic properties of many-electron systems. The ground-state density ρ(r) and the magnetic field B(r) are the variables appearing in the energy functionals that are the fundamental elements of BDFT. This is in contrast to the energy functionals of current-and-density functional theory (CDFT), the most general density-functional way of treating systems in a magnetic field, where the variables are ρ(r) and the ground-state paramagnetic current jp(r). Explicit calculations of magnetic properties have already been made that can be recognized as belonging to the BDFT paradigm, which this work therefore puts on a formal foundation. There are also aspects of BDFT discussed here that may make it an attractive alternative to the more general CDFT in some situations. In particular, we show that Kohn-Sham equations may be derived that use purely real orbitals and for which the energy does not separate into para- and diamagnetic contributions. We also show that in BDFT the zero-field electron density alone is sufficient to calculate the energy to second order in the magnetic field. Thus calculation of, e.g., diamagnetic susceptibilities or chemical shifts can in principle be made directly from zero-field electron distributions, without any need for the calculation of first-order corrections.