An electrical connector comprises an insulative housing, a plurality of conductive terminals secured in the insulative housing, a metal shell shielding around the insulative housing and a magnetic element retained in the metal shell. The metal shell forms an accommodating room for receiving the magnetic element. The magnetic element has an outer surface and a recess defined on the outer surface. The metal shell has a retaining arm corresponding to the recess. The design of the recess and the retaining arm make a better retaining effectivity for the electrical connector.