Step-by-step explanation:
A transformer consists of core of soft iron (a material that can be easily magnetized/demagnetized), to which two coils are attached at both ends.
An alternating current in the primary coil produces a magnetic field around the coil, magnetizing the iron core; therefore, the same magnetic field produces a magnetic flux in the secondary coil.
Since the AC current in the primary coil is variable, then the magnetic field also changes, so the magnetic flux through the secondary coil changes over time; therefore, an electromotive force (and so, a current) is induced in the secondary coil, according to Faraday-Newmann-Lenz:

where
is the induced emf
is the rate of change of magnetic flux through the secondary coil
We notice that this mechanism would not work if the current in the primary coil is a DC current: in fact, a DC current has always a constant value, so there is no change in the magnetic field, therefore no change in the magnetic flux through the secondary coil and no emf induced.