A transformer is designed to step-up or step-down a voltage in a wire to make transferring electricity more efficient. To do this they contain two isolated coiled wires (of varied lengths depending on the transformer). The electromotive force (EMF) in the first (primary coil) drives an alternating current through the wire inducing a magnetic field. As the size and strength of a magnetic field is proportional to the current, the magnetic field constantly changes expanding and contracting as the current alternates.
The magnetic fields lines intersect the secondary coil of wire during the expansion and contraction, which causes the reverse to occur, where a magnetic field induces an EMF and current in the new wire without them being physically connected. As a direct current is constant, the magnetic field produced would not move and the field lines would not intersect the secondary wire resulting in no induction of EMF or current. Therefore only an alternating current works in a transformer.