There are three main parts to a transformer: two coils of wire (called the primary and secondary) and a laminated iron core connecting them:
The primary coil is connected to the input electrical supply, which has to be AC to work properly. An AC current through the coil creates a changing magnetic field which is concentrated through the iron core.
The secondary coil is not electrically connected to the primary. But inside it is the iron core, which is repeatedly magnetised and demagnetised by the changing current in the primary coil! This is just like pushing a magnet in and out of a coil!