Electromagnetic waves can either be transverse or a combination of transverse and longitudinal. The simplest and most common electromagnetic waves are transverse. When an electromagnetic wave interacts with an object or material such that it is guided or deflected, it gains a longitudinal component. Even electromagnetic waves traveling through free space can have longitudinal components if set up properly. Note that you can't have an electromagnetic wave that is purely longitudinal. You can have non-radiative electromagnetic fields that are purely longitudinal, but not waves