The effect of an inclined homogeneous magnetic field on thermal convection between rigid plates heated from below under the influence of gravity is numerically simulated in a computational domain with periodic horizontal extent. The numerical technique is based on solenoidal (divergence-free) basis functions satisfying the boundary conditions for both the velocity and the induced magnetic field. Thus, the divergence-free conditions for both velocity and magnetic field are satisfied exactly. The expansion bases for the thermal field are also constructed to satisfy the boundary conditions. The governing partial differential equations are reduced to a system of ordinary differential equations under Galerkin projection and subsequently integrated in time numerically. The projection is performed by using a dual solenoidal bases set such that the pressure term is eliminated in the process. The quasi-steady relationship between the velocity and the induced magnetic field corresponding to the liquid metals or melts is used to generate the solenoidal bases for the magnetic field from those for the velocity field. The technique is validated in the linear case for both oblique and vertical case by reproducing the marginal stability curves for varying Chandrasekhar number. Some numerical simulations are performed for either case in the nonlinear regime for Prandtl numbers Pr=0.05 and Pr=0.1. Copyright (c) 2014 John Wiley & Sons, Ltd.