  We obtain conditions for the existence and stability of de Sitter attractors
in the phase space of spatially homogeneous and isotropic cosmology in
generalized theories of gravity (including non-linear and scalar-tensor
theories). These conditions are valid for any form of the coupling functions of
the theory. Stability with respect to inhomogeneous perturbations is analyzed
using a covariant and gauge-invariant formalism. The relevance for inflationary
scenarios of the early universe and for quintessence models of the present era
is discussed.
