  We study inflation and late-time acceleration in the expansion of the
universe in non-minimal electromagnetism, in which the electromagnetic field
couples to the scalar curvature function. It is shown that power-law inflation
can be realized due to the non-minimal gravitational coupling of the
electromagnetic field, and that large-scale magnetic fields can be generated
due to the breaking of the conformal invariance of the electromagnetic field
through its non-minimal gravitational coupling. Furthermore, it is demonstrated
that both inflation and the late-time acceleration of the universe can be
realized in a modified Maxwell-$F(R)$ gravity which is consistent with solar
system tests and cosmological bounds and free of instabilities. At small
curvature typical for current universe the standard Maxwell theory is
recovered. We also consider classically equivalent form of non-minimal
Maxwell-$F(R)$ gravity, and propose the origin of the non-minimal gravitational
coupling function based on renormalization-group considerations.
