A transformer has two coils of insulated wire wound on the same iron core. The coil connected to the input supply is the primary coil. The coil connected to the output is the secondary coil. The two coils are not connected electrically.
An alternating current in the primary coil produces a changing magnetic field, because the current keeps changing size and direction. The iron core carries this changing magnetic field to the secondary coil.
The secondary coil is therefore in a changing magnetic field. By electromagnetic induction, this induces an alternating potential difference across the secondary coil. If the secondary circuit is complete, an alternating current flows in it.
A transformer does not work with direct current. A steady direct current produces a steady magnetic field. The field does not change, so no potential difference is induced in the secondary coil.