The effective field theory (EFT) of cosmological perturbations is a useful framework to deal with the low-energy degrees of freedom present for inflation and dark energy. We review the EFT for modified gravitational theories by starting from the most general action in unitary gauge that involves the lapse function and the three-dimensional geometric scalar quantities appearing in the Arnowitt-Deser-Misner (ADM) formalism. Expanding the action up to quadratic order in the perturbations and imposing conditions for the elimination of spatial derivatives higher than second order, we obtain the Lagrangian of curvature perturbations and gravitational waves with a single scalar degree of freedom. The resulting second-order Lagrangian is exploited for computing the scalar and tensor power spectra generated during inflation. We also show that the most general scalar-tensor theory with second-order equations of motion-Horndeski theory-belongs to the action of our general EFT framework and that the background equations of motion in Horndeski theory can be conveniently expressed in terms of three EFT parameters. Finally we study the equations of matter density perturbations and the effective gravitational coupling for dark energy models based on Horndeski theory, to confront the models with the observations of large-scale structures and weak lensing.