The free electromagnetic field is canonically quantised in a gauge-invariant way by interpreting the Fourier coefficients of the magnetic induction field B as generalised coordinates, and the coefficients of the electric field E as their conjugate momenta. The usual commutation relations among the components of E and B are obtained. A canonical transformation, corresponding to a rotation in generalised phase space, is made on the Fourier coefficients. This transformation is shown to give a duality transformation on the electric and magnetic fields. The free-field Maxwell equations and the commutation relations are invariant under duality transformations. However, if interactions are introduced, the invariance under duality transformations is broken, and the original canonical theory should be used.