Fabricating inorganic materials with designed three-dimensional nanostructures is an exciting yet challenging area of research and industrial application. Here, we develop an approach to 3D print high-quality nanostructures of silica with sub-200 nm resolution and with the flexible capability of rare-earth element doping. The printed SiO2 can be either amorphous glass or polycrystalline cristobalite controlled by the sintering process. The 3D-printed nanostructures demonstrate attractive optical properties. For instance, the fabricated micro-toroid optical resonators can reach quality factors (Q) of over 104. Moreover, and importantly for optical applications, doping and codoping of rare-earth salts such as Er3+, Tm3+, Yb3+, Eu3+ and Nd3+ can be directly implemented in the printed SiO2 structures, showing strong photoluminescence at the desired wavelengths. This technique shows the potential for building integrated microphotonics with silica via 3D printing. A 3D-printing technique has been developed to create high-quality pure silica nanostructures with sub-200 nm resolution and the flexible capability of rare-earth element doping. It shows excellent application potential in three-dimensional micro- and nanophotonics.