In this paper, we present a framework to obtain analytical solutions to a fractional oscillator by the homotopy perturbation method. The equation of motion of a driven fractional oscillator is obtained from the corresponding equation of motion of a driven harmonic oscillator by replacing the second-order time derivative by a fractional derivative of order alpha with 0 < a <= 2. The fractional derivative is described in the Caputo sense. Some examples are tested, and the results reveal that the technique introduced here is very effective and convenient for solving a fractional oscillator. The response characteristics of the fractional oscillator are studied for several cases.