This review summarizes recent first-principles investigations of the electronic structure and magnetism of dilute magnetic semiconductors (DMSs) use in spintronics. Details of the electronic structure of transition-metal-doped III-V and II-VI semiconductors are described, especially how the electronic structure couples to the magnetic properties of an impurity. In addition, the underlying mechanism of the ferromagnetism in DMSs is investigated from the electronic structure point of view in order to establish a unified picture that explains the chemical trend of the magnetism in DMSs. A hybrid method (ab initio electronic-structure calculations coupled to Monte Carlo simulations for the thermal properties) is discussed for calculating the Curie temperature of DMSs. Finally, first-principles theory of transport properties of DMSs is reviewed. The contribution from FZÚ is mainly in the construction of effective disordered spin models and in the calculation of transport properties.